用android编写的两个activity事件之间的转换问题,用到按钮响应事件,用接口  implements OnClickListener,调试没有错误,在模拟器下面运行的时候点击按钮出现com.activity02 stoped 问题
 class myButtonListener implements OnClickListener{
   public void onClick(View v){
   Intent intent=new Intent();
   intent.putExtra("testIntent", "123");
   intent.setClass(activity02.this,otherActivity.class);
   activity02.this.startActivity(intent);
   }
   
   }
不知道哪里出现了问题

解决方案 »

  1.   

    干嘛要这样写呢!你直接去的Button id后,注册单击事件了!比如:Button myButton=(Button)findViewById(R.id.button);
    myButton.setOnClickListener(new OnClickListener(){
        Intent intent=new Intent();
        intent.setClass(this,otherActivity.class);
        startActivity(intent);
    );
      

  2.   

    看看为button添加点击事件是否正确!
    btn.setOnClickListener(new myButtonListener());如果正确的话!
    那肯定是启动的另一个Activity里面出了问题!otherActivity? AndroidMainfest.xml里面注册没有?!otherActivity里的onCreate()函数里数据接收是否正确!Intent intent=getIntent();
    String str=intent.getExtra("testIntent");
    ....楼主看看吧!
      

  3.   


     class myButtonListener implements OnClickListener{
     public void onClick(View v){
     if (v.equals(button)){//btn是你的按钮对象
       Intent intent=new Intent();
       intent.putExtra("testIntent", "123");
       intent.setClass(activity02.this,otherActivity.class);
       activity02.this.startActivity(intent);
     }
       } 
      }
      

  4.   


    在AndroidManifest.xml有没注册被打开的Activity,没注册会就打开会异常
    <activity android:name="otherActivity"></activity>
      

  5.   

    AndroidManifest.xml文件
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.activity02"
          android:versionCode="1"
          android:versionName="1.0">
        <uses-sdk android:minSdkVersion="8" />    <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".activity02"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name="com.otherActivity" android:label="@string/other">
            </activity>
        </application>
    </manifest>
    Activity02文件
    package com.activity02;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 activity02 extends Activity {
    private  Button myButton=null;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            myButton=(Button)findViewById(R.id.myButton);
            myButton.setOnClickListener(new myButtonListener());
        }
       class myButtonListener implements OnClickListener{
       public void onClick(View v){
       if(v.equals(myButton)){
       Intent intent=new Intent();
       intent.putExtra("testIntent", "123");
       intent.setClass(activity02.this,otherActivity.class);
       activity02.this.startActivity(intent);
       /*Uri uri=Uri.parse("Smsto://0800000123");
       Intent intent=new Intent(Intent.ACTION_SENDTO,uri);
       intent.putExtra("sms_body", "The SMS text");
       startActivity(intent);*/
       }
       }
       
       }
    }
    otherActivity文件
    package com.activity02;import android.app.Activity;
    import android.content.Intent;
    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.layout.other);
    Intent intent=getIntent();
    String value=intent.getStringExtra("testIntent");
    myTextView=(TextView)findViewById(R.id.myTextView);
    myTextView.setText(value);
    }
    }出现的异常
    点击myButton之后没有响应事件
      

  6.   

    异常:The application activity02(process com.activity02)has stopped unexpectedly.Please try again
      

  7.   

    先不传值,看看直接转可不可以,如果可以的话就是intent传值问题