2013-12-17 2 views
0

자습서를 기반으로 Android 용 지저귐 클라이언트를 만들고 있습니다. 내가 그것을 컴파일하고 트위터에 인증하기 위해 메뉴를 누르면, 갑자기 "안타깝게도 APP가 멈췄다"라는 경고와 함께 애플리케이션이 멈췄다. 여기 안타깝게도 APP가 중지되었습니다. - Android Twitter Client

는 프로그램의 로그 캣입니다 :

12-17 17:02:07.025: E/AndroidRuntime(24713): FATAL EXCEPTION: main 
12-17 17:02:07.025: E/AndroidRuntime(24713): java.lang.NoClassDefFoundError: oauth.signpost.commonshttp.CommonsHttpOAuthConsumer 
12-17 17:02:07.025: E/AndroidRuntime(24713): at com.tmm.android.twitter.AuthActivity.askOAuth(AuthActivity.java:106) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at com.tmm.android.twitter.AuthActivity.access$0(AuthActivity.java:104) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at com.tmm.android.twitter.AuthActivity$1.onClick(AuthActivity.java:53) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at android.view.View.performClick(View.java:4223) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at android.view.View$PerformClick.run(View.java:17275) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at android.os.Handler.handleCallback(Handler.java:615) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at android.os.Handler.dispatchMessage(Handler.java:92) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at android.os.Looper.loop(Looper.java:137) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at android.app.ActivityThread.main(ActivityThread.java:4898) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at java.lang.reflect.Method.invokeNative(Native Method) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at java.lang.reflect.Method.invoke(Method.java:511) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775) 
12-17 17:02:07.025: E/AndroidRuntime(24713): at dalvik.system.NativeStart.main(Native Method) 

그리고 이것은 기본 클래스입니다 :

package com.tmm.android.twitter; 


import oauth.signpost.OAuthProvider; 
import oauth.signpost.basic.DefaultOAuthProvider; 
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; 
import twitter4j.Twitter; 
import twitter4j.TwitterFactory; 
import twitter4j.http.AccessToken; 
import android.app.Activity; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

import com.tmm.android.twitter.appliaction.TwitterApplication; 
import com.tmm.android.twitter.util.Constants; 



public class AuthActivity extends Activity { 

    private Twitter twitter; 
    private OAuthProvider provider; 
    private CommonsHttpOAuthConsumer consumer; 

    private String CONSUMER_KEY =   "CV78QI1eZAgGe9mMS7A"; 
    private String CONSUMER_SECRET =  "zCYkLsHlAVf7DoWJlDbfqeFsghXQCu2dUaFC2O94HQ"; 
    private String CALLBACK_URL =   "callback://tweeter"; 

    private Button buttonLogin; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     System.setProperty("http.keepAlive", "false"); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main_oauth); 

     //check for saved log in details.. 
     checkForSavedLogin(); 

     //set consumer and provider on teh Application service 
     getConsumerProvider(); 

     //Define login button and listener 
     buttonLogin = (Button)findViewById(R.id.ButtonLogin); 
     buttonLogin.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       askOAuth(); 
      } 
     }); 
    } 

    private void checkForSavedLogin() { 
     // Get Access Token and persist it 
     AccessToken a = getAccessToken(); 
     if (a==null) return; //if there are no credentials stored then return to usual activity 

     // initialize Twitter4J 
     twitter = new TwitterFactory().getInstance(); 
     twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
     twitter.setOAuthAccessToken(a); 
     ((TwitterApplication)getApplication()).setTwitter(twitter); 

     startFirstActivity(); 
     finish(); 
    } 

    /** 
    * Kick off the activity to display 
    */ 
    private void startFirstActivity() { 
     System.out.println("STARTING FIRST ACTIVITY!"); 
     Intent i = new Intent(this, TweetsActivity.class); 
     startActivityForResult(i, Constants.ACTIVITY_LATEST_TWEETS); 
    } 

    /** 
    * This method checks the shared prefs to see if we have persisted a user token/secret 
    * if it has then it logs on using them, otherwise return null 
    * 
    * @return AccessToken from persisted prefs 
    */ 
    private AccessToken getAccessToken() { 
     SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME, MODE_PRIVATE); 
     String token = settings.getString("accessTokenToken", ""); 
     String tokenSecret = settings.getString("accessTokenSecret", ""); 
     if (token!=null && tokenSecret!=null && !"".equals(tokenSecret) && !"".equals(token)){ 
      return new AccessToken(token, tokenSecret); 
     } 
     return null; 
    } 



    /** 
    * Open the browser and asks the user to authorize the app. 
    * Afterwards, we redirect the user back here! 
    */ 
    private void askOAuth() { 
     try { 
      consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
      provider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token", "http://twitter.com/oauth/access_token", "http://twitter.com/oauth/authorize"); 
      String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL); 
      Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show(); 
      setConsumerProvider(); 
      startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl))); 
     } catch (Exception e) { 
      Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); 
     } 
    } 


    /** 
    * As soon as the user successfully authorized the app, we are notified 
    * here. Now we need to get the verifier from the callback URL, retrieve 
    * token and token_secret and feed them to twitter4j (as well as 
    * consumer key and secret). 
    */ 
    @Override 
    protected void onResume() { 
     super.onResume(); 
     System.out.println("RESUMING!!"); 
     if (this.getIntent()!=null && this.getIntent().getData()!=null){ 
      Uri uri = this.getIntent().getData(); 
      if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { 
       String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER); 
       try { 
        // this will populate token and token_secret in consumer 
        provider.retrieveAccessToken(consumer, verifier); 

        // Get Access Token and persist it 
        AccessToken a = new AccessToken(consumer.getToken(), consumer.getTokenSecret()); 
        storeAccessToken(a); 

        // initialize Twitter4J 
        twitter = new TwitterFactory().getInstance(); 
        twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
        twitter.setOAuthAccessToken(a); 
        ((TwitterApplication)getApplication()).setTwitter(twitter); 
        //Log.e("Login", "Twitter Initialised"); 

        startFirstActivity(); 

       } catch (Exception e) { 
        //Log.e(APP, e.getMessage()); 
        e.printStackTrace(); 
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); 
       } 
      } 
     } 
    } 

    /** 
    * This method persists the Access Token information so that a user 
    * is not required to re-login every time the app is used 
    * 
    * @param a - the access token 
    */ 
    private void storeAccessToken(AccessToken a) { 
     SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME, MODE_PRIVATE); 
     SharedPreferences.Editor editor = settings.edit(); 
     editor.putString("accessTokenToken", a.getToken()); 
     editor.putString("accessTokenSecret", a.getTokenSecret()); 
     editor.commit(); 
    } 


    /** 
    * Get the consumer and provider from the application service (in the case that the 
    * activity is restarted so the objects are not lost 
    */ 
    private void getConsumerProvider() { 
     OAuthProvider p = ((TwitterApplication)getApplication()).getProvider(); 
     if (p!=null){ 
      provider = p; 
     } 
     CommonsHttpOAuthConsumer c = ((TwitterApplication)getApplication()).getConsumer(); 
     if (c!=null){ 
      consumer = c; 
     } 
    } 


    /** 
    * Set the consumer and provider from the application service (in the case that the 
    * activity is restarted so the objects are not lost) 
    */ 
    private void setConsumerProvider() { 
     if (provider!=null){ 
      ((TwitterApplication)getApplication()).setProvider(provider); 
     } 
     if (consumer!=null){ 
      ((TwitterApplication)getApplication()).setConsumer(consumer); 
     } 
    } 

} 

정말

+0

매니페스트에서이 활동에 인 텐트 필터를 정의하고 설정하십시오. –

답변

1

을 주시면 감사하겠습니다 어떤 도움이 시도 :

프로젝트/속성/Java 빌드 경로/순서 및 내보내기로 이동 - 앞에 체크 표시가 있는지 확인하십시오. Android 종속성 및 지원 라이브러리 (사용하는 경우). 모든 체크 박스를 선택하고 적용을 클릭하고 프로젝트를 정리하십시오.

희망이 도움이됩니다.

관련 문제