运行单击按钮
“The Application Comment(Process com.one) has stoped unexpectedly.Please try again.第一个Activity代码如下
public class Activity01 extends Activity {
/** Called when the activity is first created. */
private EditText numberOne;
private EditText numberTwo;
private Button button;
private TextView symbol;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
numberOne = (EditText) findViewById(R.id.numberOne);
numberTwo = (EditText) findViewById(R.id.numberTwo);
button = (Button) findViewById(R.id.conculate);
symbol=(TextView) findViewById(R.id.symbol);
symbol.setText("X");
button.setText("计算");
button.setOnClickListener(new MyOnClickListener());
}
class MyOnClickListener implements OnClickListener{
@Override
public void onClick(View v) {
String one = numberOne.getText().toString();
String two =numberTwo.getTag().toString();
Intent intent = new Intent(Activity03.this, com.one.Result.class);
intent.putExtra("one", one);
intent.putExtra("two", two);
startService(intent);
}
}
}第二个Activity代码如下:
public class Result extends Activity {
private TextView re;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
re = (TextView) findViewById(R.id.answer);
Intent intent = getIntent();
String one = intent.getStringExtra("one");
String two =intent.getStringExtra("two");
int number1 = Integer.parseInt(one);
int number2 = Integer.parseInt(two);
int r = number1 * number2;
re.setText(r +"");
}
}
result.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/answer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>已经在AndroidManifest.xml注册第二个Activity,代码如下
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mars"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" /> <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=".Result" />
</application>
</manifest>请问问题出在哪儿?
“The Application Comment(Process com.one) has stoped unexpectedly.Please try again.第一个Activity代码如下
public class Activity01 extends Activity {
/** Called when the activity is first created. */
private EditText numberOne;
private EditText numberTwo;
private Button button;
private TextView symbol;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
numberOne = (EditText) findViewById(R.id.numberOne);
numberTwo = (EditText) findViewById(R.id.numberTwo);
button = (Button) findViewById(R.id.conculate);
symbol=(TextView) findViewById(R.id.symbol);
symbol.setText("X");
button.setText("计算");
button.setOnClickListener(new MyOnClickListener());
}
class MyOnClickListener implements OnClickListener{
@Override
public void onClick(View v) {
String one = numberOne.getText().toString();
String two =numberTwo.getTag().toString();
Intent intent = new Intent(Activity03.this, com.one.Result.class);
intent.putExtra("one", one);
intent.putExtra("two", two);
startService(intent);
}
}
}第二个Activity代码如下:
public class Result extends Activity {
private TextView re;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
re = (TextView) findViewById(R.id.answer);
Intent intent = getIntent();
String one = intent.getStringExtra("one");
String two =intent.getStringExtra("two");
int number1 = Integer.parseInt(one);
int number2 = Integer.parseInt(two);
int r = number1 * number2;
re.setText(r +"");
}
}
result.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/answer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>已经在AndroidManifest.xml注册第二个Activity,代码如下
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mars"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" /> <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=".Result" />
</application>
</manifest>请问问题出在哪儿?
声明代码是</activity>
<activity android:name="Result" ></activity>
</application>
文件有问题,和你的Intent里的完全路径不一致。com.one.Result和com.mars.Result不一样。
换成
Intent intent = new Intent(Activity03.this, Result.class);
试试~
package="com.mars"
<activity android:name=".Result" />com.one.Result 和com.mars.Result有个地方出错啦 楼主检查检查
而你manifest的package="com.mars",很明显肯定找不到你的类!要统一