Android. Support4Demos crashes

2019-09-05 21:57发布

问题:

I have runtime errors while executing Support4Demos sample.

I'm trying to launch Support4Demos sample (both on emulator and device). There are no errors in Eclipse and it's launched well. As you know first I should select category (for instance "Fragment"), then subcategory (for instance "Tabs"). And after I've selected subcategory - app crashes with following log

12-27 16:39:51.796: E/AndroidRuntime(384): FATAL EXCEPTION: main
12-27 16:39:51.796: E/AndroidRuntime(384): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.supportv4/com.example.android.supportv4.app.FragmentTabs}: java.lang.ClassNotFoundException: com.example.android.supportv4.app.FragmentTabs in loader dalvik.system.PathClassLoader[/data/app/com.example.android.supportv4-1.apk]

I did't make any changes in the source code. May be I missed something? Could anyone help me?

回答1:

You should put the android-support-v4.jar to the directory named "libs" of your project and then refresh the project.



回答2:

If you add the android-supportv4.jar it will work. Here are some detailed instructions on how to do that:

http://developer.android.com/tools/extras/support-library.html#Downloading

You need to follow every step to a "t" in that link. However, sometimes the instructions are not very clear. So, I will try to explain what some of the instructions mean:

  • I found the .jar file which I needed to add in the following directory:

             C:\Users\nadir\android-sdks\extras\android\support\v4
    
    • the steps say, In Eclipse, right-click the JAR file in the Package Explorer, select Build Path > Add to Build Path

Let me show you what that looks like on my computer:

the instructions also say: select Build Path > Add to Build Path, you may not find it worded exactly like that. Here is what I did, i(note: I clicked on the "add external JARs" button):



回答3:

Be sure that android-supportv4.jar is in your classpath.

The jar is located under /extras/android/support/v4/android-support-v4.jar