0

我一直在关注这个教程

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)
4

2 回答 2

1

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

此问题是由于库的管理方式与新 ADT 构建不同。

于 2012-08-04T06:49:39.657 回答
0

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

例如,当 twitter 库使用 slf4j 库进行日志记录,但您尚未将其包含在类路径中时,就会出现此错误。

此外,下次发布时,请确保输入完整的错误日志。仅 1 行没有太大帮助

于 2012-05-28T21:08:21.870 回答