私は 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)