第一个Activitypackage richy.activity;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class Activity_02Activity extends Activity {
    /** Called when the activity is first created. */
private Button myButton = null;
@Override
   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myButton = (Button)findViewById(R.id.myButton);
        myButton.setText("第二个Activity");
        myButton.setOnClickListener(new MyButtonListener());
    }

class MyButtonListener implements android.view.View.OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(Activity_02Activity.this, OtherActivity.class);
Activity_02Activity.this.startActivity(intent);
}

}}第二个Activitypackage richy.activity;import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;public class OtherActivity extends Activity{
private TextView myTextView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.string.other);
myTextView = (TextView)findViewById(R.id.mytextView);
myTextView.setText(R.string.app_name);
}}
在AndroidManifest.xml中已经注册了第二个Activity。
点击Button之后,程序就错误停止了。

解决方案 »

  1.   

    检查一下AndroidManifest.xml中的命名是否跟程序中的一样。
      

  2.   

    1. setContentView(R.string.other);???
    这是什么东西?这里面应该是放layout吧?
    2.检查AndroidManifest.xml中注册OtherActivity 的写法是否正确
      

  3.   

    R.string.other  是我自己定义的一个字符串,这个肯定没影响的。setContentView(R.string.other);
    这个是错了,已经改正,但是问题还是没有解决。
    AndroidManifest.xml也没有问题。还是没有解决。刚刚接触android,JAVA也不是很懂,学起来挺吃力的。唉
      

  4.   

    lz同学,logcat信息是很好的调试参考
    你直说现象,不告知logcat输出
    神仙也不知道怎么帮你解决啊请贴出logcat输出
      

  5.   

    05-06 01:09:37.651: E/AndroidRuntime(393): FATAL EXCEPTION: main
    05-06 01:09:37.651: E/AndroidRuntime(393): java.lang.RuntimeException: Unable to start activity ComponentInfo{richy.activity/richy.activity.OtherActivity}: java.lang.NullPointerException
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.os.Handler.dispatchMessage(Handler.java:99)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.os.Looper.loop(Looper.java:123)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at java.lang.reflect.Method.invokeNative(Native Method)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at java.lang.reflect.Method.invoke(Method.java:507)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at dalvik.system.NativeStart.main(Native Method)
    05-06 01:09:37.651: E/AndroidRuntime(393): Caused by: java.lang.NullPointerException
    05-06 01:09:37.651: E/AndroidRuntime(393):  at richy.activity.OtherActivity.onCreate(OtherActivity.java:15)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    05-06 01:09:37.651: E/AndroidRuntime(393):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    05-06 01:09:37.651: E/AndroidRuntime(393):  ... 11 morLogcat
      

  6.   

    顶2楼,应该是setContentView(R.Layout.other)?
      

  7.   

    class MyButtonListener implements android.view.View.OnClickListener{
    换成
    private final Button.OnClickListener MyButtonListener = new Button.OnClickListener()  {