当类明显在项目中时,NoClassDefFoundError

时间:2013-06-25 05:52:32

标签: android noclassdeffounderror twitter4j

当项目中无法找到无法找到的类时,我收到NoClassDefFoundError。

错误实际上发生在AsyncTask:

    public class PrefAuth extends AsyncTask<SharedPreferences,Object, Boolean> {

    @Override
    protected Boolean doInBackground(SharedPreferences... params) {
        return TwitterUtils.isAuthenticated(params[0]);
    }

    @Override
    protected void onPostExecute(Boolean isAuthenticated) {
        if (isAuthenticated) {
            GlobalAppContext.setTwitterFlag(true);
            Log.i("here", "isAuthenticated is true");
            Intent i = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(i);
        }
        else {
            Log.i("here", "isAuthenticated is false");
            Intent i = new Intent(getApplicationContext(), LoginActivity.class); 
            startActivity(i);
        }
    }
}

错误指向行return TwitterUtils.isAuthenticated(params[0]);TwitterUtils是一个引用Twitter4j的类。我试过订单&amp;在类路径上导出,将Twitter4j移到顶部。我尝试过清洁和重建。有谁知道为什么找不到这个班级? Logcat在下面:

06-25 00:40:42.021: E/AndroidRuntime(5078): FATAL EXCEPTION: AsyncTask #1
06-25 00:40:42.021: E/AndroidRuntime(5078): java.lang.RuntimeException: An error occured while executing doInBackground()
06-25 00:40:42.021: E/AndroidRuntime(5078):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.lang.Thread.run(Thread.java:1027)
06-25 00:40:42.021: E/AndroidRuntime(5078): Caused by: java.lang.NoClassDefFoundError: twitter4j.auth.AccessToken
06-25 00:40:42.021: E/AndroidRuntime(5078):     at com.tforan.blobtag4.twitter.TwitterUtils.isAuthenticated(TwitterUtils.java:17)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at com.tforan.blobtag4.SplashActivity$PrefAuth.doInBackground(SplashActivity.java:41)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at com.tforan.blobtag4.SplashActivity$PrefAuth.doInBackground(SplashActivity.java:1)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-25 00:40:42.021: E/AndroidRuntime(5078):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
06-25 00:40:42.021: E/AndroidRuntime(5078):     ... 4 more

1 个答案:

答案 0 :(得分:0)

右键单击项目&gt;转到属性&gt; Java构建路径&gt;订单和出口&gt;查看“Android私人图书馆”

然后清理并构建项目,然后运行项目。

如果已导出到项目中,还要检查其他jar文件。

希望它会对你有所帮助。