我是个android开发初级者,遇到一个问题:在一个activity跳转到另一个activity出现“xxx has stopped unexpectedly”。
我的代码如下:
Calculate.java
package faithll.activity;import faithll.activity.result;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;public class Calculate extends Activity {
/** Called when the activity is first created. */
private TextView symbol=null;
private EditText factorOne=null;
private EditText factorTwo = null;
private TextView result=null;
private Button myButton=null;
private Button myButton2=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
symbol = (TextView)findViewById(R.id.symbol);
symbol.setText("乘以");
factorOne=(EditText)findViewById(R.id.valueOne);
factorTwo = (EditText)findViewById(R.id.valueTwo); myButton = (Button)findViewById(R.id.myButton);
myButton2 = (Button)findViewById(R.id.myButton2); myButton.setText("result");
myButton2.setText("result2");
myButton.setOnClickListener(new calculateListener());
myButton2.setOnClickListener(new intentCalListener());
}
class intentCalListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent();
myIntent.putExtra("oneTest",factorOne.getText().toString());
myIntent.putExtra("twoTest",factorTwo.getText().toString());
//intent.putExtra("one", "123");
myIntent.setClass(Calculate.this, result.class);
Calculate.this.startActivity(myIntent);
}
}
class calculateListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("start1--Cal");
//Intent intent1= new Intent();
String cal_One=factorOne.getText().toString();
String cal_Two = factorTwo.getText().toString();
int calIntOne = Integer.parseInt(cal_One);
int calIntTwo = Integer.parseInt(cal_Two);
int resultInt = calIntOne*calIntTwo;
result=(TextView)findViewById(R.id.result);
result.setText(resultInt+"");
}
}
}
result.java
package faithll.activity;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
class result extends Activity{
private TextView cal_result=null; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
Intent intent = getIntent();
String result_One = intent.getStringExtra("oneTest");
String result_Two = intent.getStringExtra("twoTest");
int resultIntOne = Integer.parseInt(result_One);
int resultIntTwo = Integer.parseInt(result_Two);
int result_Int = resultIntOne*resultIntTwo;
cal_result = (TextView)findViewById(R.id.resultInt);
cal_result.setText(result_Int+"");
}
}
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mars.activity"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity01"
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/app_name"/>
</application>
<uses-sdk android:minSdkVersion="4" /></manifest>
我的代码如下:
Calculate.java
package faithll.activity;import faithll.activity.result;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;public class Calculate extends Activity {
/** Called when the activity is first created. */
private TextView symbol=null;
private EditText factorOne=null;
private EditText factorTwo = null;
private TextView result=null;
private Button myButton=null;
private Button myButton2=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
symbol = (TextView)findViewById(R.id.symbol);
symbol.setText("乘以");
factorOne=(EditText)findViewById(R.id.valueOne);
factorTwo = (EditText)findViewById(R.id.valueTwo); myButton = (Button)findViewById(R.id.myButton);
myButton2 = (Button)findViewById(R.id.myButton2); myButton.setText("result");
myButton2.setText("result2");
myButton.setOnClickListener(new calculateListener());
myButton2.setOnClickListener(new intentCalListener());
}
class intentCalListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent();
myIntent.putExtra("oneTest",factorOne.getText().toString());
myIntent.putExtra("twoTest",factorTwo.getText().toString());
//intent.putExtra("one", "123");
myIntent.setClass(Calculate.this, result.class);
Calculate.this.startActivity(myIntent);
}
}
class calculateListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("start1--Cal");
//Intent intent1= new Intent();
String cal_One=factorOne.getText().toString();
String cal_Two = factorTwo.getText().toString();
int calIntOne = Integer.parseInt(cal_One);
int calIntTwo = Integer.parseInt(cal_Two);
int resultInt = calIntOne*calIntTwo;
result=(TextView)findViewById(R.id.result);
result.setText(resultInt+"");
}
}
}
result.java
package faithll.activity;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
class result extends Activity{
private TextView cal_result=null; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
Intent intent = getIntent();
String result_One = intent.getStringExtra("oneTest");
String result_Two = intent.getStringExtra("twoTest");
int resultIntOne = Integer.parseInt(result_One);
int resultIntTwo = Integer.parseInt(result_Two);
int result_Int = resultIntOne*resultIntTwo;
cal_result = (TextView)findViewById(R.id.resultInt);
cal_result.setText(result_Int+"");
}
}
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mars.activity"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity01"
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/app_name"/>
</application>
<uses-sdk android:minSdkVersion="4" /></manifest>
解决方案 »
- Android应用开发揭秘—入门答疑
- Android人脸检测FaceDetector 的疑问
- android程序中怎么由输入的地址得到该地址的经纬度?
- 关于statusBAR添加back按钮实现问题
- 如何提取apk中视频的引用地址?
- soap方式获取响应内容的提取问题!!!!
- 呼啸Android视频教程【不断更新】
- 关于权限被禁止后的提示问题
- 麻烦有实际工作经验的Android开发者帮我回答以下几个问题
- android app运行时改变权限配置,application的context为空
- 用Service怎么已进入程序就在后台播放音乐呢?
- 在传数据之前怎么判断EditText的内容是汉字还是其他的呢?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mars.activity" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity01" 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" android:label="@string/app_name" />
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
出现了下面两处错误:<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mars.activity"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Calculate"
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"
android:label = "@string/app_name"/> </application>
<uses-sdk android:minSdkVersion="4" /></manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="faithll.activity"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Calculate"
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"
android:label = "@string/app_name"/> </application>
<uses-sdk android:minSdkVersion="4" /></manifest>
不好意思
使用Intent filter
我的也报错 悲剧啊<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="feel.Mp3player" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Mp3player" 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=".Testdownload">
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest> 但是又有注册ACTIVITY 郁闷啊 高手求解...
我还是同意楼上有几位的看法的
在后面一个activity中加intent-filter。应该就没问题了
你的代码从逻辑上看 是没有问题的你页面无法跳转有可能是因为 xml布局文件的问题另外这里
public class result extends Activity{
private TextView cal_result=null; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
Intent intent = getIntent();
String result_One = intent.getStringExtra("oneTest");
String result_Two = intent.getStringExtra("twoTest");
int resultIntOne = Integer.parseInt(result_One);
int resultIntTwo = Integer.parseInt(result_Two);
int result_Int = resultIntOne*resultIntTwo;
cal_result = (TextView)findViewById(R.id.resultInt);
cal_result.setText(result_Int+"");
}
}
这里int resultIntOne = Integer.parseInt(result_One);
int resultIntTwo = Integer.parseInt(result_Two);
如果前面页面 传过来的是 “” ,将会抛出 NumberFormatException 异常,导致异常退出