当无法找到的类清楚地在项目中时,我收到 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 的类。我已经尝试在类路径上进行排序和导出,将 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