【发布时间】:2011-07-07 00:22:41
【问题描述】:
我正在尝试依次进行第三个活动。 从主要活动转到第二个活动正常,但是当我尝试从第二个活动转到第三个活动时,应用程序崩溃了。
这是我的第二个活动的代码:
package com.example.helloandroid;
import android.app.Activity;
//other imports here
public class Game extends Activity implements OnClickListener {
private static final String TAG = "Matrix";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.matrix);
View doneButton = findViewById(R.id.done_button);
doneButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.done_button:
Intent k = new Intent(this, GameTwo.class);
startActivity(k);
//finish();
break;
}
}
}
以及第三个活动的代码:
package com.example.helloandroid;
import android.app.Activity;
//other imports here
public class GameTwo extends Activity {
private static final String TAG = "Matrix";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.matrixtwo);
View donetwoButton = findViewById(R.id.donetwo_button);
}
}
【问题讨论】:
-
你能把异常粘贴到这里吗?使用亚行 LOGCAT
-
不确定,但尝试在第二个活动中使用 Button 而不是 View,然后在按钮的对象中读取 view((Button)findViewById())。这可能会解决您的问题,否则就像@swaroop 所说的将异常粘贴到此处以便其他人可以理解。
标签: java android android-activity onclick