我是 android/java 编程的初学者。我下面的程序崩溃了
currkm = (Double.parseDouble(currentkm.getText().toString()));
. 我试图解决这个问题,但不能。我相信它是android中的基本编码错误。提供解决此问题的建议。
package com.example.my2app;
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
double vehiclemileage;
TextView mileage;
SharedPreferences somedata;
SharedPreferences.Editor editor;
TextView previouskm;
EditText currentkm;
EditText petrollitrs;
double currkm;
double prevkm;
double petrollt;
Button resultbtn;
String previouskmstr;
String prevkmstring;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mileagecalc);
somedata= this.getBaseContext().getSharedPreferences("sakthivel",0);
editor = somedata.edit();
previouskm = (TextView)findViewById(R.id.previouskm);
currentkm = (EditText)findViewById(R.id.currentkm);
petrollitrs = (EditText)findViewById(R.id.petroLtr);
mileage = (TextView)findViewById(R.id.mileage);
previouskmstr = somedata.getString("previousmileage", null);
previouskm.setText(previouskmstr);
resultbtn = (Button)findViewById(R.id.button1);
resultbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
try{
currkm = (Double.parseDouble(currentkm.getText().toString()));
prevkm = (Double.parseDouble(previouskm.getText().toString()));
petrollt = (Double.parseDouble(petrollitrs.getText().toString()));
vehiclemileage = (currkm-prevkm)/petrollt;
prevkmstring = currentkm.getText().toString();
mileage.setText("your vehicle mileage is " + vehiclemileage);
editor.putString("previousmileage", prevkmstring);
editor.commit();
previouskm.setText(prevkmstring);
}
catch(NumberFormatException e){
e.printStackTrace();
}
}
});
}
}
日志猫:
11-13 12:52:27.671: E/JavaBinder(661): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
11-13 12:52:27.671: E/JavaBinder(661): java.lang.RuntimeException: android.os.DeadObjectException
11-13 12:52:27.671: E/JavaBinder(661): at android.os.Parcel.writeException(Parcel.java:1332)
11-13 12:52:27.671: E/JavaBinder(661): at android.os.Binder.execTransact(Binder.java:391)