Code from book immediately crashes; "CriminalIntent has stopped working"


#1

Hi all!

I’m extremely desperate, as I cannot figure out whats causing my problems. I walked my CriminalIntent program through the upgrades in Chapter 14. I thought everything was going well, but then I started receiving the error described in the title.

Confused, I started searching, and could find no problem with the code. To compare, I opened up the solution code from Chapter 14, and tried to run that. Again, it compiles perfectly, but ultimately the app immediately shuts down, resulting in the very same error. Ive tried various other programs with success. The only ones that seem to cause this error are the CriminalIntent apps which deal with SQLite.

I’ve scoured the internet for help, and can’t find any.

Here’s whats inside my debug console:

$ adb shell am start -n “com.bignerdranch.android.criminalintent/com.bignerdranch.android.criminalintent.CrimeListActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.bignerdranch.android.criminalintent.test | com.bignerdranch.android.criminalintent
Waiting for application to come online: com.bignerdranch.android.criminalintent.test | com.bignerdranch.android.criminalintent
Waiting for application to come online: com.bignerdranch.android.criminalintent.test | com.bignerdranch.android.criminalintent
Waiting for application to come online: com.bignerdranch.android.criminalintent.test | com.bignerdranch.android.criminalintent
Waiting for application to come online: com.bignerdranch.android.criminalintent.test | com.bignerdranch.android.criminalintent
Waiting for application to come online: com.bignerdranch.android.criminalintent.test | com.bignerdranch.android.criminalintent
Waiting for application to come online: com.bignerdranch.android.criminalintent.test | com.bignerdranch.android.criminalintent
Connecting to com.bignerdranch.android.criminalintent
Connected to the target VM, address: ‘localhost:8611’, transport: 'socket’
Disconnected from the target VM, address: ‘localhost:8611’, transport: ‘socket’

I was wondering if anyone ran into the same issues, and could help guide me in the right direction, because unfortunately this is hindering almost all of my progress :frowning:

Thank you in advance! :slight_smile:

ps. my target AVD is a nexus 5x 4.4 kitkat, and runs API 19, and prior to this problem, has successfully run every program in the book


#2

To figure out what the problem is, you’ll need to find the stacktrace in LogCat. The debugging chapter of the book walks through how to find a stacktrace from a crash.

If you find that stacktrace and you’re still not sure what the problem is, feel free to post your stacktrace here.


#3

i am having the same problem after adding the listing 14.6 this is what the LogCat has in it
06-26 01:11:50.020 4213-4213/? E/SQLiteLog: (1) table schema_lookup already exists
06-26 01:11:50.022 4213-4213/? E/ReportSQLiteOpenHelper: Exception in isDataLeftInDB(): android.database.sqlite.SQLiteException: table schema_lookup already exists (code 1): , while compiling: CREATE TABLE schema_lookup(ID INTEGER PRIMARY KEY AUTOINCREMENT,DateTime TEXT,schema TEXT,tableid TEXT,description TEXT,servertype TEXT)
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(table schema_lookup already exists (code 1): , while compiling: CREATE TABLE schema_lookup(ID INTEGER PRIMARY KEY AUTOINCREMENT,DateTime TEXT,schema TEXT,tableid TEXT,description TEXT,servertype TEXT))
#################################################################


#4

i am having the same problem after adding the listing 14.6 this is what the LogCat has in it
06-26 01:11:50.020 4213-4213/? E/SQLiteLog: (1) table schema_lookup already exists
06-26 01:11:50.022 4213-4213/? E/ReportSQLiteOpenHelper: Exception in isDataLeftInDB(): android.database.sqlite.SQLiteException: table schema_lookup already exists (code 1): , while compiling: CREATE TABLE schema_lookup(ID INTEGER PRIMARY KEY AUTOINCREMENT,DateTime TEXT,schema TEXT,tableid TEXT,description TEXT,servertype TEXT)
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(table schema_lookup already exists (code 1): , while compiling: CREATE TABLE schema_lookup(ID INTEGER PRIMARY KEY AUTOINCREMENT,DateTime TEXT,schema TEXT,tableid TEXT,description TEXT,servertype TEXT))
#################################################################


#5

Your logs say “table schema_lookup already exists”. So you’ve already created that table.

A few times in the book, we ask you to uninstall the app and reinstall it to wipe out the database and start from scratch.

You would want to write a migration in a real app to convert from one version of the database to the next (and we talk about that in the book too), but for this app that we are building, we just wipe the data and start from scratch.


#6

after that now i have the following problem
06-26 21:20:35.019 19166-19166/? E/Zygote: isWhitelistProcess - Process is Whitelisted
06-26 21:20:35.020 19166-19166/? E/libpersona: scanKnoxPersonas
Couldn’t open the File - /data/system/users/0/personalist.xml - No such file or directory


#7

and when i run the code on the emulator i get same Error


#8

Did you delete the app from your emulator?

The errors you posted from your phone, aren’t real errors. Those aren’t crashing issues and are related to what’s going on with your phone and not the app.


#9

well how can i get the app to run cause its crashing when the app is created i tried to use a different phone still crashes


#10

does this make it more clear of what is going wrong.
06-27 21:14:16.110 975-975/? E/audit: type=1400 audit(1530148456.102:6670): avc: denied { read } for pid=28875 comm=“Bg_Shared1” name=“boot_id” dev=“proc” ino=1579505 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0 SEPF_SAMSUNG-SM-G891A_8.0.0_0009 audit_filtered
type=1300 audit(1530148456.102:6670): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=cfe1dd20 a2=20000 a3=0 items=0 ppid=1008 pid=28875 auid=4294967295 uid=10118 gid=10118 euid=10118 suid=10118 fsuid=10118 egid=10118 sgid=10118 fsgid=10118 tty=(none) ses=4294967295 comm=“Bg_Shared1” exe="/system/bin/app_process32" subj=u:r:untrusted_app_25:s0:c512,c768 key=(null)
type=1327 audit(1530148456.102:6670): proctitle=“com.facebook.katana”
06-27 21:14:16.111 28875-29325/? E/fb4a.BootIdReader: Error reading boot_id from procfs
java.io.FileNotFoundException: /proc/sys/kernel/random/boot_id (Permission denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:200)
at java.io.FileInputStream.(FileInputStream.java:150)
at java.io.FileInputStream.(FileInputStream.java:103)
at java.io.FileReader.(FileReader.java:58)
at X.2AU.D(:522155)
at X.30Z.B(Unknown Source:871)
at X.0He.B(Unknown Source:31)
at X.0IH.F(:48174)
at X.0IH.D(:48162)
at X.2w9.D(:691848)
at X.2w9.E(:691852)
at X.2w9.A(:691823)
at X.4LZ.init(:942449)
at X.0Nz.run(:60794)
at X.0NF.run(:59604)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at X.0OX.run(:62650)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at X.0Ky.run(:53570)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at X.0OZ.run(:62672)
at java.lang.Thread.run(Thread.java:764)


#11

Any time you get a crash, search for “FATAL EXCEPTION” in the stacktrace and that will lead you to the actual cause of the crash.

I don’t see that in your latest series of logs.


#12

07-19 13:14:51.301 13021-13021/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bignerdranch.android.criminalintent, PID: 13021
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.criminalintent/com.bignerdranch.android.criminalintent.CrimeListActivity}: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/com.bignerdranch.android.criminalintent/databases/crimeBase.db
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/com.bignerdranch.android.criminalintent/databases/crimeBase.db
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1588)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1464)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1632)
at com.bignerdranch.android.criminalintent.CrimeLab.queryCrimes(CrimeLab.java:86)
at com.bignerdranch.android.criminalintent.CrimeLab.getCrimes(CrimeLab.java:47)
at com.bignerdranch.android.criminalintent.CrimeListFragment.updateUI(CrimeListFragment.java:94)
at com.bignerdranch.android.criminalintent.CrimeListFragment.onCreateView(CrimeListFragment.java:66)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1340)
at android.app.Activity.performStart(Activity.java:7191)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
07-19 13:14:51.353 13021-13021/? I/Process: Sending signal. PID: 13021 SIG: 9


#13

That line of the logs is interesting. Are you calling close() on your database somehow? Take a look at your code related to the initial set up of the database.


#14

I am not seeing the problem can you take a look at my code and help me find the problem i have been stuck for weeks https://github.com/anthonysmcbrayer28/CriminalIntent.git


#15

This line of code looks suspect to me: https://github.com/anthonysmcbrayer28/CriminalIntent/blob/master/app/src/main/java/com/bignerdranch/android/criminalintent/CrimeLab.java#L33

By loading your database in that try (...) block, you are asking for the database to be cleaned up once that try block is completed (very early). Try removing the try block.


#16

it stopped it from crashing but now when i hit new crime it just shows up a blank screen should it be doing that at this point. are did i remove something that made that happen