我是个android开发初级者,遇到一个问题:在一个activity跳转到另一个activity出现“xxx has stopped unexpectedly”。
我的代码如下:
Calculate.java
package faithll.activity;import faithll.activity.result;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;public class Calculate extends Activity {
    /** Called when the activity is first created. */
    private TextView symbol=null;
    private EditText factorOne=null;
    private EditText factorTwo = null;
    private TextView result=null;
    private Button myButton=null;
    private Button myButton2=null;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        symbol = (TextView)findViewById(R.id.symbol);
        symbol.setText("乘以");
        
        factorOne=(EditText)findViewById(R.id.valueOne);
        factorTwo = (EditText)findViewById(R.id.valueTwo);        myButton = (Button)findViewById(R.id.myButton);
        myButton2 = (Button)findViewById(R.id.myButton2);        myButton.setText("result");
        myButton2.setText("result2");
        
       myButton.setOnClickListener(new calculateListener());
       myButton2.setOnClickListener(new intentCalListener());
        
    }
class intentCalListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent();
myIntent.putExtra("oneTest",factorOne.getText().toString());
myIntent.putExtra("twoTest",factorTwo.getText().toString());
//intent.putExtra("one", "123");
myIntent.setClass(Calculate.this, result.class);
Calculate.this.startActivity(myIntent);

}

}
class calculateListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("start1--Cal");
//Intent intent1= new Intent();
String cal_One=factorOne.getText().toString();
String cal_Two = factorTwo.getText().toString();
int calIntOne = Integer.parseInt(cal_One);
int calIntTwo = Integer.parseInt(cal_Two);
int resultInt = calIntOne*calIntTwo;
result=(TextView)findViewById(R.id.result);
result.setText(resultInt+"");
}

}
}
result.java
package faithll.activity;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
class result extends Activity{
private TextView cal_result=null; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.result);

Intent intent = getIntent();
String result_One = intent.getStringExtra("oneTest");
String result_Two = intent.getStringExtra("twoTest");
int resultIntOne = Integer.parseInt(result_One);
int resultIntTwo = Integer.parseInt(result_Two);
int result_Int = resultIntOne*resultIntTwo;
cal_result = (TextView)findViewById(R.id.resultInt);
cal_result.setText(result_Int+"");
}

}
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="mars.activity"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Activity01"
                  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 =".Otheractivity"
        android:label = "@string/app_name"/>
    </application>
    <uses-sdk android:minSdkVersion="4" /></manifest> 

解决方案 »

  1.   

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mars.activity" android:versionCode="1" android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Activity01" 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=".result" android:label="@string/app_name" />
    </application>
    <uses-sdk android:minSdkVersion="4" />
    </manifest>
      

  2.   

    我有点怀疑LZ的代码能运行吗??
    出现了下面两处错误:<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="mars.activity"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".Calculate"
                      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 =".result"
            android:label = "@string/app_name"/>
        </application>
        <uses-sdk android:minSdkVersion="4" /></manifest> 
      

  3.   

    的确能运行,就是点第二个button按钮时跳到另一个activity时出错,但是点击第一个button按钮在同一个activity下面能正确显示结果
      

  4.   

    androidmanifest.xml贴错了,应该是
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="faithll.activity"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".Calculate"
                      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 =".result"
            android:label = "@string/app_name"/>    </application>
        <uses-sdk android:minSdkVersion="4" /></manifest> 
    不好意思
      

  5.   

    把错误日志贴出来看看eclipse菜单:Window-->show view-->other-->android-->LogCat,点击确定,就会在eclipse里面显示出对话框,这样里面就会有日志了
      

  6.   

    出错误用Logcat来DEBUG吧,那样快很多~~~~
      

  7.   

    resultActivity至少需要加一个intent filter的
      

  8.   

    用LogCat看看错误信息吧,虽然不一定定位正确,但也是一条路
      

  9.   

    LZ是不是对Activity的注册错误了啊??!!!
    使用Intent filter
      

  10.   

     have you declared this activity in your AndroidManifest.xml?
    我的也报错  悲剧啊<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="feel.Mp3player" android:versionCode="1" android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Mp3player" 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=".Testdownload">
    </activity>
    </application>
    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    </manifest> 但是又有注册ACTIVITY  郁闷啊  高手求解...
      

  11.   

    不要让看代码  看bug比看代码更能解决问题
      

  12.   

    这种问题 果断看logcat 然后定位到代码去找啊
      

  13.   

    http://hi.baidu.com/babypyx/blog/item/e7ceec449b6cdd1a6b63e5eb.html?timeStamp=1296352654494
    我还是同意楼上有几位的看法的
    在后面一个activity中加intent-filter。应该就没问题了
      

  14.   

    LZ
    你的代码从逻辑上看 是没有问题的你页面无法跳转有可能是因为 xml布局文件的问题另外这里
    public class result extends Activity{
        private TextView cal_result=null;    @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.result);
            
            Intent intent = getIntent();
            String result_One = intent.getStringExtra("oneTest");
            String result_Two = intent.getStringExtra("twoTest");
            int resultIntOne = Integer.parseInt(result_One);
            int resultIntTwo = Integer.parseInt(result_Two);
            int result_Int = resultIntOne*resultIntTwo;
            cal_result = (TextView)findViewById(R.id.resultInt);
            cal_result.setText(result_Int+"");
        }
        
    }
    这里int resultIntOne = Integer.parseInt(result_One);
    int resultIntTwo = Integer.parseInt(result_Two);
    如果前面页面 传过来的是 “” ,将会抛出 NumberFormatException 异常,导致异常退出