2014-11-23 107 views
0

我正在嘗試開發使用android的twitter客戶端。現在除了「signIn.setOnClickListener(this);」這行外,我的整個代碼都是無錯的。我試着按照其他建議,但他們似乎沒有幫助。報告的錯誤是「類型View中的方法setOnClickListener(View.OnClickListener)不適用於參數(起點)」。根據建議,似乎我應該使用「查看」而不是「登錄」。可能的解釋是什麼?我需要在哪裏糾正我的代碼?類型View中的方法setOnClickListener(View.OnClickListener)不適用於參數(起點)

package com.HIT.bjak; 

import twitter4j.Twitter; 
import twitter4j.TwitterException; 
import twitter4j.TwitterFactory; 
import twitter4j.auth.AccessToken; 
import twitter4j.auth.RequestToken; 
import android.app.Activity; 
import android.content.DialogInterface; 
import android.content.DialogInterface.OnClickListener; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 

public class startingpoint extends Activity implements OnClickListener { 

/** developer account key for this app */ 
public final static String TWIT_KEY = "xxx"; 
/** developer secret for the app */ 
public final static String TWIT_SECRET = "xxx"; 
/** app url */ 
public final static String TWIT_URL = "bjak-android:///"; 
/** Twitter instance */ 
private Twitter bjak_instance; 
/** request token for accessing user account */ 
private RequestToken bjak_RequestToken; 
/** shared preferences to store user details */ 
private SharedPreferences Prefs; 

// for error logging 
private String LOG_TAG = "startingpoint"; 

Button signIn; 
String oaVerifier=null; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    // get the preferences for the app 
    bjak_instance = (Twitter) getSharedPreferences("TweetPrefs", 0); 

    // find out if the user preferences are set 
    if (Prefs.getString("user_token", null) == null) { 

     // no user preferences so prompt to sign in 
     setContentView(R.layout.main); 
     // get a twitter instance for authentication 
     bjak_instance = new TwitterFactory().getInstance(); 

     // pass developer key and secret 
     bjak_instance.setOAuthConsumer(TWIT_KEY, TWIT_SECRET); 
     // try to get request token 
     try { 
      // get authentication request token 
      bjak_RequestToken = bjak_instance.getOAuthRequestToken(TWIT_URL); 
     } catch (TwitterException te) { 
      Log.e(LOG_TAG, "TE " + te.getMessage()); 
     } 
     // setup button for click listener 
     signIn = (Button)findViewById(R.id.signin); 
     signIn.setOnClickListener(this); 
     //attempt to retrieve access token 
     try 
     { 
      //try to get an access token using the returned data from the verification page 
      AccessToken accToken = bjak_instance.getOAuthAccessToken(bjak_RequestToken, oaVerifier); 

      //add the token and secret to shared prefs for future reference 
      Prefs.edit() 
       .putString("user_token", accToken.getToken()) 
       .putString("user_secret", accToken.getTokenSecret()) 
       .commit(); 

      //display the timeline 
      setupTimeline(); 
     } 
     catch (TwitterException te) 
     { Log.e(LOG_TAG, "Failed to get access token: " + te.getMessage()); } 

    } else { 
     // user preferences are set - get timeline 
     setupTimeline(); 
    } 
} 

/** 
* Click listener handles sign in and tweet button presses 
*/ 
public void onClick(View v) { 
    // find view 
    switch (v.getId()) { 
    // sign in button pressed 
    case R.id.signin: 
     // take user to twitter authentication web page to allow app access 
     // to their twitter account 
     String authURL = bjak_RequestToken.getAuthenticationURL(); 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL))); 
     break; 
    // other listeners here 

    default: 
     break; 
    } 

} 
/* 
* onNewIntent fires when user returns from Twitter authentication Web page 
*/ 
@Override 
protected void onNewIntent(Intent intent) { 
    super.onNewIntent(intent); 
    //get the retrieved data 
    Uri twitURI = intent.getData(); 
    //make sure the url is correct 
    if(twitURI!=null && twitURI.toString().startsWith(TWIT_URL)) 
    { 
     //is verifcation - get the returned data 
     oaVerifier = twitURI.getQueryParameter("oauth_verifier"); 

    } 
} 
private void setupTimeline() { 
    Log.v(LOG_TAG, "setting up timeline"); 
    } 

@Override 
public void onClick(DialogInterface dialog, int which) { 
    // TODO Auto-generated method stub 

} 

}`

回答

0

這是因爲你的活動實現的接口是錯誤的!

import android.content.DialogInterface.OnClickListener; 
... 
public class startingpoint extends Activity implements OnClickListener { 

你應該實現這個接口View.OnClickListener

相關問題