E / AndroidRuntime(585):java.lang.NoClassDefFoundError twitter4j.http.AccessToken

时间:2012-05-28 21:02:01

标签: twitter4j

我一直在关注本教程

http://www.android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application

我为consumer_key和consumer_secret

输入了这些详细信息
public class Constants {

    public static final String CONSUMER_KEY = "<FILL IN YOUR CONSUMER KEY FROM TWITTER HERE>";
    public static final String CONSUMER_SECRET= "<FILL IN YOUR CONSUMER SECRET FROM TWITTER HERE>";

    public static final String REQUEST_URL = "http://api.twitter.com/oauth/request_token";
    public static final String ACCESS_URL = "http://api.twitter.com/oauth/access_token";
    public static final String AUTHORIZE_URL = "http://api.twitter.com/oauth/authorize";

    public static final String  OAUTH_CALLBACK_SCHEME   = "x-oauthflow-twitter";
    public static final String  OAUTH_CALLBACK_HOST     = "callback";
    public static final String  OAUTH_CALLBACK_URL      = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;

}

然后我添加了lib目录 的.classpath 也是具有此路径的文本文档 的.gitignore

这允许文件被识别为我添加的新库文件。

这是我的错误日志

05-28 21:10:10.586: E/dalvikvm(538): Could not find class 'twitter4j.http.AccessToken', referenced from method alex.android.twitter.feed.TwitterUtils.isAuthenticated
05-28 21:10:10.586: W/dalvikvm(538): VFY: unable to resolve new-instance 67 (Ltwitter4j/http/AccessToken;) in Lalex/android/twitter/feed/TwitterUtils;
05-28 21:10:10.596: D/dalvikvm(538): VFY: replacing opcode 0x22 at 0x0010
05-28 21:10:10.596: E/dalvikvm(538): Could not find class 'twitter4j.http.AccessToken', referenced from method alex.android.twitter.feed.TwitterUtils.sendTweet
05-28 21:10:10.596: W/dalvikvm(538): VFY: unable to resolve new-instance 67 (Ltwitter4j/http/AccessToken;) in Lalex/android/twitter/feed/TwitterUtils;
05-28 21:10:10.606: D/dalvikvm(538): VFY: replacing opcode 0x22 at 0x0010
05-28 21:10:10.606: D/dalvikvm(538): DexOpt: unable to opt direct call 0x006c at 0x12 in Lalex/android/twitter/feed/TwitterUtils;.isAuthenticated
05-28 21:10:10.606: D/dalvikvm(538): DexOpt: unable to opt direct call 0x006a at 0x17 in Lalex/android/twitter/feed/TwitterUtils;.isAuthenticated
05-28 21:10:10.606: D/dalvikvm(538): DexOpt: unable to opt direct call 0x006c at 0x12 in Lalex/android/twitter/feed/TwitterUtils;.sendTweet
05-28 21:10:10.606: D/dalvikvm(538): DexOpt: unable to opt direct call 0x006a at 0x17 in Lalex/android/twitter/feed/TwitterUtils;.sendTweet
05-28 21:10:10.606: D/AndroidRuntime(538): Shutting down VM
05-28 21:10:10.616: W/dalvikvm(538): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
05-28 21:10:10.636: E/AndroidRuntime(538): FATAL EXCEPTION: main
05-28 21:10:10.636: E/AndroidRuntime(538): java.lang.NoClassDefFoundError: twitter4j.http.AccessToken
05-28 21:10:10.636: E/AndroidRuntime(538):  at alex.android.twitter.feed.TwitterUtils.isAuthenticated(TwitterUtils.java:17)
05-28 21:10:10.636: E/AndroidRuntime(538):  at alex.android.twitter.feed.TwitterActivity.updateLoginStatus(TwitterActivity.java:74)
05-28 21:10:10.636: E/AndroidRuntime(538):  at alex.android.twitter.feed.TwitterActivity.onResume(TwitterActivity.java:70)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.Activity.performResume(Activity.java:4539)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.os.Looper.loop(Looper.java:137)
05-28 21:10:10.636: E/AndroidRuntime(538):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-28 21:10:10.636: E/AndroidRuntime(538):  at java.lang.reflect.Method.invokeNative(Native Method)
05-28 21:10:10.636: E/AndroidRuntime(538):  at java.lang.reflect.Method.invoke(Method.java:511)
05-28 21:10:10.636: E/AndroidRuntime(538):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-28 21:10:10.636: E/AndroidRuntime(538):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-28 21:10:10.636: E/AndroidRuntime(538):  at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:1)

我的项目也面临同样的问题。我将文件夹名称 lib 更改为 libs 然后 它对我来说很好。

这个问题是由于新的ADT版本不能以相同的方式管理库。

答案 1 :(得分:0)

NoClassDefFoundError意味着您的某个库依赖于另一个无法找到的库。如果您没有在类路径中放置所有正确的库,则很可能会出现此错误。

例如, 当twitter库使用slf4j库进行日志记录时,但是您还没有将它包含在类路径中,则会出现此错误。

下次发帖时,请务必输入完整的错误日志。只有1行没有多大帮助