打开时模拟机上显示the application has stopped unexpectedly
packagecom.example.activity_02;importandroid.os.Bundle;importandroid.app.Activity;imp...
package com.example.activity_02;
import android.os.Bundle;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button myButton = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myButton = (Button)findViewById(R.id.myButton);
myButton.setOnClickListener((android.view.View.OnClickListener) new MyButtonListener());
}
class MyButtonListener implements OnClickListener{
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(MainActivity.this, OtherActivity.class);
MainActivity.this.startActivity(intent);
}
}
}
package com.example.activity_02;
import android.os.Bundle;
import android.widget.TextView;
public class OtherActivity extends MainActivity{
private TextView myTextView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setText(R.string.other);
}
}
应该是程序内部问题,因为我可以运行helloworld的程序 展开
import android.os.Bundle;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button myButton = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myButton = (Button)findViewById(R.id.myButton);
myButton.setOnClickListener((android.view.View.OnClickListener) new MyButtonListener());
}
class MyButtonListener implements OnClickListener{
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(MainActivity.this, OtherActivity.class);
MainActivity.this.startActivity(intent);
}
}
}
package com.example.activity_02;
import android.os.Bundle;
import android.widget.TextView;
public class OtherActivity extends MainActivity{
private TextView myTextView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setText(R.string.other);
}
}
应该是程序内部问题,因为我可以运行helloworld的程序 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询