public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = new Button(this);
button1 = (Button) findViewById(R.id.click_me);
button1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent nextActivity = new Intent(this, NextActivity.class);
startActivity(nextActivity);
}
}
);
}
嗨,大家好,我在声明/创建一个新的意图实例时遇到错误,
Intent nextActivity = new Intent(this, NextActivity.class);
它说无法解析构造函数Intent .... 有什么问题?
很抱歉这篇长篇文章,希望你们能尽快告诉我。 谢谢!
答案 0 :(得分:4)
试试这个
button1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent nextActivity = new Intent(MainActivity.this, NextActivity.class);
startActivity(nextActivity);
}
}
);
并确保您必须在NextActivity.class
AndroidManifest.xml