程序打开时模拟机上显示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);
}
} 展开
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);
}
} 展开
3个回答
2015-04-08 · 知道合伙人互联网行家
关注
展开全部
PhoneRecordActivity 这个Activity在初始化的时候出现了空指针异常,检查PhoneRecordActivity.java的16行。
追问
我是初学者 找不到你说的东西在哪儿 能说详细点吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-04-08
展开全部
你少了setContentView(R.layout.****); 在super.onCreate(savedInstanceState); 下面写
更多追问追答
追问
setContentView(R.layout.activity_main);
我加了这个 还是不对呢
追答
把logcat里的信息贴上来 不然没法找
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询