//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
<?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
解决方案 »
- android 怎样播放 rtmp 视频流
- GPS HAL 换掉 libhardware_legacy.so 之后开发板总是重启
- 请问LinearLayout如何动态设置宽度
- 如何实现自动登录问题
- 为何设置padding数值之后,背景色还是会填充了整个屏幕?
- 用SurfaceView画大尺寸图片也会产生闪烁裂痕?
- No activity specified! Getting the launcher activity.想在手机上运行时出现这个提示?
- Android File.length() 获取相册图片文件大小出错
- 奇怪的界面改动问题
- 【求助】fragment内添加单击事件后没有跳转到目标Activity
- android4.0以上怎么代码设置有线网的静态ip地址
- android 闹钟
String factorTwostr=factorTwo.getText().toString();
这两行放到onClick方法里面试试。
参考一下这里http://onewayonelife.iteye.com/blog/833463
int factorOneInt=Integer.parseInt(factorOnestr);
int factorTwoInt=Integer.parseInt(factorTwostr);
int result=factorOneInt*factorTwoInt;
这几行出的问题,你取到的factorOnestr 和factorTwostr 为null,
楼主打印一下就可以了,而且你截取的日志不是主要的日志,要看cause by 后面的