28

I just used Android SDK Manager to update Android SDK Tools to revision 17, and Android Compatiblity to revision 7. Now, the program I've been running for ages crashes on startup.

Narrowing down the issue, I have created a new blank project, added android-support-v4.jar to the build path, and changed Activity to FragmentActivity and that's all. Now it crashes.

The error message is:

java.lang.ClassNotFoundException: com.example.test.TestActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.test-2.apk]

The code is:

package com.example.test;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class TestActivity extends FragmentActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Everything else, including the manifest, is unchanged from the defaults. Any help is much appreciated!

Edit: Manifest included below:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="9" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Dave
  • 2,248
  • 1
  • 21
  • 28

8 Answers8

27

Turns out it's a problem with Android SDK Tools r17. I had previously been using the method given in the tutorial at:

http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/

However, this no longer works. Instead, all I needed to do was right-click on my project in Eclipse and choose Android Tools-->Add Support Library...

Doing this means it is no longer necessary to go to Java Build Path and click "Add External JARs..."

Many thanks to eMich for this solution from: Jar-file issue with ADT r17

Community
  • 1
  • 1
Dave
  • 2,248
  • 1
  • 21
  • 28
  • Just trying to get started with fragments ... that saved me some time. It's nice to be informed about this issue. Thanks. – Knickedi May 02 '12 at 14:07
  • I don't see why you no longer need to add external jar compatibility library. – IgorGanapolsky May 09 '12 at 18:37
  • @igor-ganapolsky I think Eclipse does that for you when you click the "add support library" button. It actually copies the .jar file to the /libs folder, which results in it being deployed with the app. A question I will ask though, is why the old method doesn't work anymore. – Nilzor May 08 '13 at 12:47
  • 3
    adding the support library via Android Tools still causes my code to crash, the culprit as i identified is v4.FragmentActivity – DevZer0 May 28 '13 at 04:03
  • Thank, though besides this I had to go to project properties, java build path, and select "Android private libraries" in "Order and Export" in order for it to work – h4lc0n Jun 04 '13 at 14:07
11

I had the same issue and none of the answers I found in stackoverflow solved my problem. After hours of several (many) trial-and-error, I solved my problem by configuring build path of my project. In Eclipse, right click the project > Build Path > Configure Build Path..., in Order and Export tab, check Android Private Libraries, click OK. After that, clean up the project and try running again.

I solved this problem by comparing my project with other (newly created) project that could run as expected. I compared each configurations and AndroidManifest.xml of them.

Hope this helps you too :)

UPDATE Other solution: using ANT

I found another way to solve this problem: using ANT. My friend faced the same issue, but fixing the build path didn't solve his problem. I don't know whether it was because we use the different IDE version, different ADT version, or different operating system (I use GNU/Linux). And then, I suggested him to use ANT rather than the IDE's one.

First, setup the project (create build.xml) by executing android update project -p <project-dir> -n <project-name> for each project (including library projects). And then, from the main project's directory, execute ant debug to build, ant installd to install, and run the application.

The strange thing was, once he succeeded with this way, he even can compile by using IDE again, without ANT at all.

fikr4n
  • 3,250
  • 1
  • 25
  • 46
  • Upvoted. Found the same answer independently (and also after a few hours experimentation). Nasty moment when an app that had been working for months suddently starts crashing on startup, following an upgrade of the dev tools. Belongs on the Android gotchas list. – JulianSymes Jun 17 '13 at 13:51
  • Exact same thing happened to me, this is indeed the correct answer. – Jackson Walters Jun 18 '13 at 09:43
  • For 3 days I was trying to find the solution. Thanks a lot! :D – opc0de Jul 11 '13 at 09:12
0

I got the

 java.lang.NoClassDefFoundError: com.android.example.SupportFragment
    at com.android.example.SupportFragmentActivity.onCreate()

on PopupMenu

SupportFragment extends SherlockFragment implements PopupMenu.OnMenuItemClickListener
...
    @Override
    public boolean onMenuItemClick(android.view.MenuItem item) {
        return onOptionsItemSelected(item);
    }

when trying to make a api 17 app compatible with api 8, the only indication was the logcat error above, so check that all your imported classes are supported if you get this error.

TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
0

Same issue got solved by Doing Build path->Configure Build path->order and export->Check Add private libraries->ok.

Then clean up the project.

Done a big problem solved.

Rach
  • 21
  • 3
0

I also got the same issue, and resolved it by the below way. If because of some reason you have UNCHECKED to the private libraries from build path, so just add Androidv-4 jar in build path and enable(check) it in "Order and Export" tab

Kuldip Sharma
  • 782
  • 1
  • 6
  • 8
0

I assume that fragment activity is listed in the manifest properly? Here's my main FragmentActivity class in the Manifest:

    <activity android:name=".Polling" android:label="@string/app_name"
        android:windowSoftInputMode="stateHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
Davek804
  • 2,804
  • 4
  • 26
  • 55
  • Yes, mine looks just like yours, except the name is ".TestActivity" and I don't have the SoftInputMode thing. – Dave Mar 29 '12 at 18:37
  • Yeah, the softinput thing is irrelevant here and I could have just changed the activity's name for you I suppose. Hmm... have you tried using compatibility pack 16 rather than 4? – Davek804 Mar 29 '12 at 18:53
  • Rolling back to the previous revision of the compatibility pack would be ideal. Is there any way to get a previous revision though? I don't see any option to do so. – Dave Mar 30 '12 at 18:11
  • @Dave: I suggest you just make a new package, adding in the v16 libraries instead of the v4 just to see what to do. THe directory for the jar is: \android-sdks\extras\android\support\v13. Just add it the same as you would v4. If you load it properly and your new project functions fine, you can make the appropriate changes to your real project. If you need any help changing/removing/adding, just let me know and we can start up a StackOver flow chat to sort it out live. – Davek804 Mar 30 '12 at 18:48
  • 1
    Thanks for all the help, I really appreciate it. I created a new project and put in the v13 library but it made no difference. I've also tried uninstalling/reinstalling the whole of my Android SDK, also making no difference. I'm going to persevere a bit more tonight, and if I can't make it work I'm considering reinstalling Eclipse. From the lack of usable results after several Google searches I figure it must be something to do with how I've got things configured rather than an Eclipse/Android thing. – Dave Mar 30 '12 at 20:16
  • No problem. I actually dealt with a very similar problem where adding in the compatability libraries removed my R file, so the whole project became useless. It took five or six solutions to finally repair the problem, including changing projects entirely. So if you don't sort this out, I'd be glad to lend a further hand if needed. I don't know how to start a private chat/PM you on here, but they don't like when there are long conversations in comments, so we'd have to sort out how to make a chat. – Davek804 Mar 30 '12 at 21:06
0

select your project in Package Explorer > Right Click it > Android Tools > Fix PRoject Properties and also Try Project > Clean

Then rerun.

petey
  • 16,914
  • 6
  • 65
  • 97
  • Thanks for the idea, but it didn't work. I tried deleting and reinstalling the compatibility package too but that made no difference. – Dave Mar 29 '12 at 18:36
  • 1
    For what it's worth, I tried all the other solutions posted in this thread first, but it was only when I tried Project > Clean that the app started running again. – GarrickW Jul 01 '13 at 20:41
-1
  1. Remove anything lib about v7 or v4. Move your Android project, Alt+Enter, click android, look is lib: make sure there is nothing about v7 or v4 lib
  2. add v4 lib
  3. clean project
  4. run again

enter image description here enter image description here enter image description here

if you remove v7, will be error with styles... you may look this

enter image description here

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Z.Daiv
  • 1