It will shows me this kind of error when i am converting my old eclipse project into the android studio project even after i already added the twitter4j-core-3.0.3.jar file in my lib folder and i will added them Add as Library in my project than also they will shows me this kind of error they can't give me the option of ALT+ENTER for auto import.
My code is given below:-
ShareTwitterActivity.java
@SuppressLint("HandlerLeak")
public class ShareTwitterActivity extends Activity {
private TwitterApp mTwitter;
private boolean postToTwitter = false;
private String review = "";
private EditText editReview;
private ProgressDialog mProgress;
private ShareTwitterActivity context;
private int[] textview = { R.id.textView_header, R.id.text_share_msg, R.id.text_share_head,R.id.shareTwitter_edit_review };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share_twitter);
context = ShareTwitterActivity.this;
// change font of textview
if (Utility.tf != null) {
for (int i = 0; i < textview.length; i++) {
((TextView) findViewById(textview[i])).setTypeface(Utility.tf);
}
}
mProgress = new ProgressDialog(ShareTwitterActivity.this);
editReview = (EditText) findViewById(R.id.shareTwitter_edit_review);
findViewById(R.id.shareTwitter_btn_post).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (Utility.hasConnection(context)) {
review = editReview.getText().toString();
if (postToTwitter) {
postToTwitter(review + "\nAndroid Applications Here: " + Consts.APP_LINK);
} else {
Toast.makeText(ShareTwitterActivity.this, "Please Login to Continue....", Toast.LENGTH_LONG).show();
onTwitterClick();
}
} else {
Utility.showToast("Internet Connection Failed", context);
}
}
});
mTwitter = new TwitterApp(ShareTwitterActivity.this, Consts.CONSUMER_KEY, Consts.CONSUMER_SECRET);
mTwitter.setListener(mTwLoginDialogListener);
}
public void postToTwitter(final String review) {
mProgress.setMessage("Posting on Wall...");
mProgress.show();
new Thread() {
public void run() {
int what = 0;
try {
mTwitter.updateStatus(review);
} catch (Exception e) {
what = 1;
}
mHandler.sendMessage(mHandler.obtainMessage(what));
}
}.start();
}
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
mProgress.cancel();
String text = (msg.what == 0) ? "Posted to Twitter" : "Post to Twitter failed";
Toast.makeText(ShareTwitterActivity.this, text, Toast.LENGTH_SHORT).show();
Log.d("CALL", "Call Before Finish");
// ------------------Test-----------------
mTwitter.resetAccessToken();
// ------------------------------------------
onBackPressed();
}
};
private final TwDialogListener mTwLoginDialogListener = new TwDialogListener() {
public void onComplete(String value) {
postToTwitter = true;
review = editReview.getText().toString();
postToTwitter(review + "\nAwesome Android Applications Here: " + Consts.APP_LINK);
}
public void onError(String value) {
Toast.makeText(ShareTwitterActivity.this, "Twitter connection failed", Toast.LENGTH_LONG).show();
}
};
public void onTwitterClick() {
if (mTwitter.hasAccessToken()) {
final AlertDialog.Builder builder = new AlertDialog.Builder(ShareTwitterActivity.this);
builder.setMessage("Delete current Twitter connection?").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mTwitter.resetAccessToken();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
} else {
mTwitter.authorize();
}
}
protected void onDestroy() {
super.onDestroy();
}
}
build.gradle(Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:26.0.0-alpha1'
compile 'com.google.android.gms:play-services:11.0.4'
compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/signpost-jetty6-1.2.1.1.jar')
compile files('libs/twitter4j-core-3.0.3.jar')
}
It seems that TwitterApp and TwDialogListener are classes made for examples, they shouldn't be part of twitter4j-core lib