Sample apps using Fragments crash


#1

After installing the latest revisions to the SDK and ADT in Eclipse, all the book’s sample apps that use Fragments now crash as soon as they start up. All other apps run just fine. So, I downloaded the ADT bundle for Windows and tried that. Same result. The Android Support Library is installed and everything seems fine until I run the project. For the solution provided for chapter 7, the Android Console shows:

[2013-05-26 21:30:28 - 07_UIFragments_CriminalIntent] ------------------------------
[2013-05-26 21:30:28 - 07_UIFragments_CriminalIntent] Android Launch!
[2013-05-26 21:30:28 - 07_UIFragments_CriminalIntent] adb is running normally.
[2013-05-26 21:30:28 - 07_UIFragments_CriminalIntent] Performing com.bignerdranch.android.criminalintent.CrimeActivity activity launch
[2013-05-26 21:30:28 - 07_UIFragments_CriminalIntent] Automatic Target Mode: using existing emulator ‘emulator-5554’ running compatible AVD ‘Android2.3.3Level10’
[2013-05-26 21:30:28 - 07_UIFragments_CriminalIntent] Uploading 07_UIFragments_CriminalIntent.apk onto device ‘emulator-5554’
[2013-05-26 21:30:28 - 07_UIFragments_CriminalIntent] Installing 07_UIFragments_CriminalIntent.apk…
[2013-05-26 21:30:32 - 07_UIFragments_CriminalIntent] Success!
[2013-05-26 21:30:33 - 07_UIFragments_CriminalIntent] Starting activity com.bignerdranch.android.criminalintent.CrimeActivity on device emulator-5554
[2013-05-26 21:30:34 - 07_UIFragments_CriminalIntent] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.bignerdranch.android.criminalintent/.CrimeActivity }

The emulator (API Level 10) says:

Sorry! The application CriminalIntent(process com.bignerdranch.android.criminalintent) has stopped unexpectedly. Please try again.
Force close

Here is the stack trace from LogCat:

05-25 22:30:09.465: W/dalvikvm(331): Unable to resolve superclass of Lcom/bignerdranch/android/criminalintent/CrimeActivity; (3)
05-25 22:30:09.545: W/dalvikvm(331): Link of class ‘Lcom/bignerdranch/android/criminalintent/CrimeActivity;’ failed
05-25 22:30:09.606: D/AndroidRuntime(331): Shutting down VM
05-25 22:30:09.606: W/dalvikvm(331): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-25 22:30:09.706: E/AndroidRuntime(331): FATAL EXCEPTION: main
05-25 22:30:09.706: E/AndroidRuntime(331): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.bignerdranch.android.criminalintent/com.bignerdranch.android.criminalintent.CrimeActivity}: java.lang.ClassNotFoundException: com.bignerdranch.android.criminalintent.CrimeActivity in loader dalvik.system.PathClassLoader[/data/app/com.bignerdranch.android.criminalintent-2.apk]
05-25 22:30:09.706: E/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.os.Looper.loop(Looper.java:123)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-25 22:30:09.706: E/AndroidRuntime(331): at java.lang.reflect.Method.invokeNative(Native Method)
05-25 22:30:09.706: E/AndroidRuntime(331): at java.lang.reflect.Method.invoke(Method.java:507)
05-25 22:30:09.706: E/AndroidRuntime(331): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-25 22:30:09.706: E/AndroidRuntime(331): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-25 22:30:09.706: E/AndroidRuntime(331): at dalvik.system.NativeStart.main(Native Method)
05-25 22:30:09.706: E/AndroidRuntime(331): Caused by: java.lang.ClassNotFoundException: com.bignerdranch.android.criminalintent.CrimeActivity in loader dalvik.system.PathClassLoader[/data/app/com.bignerdranch.android.criminalintent-2.apk]
05-25 22:30:09.706: E/AndroidRuntime(331): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-25 22:30:09.706: E/AndroidRuntime(331): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-25 22:30:09.706: E/AndroidRuntime(331): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-25 22:30:09.706: E/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
05-25 22:30:09.706: E/AndroidRuntime(331): … 11 more
05-25 22:30:18.055: I/Process(331): Sending signal. PID: 331 SIG: 9


#2

Yeah, it looks like they changed how jar dependencies work. Keep an eye out - we will get this fixed sometime this week. I’ll post here and in General Discussion when they’re updated.


#3

The following seems to fix the problem:

  1. Right-click the Project in Package Explorer > Build Path > Configure Build Path…
  2. Select Order and Export tab.
  3. Check checkbox and select android-support-v4.jar - 07_UIFragments_CriminalIntents/libs and move Up to third position.
  4. Click OK.

The project now runs without error.

This process has also worked with the solutions provided for chapters 8, 9, and 18 on both Windows and Ubuntu 12. :smiley:


#4

Same problems after refreshing latest ADT and SDKs. Activity based projects look ok. But, for fragment based projects, I am getting

05-31 09:32:16.238: D/AndroidRuntime(21610): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-31 09:32:16.246: D/AndroidRuntime(21610): CheckJNI is OFF
05-31 09:32:16.246: D/dalvikvm(21610): creating instr width table
05-31 09:32:16.527: D/dalvikvm(21610): No JNI_OnLoad found in /system/lib/libidme.so 0x0, skipping init
05-31 09:32:16.527: D/AndroidRuntime(21610): Calling main entry com.android.commands.pm.Pm
05-31 09:32:16.535: D/AndroidRuntime(21610): Shutting down VM
05-31 09:32:16.535: I/AndroidRuntime(21610): NOTE: attach of thread ‘Binder Thread #3’ failed
05-31 09:32:16.535: D/dalvikvm(21610): GC_CONCURRENT freed 105K, 71% free 305K/1024K, external 0K/0K, paused 0ms+1ms
05-31 09:32:16.535: D/dalvikvm(21610): Debugger has detached; object registry had 1 entries
05-31 09:32:16.636: D/AndroidRuntime(21620): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-31 09:32:16.636: D/AndroidRuntime(21620): CheckJNI is OFF
05-31 09:32:16.636: D/dalvikvm(21620): creating instr width table
05-31 09:32:16.761: D/dalvikvm(21620): No JNI_OnLoad found in /system/lib/libidme.so 0x0, skipping init
05-31 09:32:16.761: D/AndroidRuntime(21620): Calling main entry com.android.commands.am.Am
05-31 09:32:16.769: D/ActivityManager(1399): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.bignerdranch.android.criminalintent/.CrimeActivity } from pid 21620
05-31 09:32:16.793: D/AndroidRuntime(21620): Shutting down VM
05-31 09:32:16.793: D/dalvikvm(21620): GC_CONCURRENT freed 107K, 69% free 327K/1024K, external 0K/0K, paused 0ms+0ms
05-31 09:32:16.793: D/jdwp(21620): Got wake-up signal, bailing out of select
05-31 09:32:16.793: D/dalvikvm(21620): Debugger has detached; object registry had 1 entries
05-31 09:32:16.816: I/ActivityManager(1399): Start proc com.bignerdranch.android.criminalintent for activity com.bignerdranch.android.criminalintent/.CrimeActivity: pid=21629 uid=10005 gids={}
05-31 09:32:16.855: I/LAB126(1568): StatusBarService hears intent. action: com.lab126.intent.TOP_WINDOW_CHANGED
05-31 09:32:16.855: I/LAB126(1568): window changed
05-31 09:32:16.855: E/jdwp(21629): Failed sending reply to debugger: Broken pipe
05-31 09:32:16.855: D/dalvikvm(21629): Debugger has detached; object registry had 1 entries
05-31 09:32:16.855: I/LAB126(1568): don’t set softkey config for ‘Starting…’ window
05-31 09:32:16.863: W/dalvikvm(21629): Unable to resolve superclass of Lcom/bignerdranch/android/criminalintent/CrimeActivity; (3)
05-31 09:32:16.863: W/dalvikvm(21629): Link of class ‘Lcom/bignerdranch/android/criminalintent/CrimeActivity;’ failed
05-31 09:32:16.863: D/AndroidRuntime(21629): Shutting down VM
05-31 09:32:16.863: W/dalvikvm(21629): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-31 09:32:16.871: E/AndroidRuntime(21629): FATAL EXCEPTION: main
05-31 09:32:16.871: E/AndroidRuntime(21629): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.bignerdranch.android.criminalintent/com.bignerdranch.android.criminalintent.CrimeActivity}: java.lang.ClassNotFoundException: com.bignerdranch.android.criminalintent.CrimeActivity in loader dalvik.system.PathClassLoader[/data/app/com.bignerdranch.android.criminalintent-2.apk]
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.os.Looper.loop(Looper.java:130)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-31 09:32:16.871: E/AndroidRuntime(21629): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 09:32:16.871: E/AndroidRuntime(21629): at java.lang.reflect.Method.invoke(Method.java:507)
05-31 09:32:16.871: E/AndroidRuntime(21629): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:850)
05-31 09:32:16.871: E/AndroidRuntime(21629): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
05-31 09:32:16.871: E/AndroidRuntime(21629): at dalvik.system.NativeStart.main(Native Method)
05-31 09:32:16.871: E/AndroidRuntime(21629): Caused by: java.lang.ClassNotFoundException: com.bignerdranch.android.criminalintent.CrimeActivity in loader dalvik.system.PathClassLoader[/data/app/com.bignerdranch.android.criminalintent-2.apk]
05-31 09:32:16.871: E/AndroidRuntime(21629): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-31 09:32:16.871: E/AndroidRuntime(21629): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-31 09:32:16.871: E/AndroidRuntime(21629): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-31 09:32:16.871: E/AndroidRuntime(21629): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
05-31 09:32:16.871: E/AndroidRuntime(21629): … 11 more
05-31 09:32:16.871: W/ActivityManager(1399): Force finishing activity com.bignerdranch.android.criminalintent/.CrimeActivity
05-31 09:32:17.371: D/dalvikvm(1399): GC_FOR_MALLOC freed 1318K, 51% free 7393K/14791K, external 10266K/11882K, paused 68ms
05-31 09:32:17.379: W/ActivityManager(1399): Activity pause timeout for HistoryRecord{405254b8 com.bignerdranch.android.criminalintent/.CrimeActivity}
05-31 09:32:17.441: D/dalvikvm(1399): GC_FOR_MALLOC freed 815K, 48% free 7767K/14791K, external 10262K/11882K, paused 57ms
05-31 09:32:17.558: I/LAB126(1568): StatusBarService hears intent. action: com.lab126.intent.TOP_WINDOW_CHANGED
05-31 09:32:17.558: I/LAB126(1568): window changed
05-31 09:32:27.574: W/ActivityManager(1399): Activity destroy timeout for HistoryRecord{405254b8 com.bignerdranch.android.criminalintent/.CrimeActivity}
05-31 09:32:35.269: D/dalvikvm(20262): GC_EXPLICIT freed 18K, 49% free 2800K/5447K, external 847K/1181K, paused 59ms
05-31 09:32:39.824: V/DeviceStorageMonitorService(1399): mTotalMemory is 11734999

===
Eclipse Project build path or export setup looks Okay.
I used Amazon orig kindle fire (2.3.4) and Samsung SCH-I500 (2.3.5). I got the same errors.


#5

This looks eclipse ADT plugin issues. The latest ADT does not like the project settings for all fragment based projects from the book’s zip. For example, if I import chapter 8 project, I have to do this in order to launch the application correctly.

– Right click on the project and bring up Properties
– From Properties dialog, click on the “Java Build Path”. And click on “Libraries” tab. Remove the android-support--08 library entry.
– Click on “Order and Export” tab. Check mark on “Android Private Libraries”.

Then, it works. All book’s original projects that use the support library should go through this process in order to launch the application correctly. Otherwise, we will get the ClassNotFound exception.


#6

Getting rid of the support library reference isn’t necessary. Checking the box next to “Android Private Libraries” in Order and Export is all that is necessary.

I’ve fixed the issue in my solutions locally. We’ll have updated solutions up on our web site on Monday.


#7

Updated solutions are now up:

http://www.bignerdranch.com/solutions/AndroidProgramming.zip


#8

On "Getting rid of the support library reference isn’t necessary. "

True, either ways work. But leaving the support library reference is redundant since the Android Private Libraries include it. If we create a Android project that includes the support library with the latest ADT, it will not have the support library reference. It just have Android Dependencies and Private Libraries. That is all. Just to clarify why I removed the extra support library reference.