//MainActivity .javapackage com.example.testwidget;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class MainActivity extends Activity {
    /** Called when the activity is first created. */
private Button b1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1 = (Button) findViewById(R.id.Button01);
        // 响应按键事件
        b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 显示方式声明Intent,直接启动SecondActivity
        Intent intent = new Intent(MainActivity.this,Result.class);
        startActivity(intent);
}
});
    }
}//**************************************
//result.java
//**************************************/
package com.example.testwidget;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class Result extends Activity {
    /** Called when the activity is first created. */
private Button b2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);
        
        b2 = (Button) findViewById(R.id.Button02);
        // 响应按键事件
        b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 显示方式声明Intent,直接启动SecondActivity
        Intent intent = new Intent(Result.this,MainActivity.class);
        startActivity(intent);
}
});
    }
}
/**********
相应的XML文件
**********/<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
<Button android:id="@+id/Button01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Second Activity"></Button>

</LinearLayout>//////////////////////////////////////////////////<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> <Button android:id="@+id/Button02" 
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:text="返回"></Button>
</LinearLayout>
为什么我一点击就出现Unfortunately, *** has stop  !!!!!!!就关闭了!!感觉程序上是没错的!这是为什么 ?android

解决方案 »

  1.   

    你可以尝试单步去调试. 可能不是你程序问题. 而是没有在Manifest文件中注册你的Result
      

  2.   


    LZ  类似FC问题  很好解决   要善于查看adb日志信息   如果是报ClassNotFond  估计就是1L说的 
    没有在Manifest文件中注册声明你的Result.class  
      

  3.   

    都注册了,情况还是一样....代码我是复制过去运行的...所以就是搞不明白 .......我试过在ActivityManifest.xml里面注册,也试过在程序里面注册...但是都有问题.所以很奇怪...我的工具是直接下eslipse集成的工具!