//manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="eric.activity03"
    android:versionCode="1"
    android:versionName="1.0" >    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="4" />    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="eric.activity03.Activity03"
            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="eric.activity03.ResultActivity">
            
        </activity>
    </application></manifest>
//Activity03.java
package eric.activity03;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;
import android.widget.EditText;
import android.widget.TextView;public class Activity03 extends Activity {
    private EditText factorOne;
    private EditText factorTwo;
    private TextView symbol;
    private Button calculate;
    
    
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
factorOne=(EditText)findViewById(R.id.factorOne);
factorTwo=(EditText)findViewById(R.id.factorTwo);
symbol=(TextView)findViewById(R.id.symbol);
calculate=(Button)findViewById(R.id.calculate);
symbol.setText(R.string.symbol);
calculate.setText(R.string.calculate);
calculate.setOnClickListener(new calculateListener());
}
    class calculateListener implements OnClickListener{
     String factorOnestr=factorOne.getText().toString();
     String factorTwostr=factorTwo.getText().toString();
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.putExtra("One",factorOnestr);
intent.putExtra("Two",factorTwostr);
intent.setClass(Activity03.this,ResultActivity.class);
Activity03.this.startActivity(intent);
}
    }
}
//ResultActivity.java
package eric.activity03;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;public class ResultActivity extends Activity {
    private TextView resultView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
resultView=(TextView)findViewById(R.id.result);
Intent intent=getIntent();
String factorOnestr =intent.getStringExtra("One");
String factorTwostr=intent.getStringExtra("Two");
int factorOneInt=Integer.parseInt(factorOnestr);
int factorTwoInt=Integer.parseInt(factorTwostr);
int result=factorOneInt*factorTwoInt;
resultView.setText(result+"");
}
}程序点击button后老是出现The application activity03 has stopped unexpected,please try it again  forced close

解决方案 »

  1.   

        String factorOnestr=factorOne.getText().toString();
         String factorTwostr=factorTwo.getText().toString();
    这两行放到onClick方法里面试试。
    参考一下这里http://onewayonelife.iteye.com/blog/833463
      

  2.   

    不出意外是
    int factorOneInt=Integer.parseInt(factorOnestr);
    int factorTwoInt=Integer.parseInt(factorTwostr);
    int result=factorOneInt*factorTwoInt;
    这几行出的问题,你取到的factorOnestr 和factorTwostr 为null,
    楼主打印一下就可以了,而且你截取的日志不是主要的日志,要看cause by 后面的
      

  3.   

    对呀 你双击一下caused by 后面的信息,就会跳转到出问题的那行代码 在具体看一下是什么原因造成的