コードのどこでエラーが発生するかを知りたいです。この活動は、単位換算のようなものでなければなりません。単位を選択するための 2 つのスピナー、値を挿入するための edittest、および結果を表示するための textview があります。実際に、値を挿入してボタンを押して変換すると、クラッシュします。手伝って頂けますか?ありがとう、私の英語でごめんなさい
public class lunghezze extends Activity implements OnClickListener {
EditText et1;
TextView tv1;
Spinner spinner1,spinner2;
Button btnAdd;
String oper = "";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.converter);
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this,R.array.lunghezza, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,R.array.lunghezza, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter2);
// find the elements
et1 = (EditText) findViewById(R.id.editText1);
btnAdd = (Button) findViewById(R.id.button1);
tv1 = (TextView) findViewById(R.id.textView4);
// set a listener
btnAdd.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
double num1 = 0;
double resdelta = 0;
double res = 0;
double resx2 = 0;
if (TextUtils.isEmpty(et1.getText().toString())) {
return;
}
String a = et1.getText().toString().trim();
num1 = a.isEmpty()? Double.NaN:Double.parseDouble(a);
switch (v.getId()) {
case R.id.button1:
String s1 = spinner1.getSelectedItem().toString();
String s2 = spinner2.getSelectedItem().toString();
if (s1 + s2 == "IardeIarde"){
tv1.setText("" + num1);
} else {
}
break;
default:
break;
ここにlogcatがあります
11-12 17:56:04.063: E/AndroidRuntime(1415): FATAL EXCEPTION: main
11-12 17:56:04.063: E/AndroidRuntime(1415): java.lang.NullPointerException
11-12 17:56:04.063: E/AndroidRuntime(1415): at com.example.easyphysics.lunghezze.onClick(lunghezze.java:91)
11-12 17:56:04.063: E/AndroidRuntime(1415): at android.view.View.performClick(View.java:4084)
11-12 17:56:04.063: E/AndroidRuntime(1415): at android.view.View$PerformClick.run(View.java:16966)
11-12 17:56:04.063: E/AndroidRuntime(1415): at android.os.Handler.handleCallback(Handler.java:615)
11-12 17:56:04.063: E/AndroidRuntime(1415): at android.os.Handler.dispatchMessage(Handler.java:92)
11-12 17:56:04.063: E/AndroidRuntime(1415): at android.os.Looper.loop(Looper.java:137)
11-12 17:56:04.063: E/AndroidRuntime(1415): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-12 17:56:04.063: E/AndroidRuntime(1415): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 17:56:04.063: E/AndroidRuntime(1415): at java.lang.reflect.Method.invoke(Method.java:511)
11-12 17:56:04.063: E/AndroidRuntime(1415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-12 17:56:04.063: E/AndroidRuntime(1415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-12 17:56:04.063: E/AndroidRuntime(1415): at dalvik.system.NativeStart.main(Native Method)