【发布时间】:2014-01-29 09:15:19
【问题描述】:
我无法使用 Intent 启动 Main Activity。我在此代码末尾提到的错误。我该如何解决这个错误?
Activity类型中的方法startActivity(Intent)不是 适用于参数(意图)
package com.example.rishabhsintent;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Intent extends Activity {
Button b;
EditText e;
TextView t;
SharedPreferences.Editor spe;
SharedPreferences sp;
public Intent(Intent intent, Class<MainActivity> class1) {
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent);
spe = sp.edit();
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
spe.putString("Message", e.getText().toString());
spe.commit();
startActivity(new Intent(Intent.this, MainActivity.class));
}//Error on startActivity;it says"The method startActivity(Intent) in the type Activity is not applicable for the arguments (Intent)"
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
【问题讨论】:
-
请更改您的活动名称。现在真的很混乱。
-
这个问题似乎是题外话,因为它是关于提问者直接提问的。