将editable转换为int异常

时间:2014-02-27 20:35:45

标签: java android exception

我是Android编程的初学者。

我想在onClickListener中为button运行此代码,但我收到以下异常:

02-27 23:55:01.496: E/AndroidRuntime(1547): FATAL EXCEPTION: main
02-27 23:55:01.496: E/AndroidRuntime(1547): java.lang.NullPointerException
02-27 23:55:01.496: E/AndroidRuntime(1547):     at 
com.example.trsa.RAP1$4.onClick(RAP1.java:152)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.View.performClick(View.java:2485)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.View.onKeyUp(View.java:4257)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.widget.TextView.onKeyUp(TextView.java:4566)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.KeyEvent.dispatch(KeyEvent.java:1280)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.View.dispatchKeyEvent(View.java:3855)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.widget.ScrollView.dispatchKeyEvent(ScrollView.java:328)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.os.Looper.loop(Looper.java:123)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at android.app.ActivityThread.main(ActivityThread.java:3683)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at java.lang.reflect.Method.invokeNative(Native Method)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at java.lang.reflect.Method.invoke(Method.java:507)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-27 23:55:01.496: E/AndroidRuntime(1547):     at dalvik.system.NativeStart.main(Native Method)
02-27 23:55:09.946: I/Process(1547): Sending signal. PID: 1547 SIG: 9

button的代码是:

Button diag = (Button) findViewById(R.id.buttondiag);
diag.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO fuzzy calculations around inputs                    

    String  strrestingpress = enteredrestpress.getText().toString();
    int numrestingpress= Integer.parseInt(strrestingpress);

    String  strcholeserum = choleserum.getText().toString();
    int numcholeserum= Integer.parseInt(strcholeserum);

    String  strmaxrate = maxrate.getText().toString();
    int nummaxrate = Integer.parseInt(strmaxrate);

    String  strrestrate = restrate.getText().toString();
    int numrestrate= Integer.parseInt(strrestrate);                     

    }
});

请帮助我并指导我学习一种有效的Visual Studio调试方法。

0 个答案:

没有答案