急急急!!! 本人刚刚开始学习基于android的开发 写了一个计算器的程序,就是计算两个数的积,程序执行的过程出差,点击计算的时候不能跳转到另一个Activity上,并出现提示“The application Activity03(process Activity。masr)has stopped unexpectedly.Please try again” 重新启动了好几遍还是这样,不知道那位大侠有时间指点一下,谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 “The application Activity03(process Activity。masr)has stopped unexpectedly.Please try again”这个不是出错信息。只要程序出错,都报这个错!你应该把你的logcat日志贴出来!或程序代码。这样根本就不知道你的程序到底哪儿错了! //第一个Activitypackage Activity.masr;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;//1.在Activity03中声明四个控件//2.要为其中的两个控件设置显示的值//3.创建一个监听器类,监听按钮按下的动作//4.将监听器类的对象,绑定在按钮对象上public class Activity03 extends Activity { /** Called when the activity is first created. */ private EditText factorOne; private EditText factorTwo; private TextView symbol; private Button calculate; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //根据控件的ID来取得代表控件的对象 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和calculate设置显示的值 /* symbol.setText("乘以"); calculate.setText("计算");*/ symbol.setText(R.string.symbol); calculate.setText(R.string.calculate); //将监听器绑定到按钮对象上面 calculate.setOnClickListener(new calculateListener()); } class calculateListener implements OnClickListener{ public void onClick(View v) { // 取得两个EditText控件的值 String factorOneStr = factorOne.getText().toString(); String factorTwoStr = factorTwo.getText().toString(); //将这两个值存放到Intended对象中 Intent intent = new Intent(); intent.putExtra("one",factorOneStr); intent.putExtra("two",factorTwoStr); intent.setClass(Activity03.this,ResultActivity.class); //使用这个Intend对象来启动ResultActivity Activity03.this.startActivity(intent); } }}//第二个Activitypackage Activity.masr;import android.app.Activity;import android.content.Intent;import android.os.Bundle;// 1.首先应该接受从Activity03当中传递的值// 2.计算两个值得积// 3.将计算的结果显示在Activity上import android.widget.TextView;public class ResultActivity extends Activity { /** Called when the activity is first created. */ private TextView resultView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.result); resultView = (TextView)findViewById(R.id.result); //得到intent对象当中的值 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+""); }} 哦 我把两个Activity文件给贴出来了,这样能看出来吗?谢谢! 看不出来的 说的是DDMS中Log Cat部分的Error信息 你得把那个贴出来不过 如果你代码没错的话 那你查看一下第二个Acitivity有没有添加进AndroidManifest.xml格式如下的那种<activity android:name=".ClassName"></activity> <?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Activity.masr" 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=".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=".ResultActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>*/ </application></manifest>谢谢啊!我是NewComer!!! 第二个Activity的配置不需要<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>这部分了,要不然会出现一启动让你选择进入哪个Activity的问题的 /* 忘记了这一部分 <activity android:name=".ResultActivity" 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=".ResultActivity" android:label="@string/app_name"> </activity>*/这样就可以了。 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>表示程序一开始时导入的Activity Android 程序内部的一个线程怎样与两个Activity界面通信!最好给出例子 Irrlicht Android版的一个加载pk3地图包的例子出现花屏现象 如何去掉:退出程序后默认回到登录界面,但“usernameTxt”框依然显示刚登录过的用户名 26岁学Android晚不晚 调用系统浏览器的问题. 跪求大神解答~ 求助 网页显示不正常 Android平台的源代码怎么这么混乱,各处代码都不一致啊? Android老油条请进 谁能教我怎么配置android 环境 VC++转移动开发 求推荐好的方案 用什么IDE好 在Dialog中的TextView控件中的值怎么传递 如何取消监听
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;
//1.在Activity03中声明四个控件
//2.要为其中的两个控件设置显示的值
//3.创建一个监听器类,监听按钮按下的动作
//4.将监听器类的对象,绑定在按钮对象上
public class Activity03 extends Activity {
/** Called when the activity is first created. */
private EditText factorOne;
private EditText factorTwo;
private TextView symbol;
private Button calculate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//根据控件的ID来取得代表控件的对象
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和calculate设置显示的值
/* symbol.setText("乘以");
calculate.setText("计算");*/
symbol.setText(R.string.symbol);
calculate.setText(R.string.calculate);
//将监听器绑定到按钮对象上面
calculate.setOnClickListener(new calculateListener());
}
class calculateListener implements OnClickListener{ public void onClick(View v) {
// 取得两个EditText控件的值
String factorOneStr = factorOne.getText().toString();
String factorTwoStr = factorTwo.getText().toString();
//将这两个值存放到Intended对象中
Intent intent = new Intent();
intent.putExtra("one",factorOneStr);
intent.putExtra("two",factorTwoStr);
intent.setClass(Activity03.this,ResultActivity.class);
//使用这个Intend对象来启动ResultActivity
Activity03.this.startActivity(intent); }
}}
//第二个Activity
package Activity.masr;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
// 1.首先应该接受从Activity03当中传递的值
// 2.计算两个值得积
// 3.将计算的结果显示在Activity上
import android.widget.TextView;public class ResultActivity extends Activity {
/** Called when the activity is first created. */
private TextView resultView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
resultView = (TextView)findViewById(R.id.result);
//得到intent对象当中的值
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+"");
}
}
说的是DDMS中Log Cat部分的Error信息 你得把那个贴出来
不过 如果你代码没错的话 那你查看一下第二个Acitivity有没有添加进AndroidManifest.xml
格式如下的那种
<activity android:name=".ClassName"></activity>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Activity.masr"
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=".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=".ResultActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>*/ </application>
</manifest>谢谢啊!我是NewComer!!!
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
这部分了,要不然会出现一启动让你选择进入哪个Activity的问题的
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=".ResultActivity"
android:label="@string/app_name"> </activity>*/这样就可以了。
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>表示程序一开始时导入的Activity