[英]The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (startingpoint)
I am trying to develop a twitter client using android. 我正在尝试使用android开发一个twitter客户端。 My entire code is error free for now excepting the line " signIn.setOnClickListener(this);".
除了“ signIn.setOnClickListener(this);”这一行外,我的整个代码目前没有错误。 I've tried following every other suggestion but they don't seem to help.
我尝试遵循所有其他建议,但它们似乎无济于事。 The error reported is "The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (startingpoint)".
报告的错误是“类型View中的方法setOnClickListener(View.OnClickListener)不适用于自变量(起点)”。 According to suggestions it seems i should use "View" instead of "signIn".
根据建议,看来我应该使用“查看”而不是“登录”。 What could be the possible explanation and where do i need to correct my code?
可能的解释是什么?我需要在哪里更正我的代码?
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
}
}` }`
this is because the interface your activity implements is wrong! 这是因为您的活动实现的接口是错误的!
import android.content.DialogInterface.OnClickListener;
...
public class startingpoint extends Activity implements OnClickListener {
you should implements this interface View.OnClickListener
. 您应该实现此接口
View.OnClickListener
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.