-7
我的Android應用程序仍然給我這個下面的錯誤。當我點擊模擬器中的應用程序圖標時,不幸的是我的應用程序已停止工作。以下應用程序在Android中意外停止?
是logcat的錯誤
01-04 11:20:57.440: E/AndroidRuntime(798): FATAL EXCEPTION: main
01-04 11:20:57.440: E/AndroidRuntime(798): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oj2.currrencyconverter/com.oj2.currrencyconverter.MainConverter}: java.lang.NumberFormatException: Invalid int: ""
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.os.Looper.loop(Looper.java:137)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-04 11:20:57.440: E/AndroidRuntime(798): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 11:20:57.440: E/AndroidRuntime(798): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 11:20:57.440: E/AndroidRuntime(798): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-04 11:20:57.440: E/AndroidRuntime(798): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-04 11:20:57.440: E/AndroidRuntime(798): at dalvik.system.NativeStart.main(Native Method)
01-04 11:20:57.440: E/AndroidRuntime(798): Caused by: java.lang.NumberFormatException: Invalid int: ""
01-04 11:20:57.440: E/AndroidRuntime(798): at java.lang.Integer.invalidInt(Integer.java:138)
01-04 11:20:57.440: E/AndroidRuntime(798): at java.lang.Integer.parseInt(Integer.java:359)
01-04 11:20:57.440: E/AndroidRuntime(798): at java.lang.Integer.parseInt(Integer.java:332)
01-04 11:20:57.440: E/AndroidRuntime(798): at com.oj2.currrencyconverter.MainConverter.onCreate(MainConverter.java:28)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.Activity.performCreate(Activity.java:5104)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-04 11:20:57.440: E/AndroidRuntime(798): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-04 11:20:57.440: E/AndroidRuntime(798): ... 11 more
以下是代碼
package com.oj2.currrencyconverter;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
public class MainConverter extends Activity {
EditText dollars;
EditText rupees;
RadioButton dTOr;
RadioButton rTOd;
Button convert;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set Gui gui_main_converter for class MainConverter
setContentView(R.layout.gui_main_converter);
//Get the value from edittext in dollars
dollars = (EditText)findViewById(R.id.dollaredtxt);
//
String rup = dollars.getText().toString();
int convertrup = Integer.parseInt(rup);
rupees = (EditText)findViewById(R.id.edtrup);
dTOr = (RadioButton) findViewById(R.id.radioDtoR);
dTOr.setChecked(true);
rTOd = (RadioButton) findViewById(R.id.radioRtoD);
convert = (Button) findViewById(R.id.btnConvert);
convert.setOnClickListener(mylistner);
}
private OnClickListener mylistner = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (dTOr.isChecked()) {
ConvertDollarToRup();
}
if (rTOd.isChecked()) {
ConvertRupToDollar();
}
}
};
public void ConvertDollarToRup() {
// TODO Auto-generated method stub
double val = Double.parseDouble(dollars.getText().toString());
rupees.setText(Double.toString(val*56));
}
public void ConvertRupToDollar() {
// TODO Auto-generated method stub
double val = Double.parseDouble(rupees.getText().toString());
dollars.setText(Double.toString(val/56));
}
}
感謝你
發佈您的代碼和logcat的...... – Subburaj
LO(N)g催化劑? http://blog.seanbonner.com/wp-content/uploads/2009/07/1246818021845.jpg – doge
請參閱logcat的是有錯誤的'NumberFormatException'這意味着你的'ConvertDollarToRup()'是有problem.So請檢查。 – Akshay