FragmentActivity causing ClassNotFoundException

荒凉一梦 提交于 2019-11-27 19:41:36
Dave

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

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.

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>

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

Then rerun.

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.

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.

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

Z.Daiv
  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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!