我的android没错,怎么就是运行不出结果呢? intent.putExtra("One", FactorOneStr);intent.putExtra("Two", FctorTwoStr); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在AndroidManifest.xml中加了上面的Activity了吗?<activity android:name="AutoSelect"></activity><activity android:name="Activity03"></activity> intent.putExtra("One", FactorOneStr);intent.putExtra("Two", FctorTwoStr);这里改好了。在AndroidManifest.xml中我也添加了。代码如下:<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.activity" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="3"></uses-sdk> <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=".OtherActivity" android:label="@string/Result" /> </application></manifest> 但是运行后还是出现上面所说的问题啊!还没解决! 12-26 07:23:32.152: ERROR/AndroidRuntime(343): Caused by: java.lang.NumberFormatException: unable to parse 'FactorOneStr' as integer 把Activity03内代码改下 EditText et1 = (EditText)findViewById(R.id.myFactorOne); EditText et2 = (EditText)findViewById(R.id.myFactorTwo); intent.putExtra("One", Integer.parseInt(et1.getText().toString().trim())); intent.putExtra("Two", Integer.parseInt(et2.getText().toString().trim())); intent.setClass(Activity03.this, OtherActivity.class); Activity03.this.startActivity(intent);OtherActivity改成这样 ResultView = (TextView) findViewById(R.id.Result); Intent intent = getIntent(); int FactorOneStr =intent.getIntExtra("One", 0); int FactorTwoStr =intent.getIntExtra("Two", 0); int result = FactorOneStr * FactorTwoStr; ResultView.setText(result + " "); 看了一下午,原来是我这段代码些错了,应把下列代码改为: String FactorOneStr=getText(R.id.myFactorOne).toString(); String FactorTwoStr=getText(R.id.myFactorTwo).toString(); intent.putExtra("One", "FactorOneStr"); intent.putExtra("Two", "FctorTwoStr");改为:String FactorOneStr=myFactorOne.getText().toString(); String FactorTwoStr=myFactorTwo.getText().toString(); intent.putExtra("One", FactorOneStr); intent.putExtra("Two", FctorTwoStr);不过还是应该谢谢大家! 一个简单的时钟计数器 构建一个Android阅读项目 如何看一个 android 应用的服务是什么? 关于 里程碑刷机小问题 Android2.2 触摸键点亮? Android开发新手求教 Android 模拟器 No Service的问题 viewpagerindicator指示器 小米2s数据库查询短信问题 Android studio error!求解~~~~ 创建activity失败,会是怎么回事
<activity android:name="Activity03"></activity>
intent.putExtra("Two", FctorTwoStr);这里改好了。在AndroidManifest.xml中我也添加了。代码如下:<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.activity"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3"></uses-sdk>
<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=".OtherActivity" android:label="@string/Result" /> </application>
</manifest>
但是运行后还是出现上面所说的问题啊!还没解决!
EditText et1 = (EditText)findViewById(R.id.myFactorOne);
EditText et2 = (EditText)findViewById(R.id.myFactorTwo);
intent.putExtra("One", Integer.parseInt(et1.getText().toString().trim()));
intent.putExtra("Two", Integer.parseInt(et2.getText().toString().trim()));
intent.setClass(Activity03.this, OtherActivity.class);
Activity03.this.startActivity(intent);OtherActivity改成这样
ResultView = (TextView) findViewById(R.id.Result);
Intent intent = getIntent();
int FactorOneStr =intent.getIntExtra("One", 0);
int FactorTwoStr =intent.getIntExtra("Two", 0);
int result = FactorOneStr * FactorTwoStr;
ResultView.setText(result + " ");
String FactorOneStr=getText(R.id.myFactorOne).toString();
String FactorTwoStr=getText(R.id.myFactorTwo).toString();
intent.putExtra("One", "FactorOneStr");
intent.putExtra("Two", "FctorTwoStr");改为:
String FactorOneStr=myFactorOne.getText().toString();
String FactorTwoStr=myFactorTwo.getText().toString();
intent.putExtra("One", FactorOneStr);
intent.putExtra("Two", FctorTwoStr);
不过还是应该谢谢大家!