setText(“”)android error group = 0x4001b188

时间:2014-08-18 13:02:37

标签: android

当点击一个按钮使编辑文本为空时,我遇到了问题。 DDMS表示未捕获的异常组= 0x4001b188是错误的。 这是y代码

public class Main extends Activity {
    float fm_value_pdty;
    Button calc_fm_pdty, dt_pdty_calc, loader_pdty_calc;
    TextView fm_value_pdty_txt;
    EditText DT_count, Loader_count;
    public EditText DT_Pdty;
    public EditText Loader_Pdty;
    public static float vdtpdty;
    public static float vloaderpdty;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fm_value_pdty=(float) 0;
        calc_fm_pdty = (Button) findViewById(R.id.calcpdty);
        dt_pdty_calc = (Button) findViewById(R.id.calcpdty_dt);
        loader_pdty_calc = (Button) findViewById(R.id.calcpdty_loader);
        fm_value_pdty_txt = (TextView) findViewById(R.id.fm_pdty_value);
        DT_Pdty = (EditText) findViewById(R.id.DTPdty_ET);
        Loader_Pdty = (EditText) findViewById(R.id.Loader_CT_ET);
        vdtpdty=(float) 0.0;
        vloaderpdty=(float) 0.0;


        calc_fm_pdty.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //if (DT_CT.getText().toString() <>""){
                    if ((DT_Pdty.getText().toString()!=null) &&  (Loader_Pdty.getText().toString()!=null))  {
                        fm_value_pdty = ((float) Integer.parseInt(DT_Pdty.getText().toString()))/((float) Integer.parseInt(Loader_Pdty.getText().toString()));
                        fm_value_pdty_txt.setText("Fleet Matching value is " + fm_value_pdty);
                    }
                    else if ((DT_Pdty.getText().toString()==null) ||  (Loader_Pdty.getText().toString()==null)) {
                        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(getApplicationContext());
                        dlgAlert.setMessage("Please input the DT Productivty and Loader Productivty");
                        dlgAlert.setTitle("Data is empty");
                        dlgAlert.setPositiveButton("OK",null);
                        dlgAlert.setCancelable(true);
                        dlgAlert.create().show();
                    }
            }
        });
        dt_pdty_calc.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dt_pdty.vloaderpdty=vloaderpdty;
                DT_Pdty.setText("");
                Loader_Pdty.setText("");
                Intent pdty = new Intent(Main.this, dt_pdty.class);
                startActivity(pdty);
                DT_Pdty.setText(Float.toString(vdtpdty));
                Loader_Pdty.setText(Float.toString(vloaderpdty));
            }
        });
        loader_pdty_calc.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v2) {
                ld_pdty.vdtpdty=vdtpdty;
                DT_Pdty.setText("");
                Loader_Pdty.setText("");
                Intent pdty = new Intent(Main.this, ld_pdty.class);
                startActivity(pdty);
                DT_Pdty.setText(Float.toString(vdtpdty));
                Loader_Pdty.setText(Float.toString(vloaderpdty));
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

当我尝试使用按钮激活活动时,代码很简单,首先清空编辑文本并且活动开始,活动结束后,已清空的编辑文本将填充活动中的计算值。 我想制作一个有两个编辑文本和两个按钮的程序。第一个编辑文本将填充第一个按钮的结果,与其他编辑文本和按钮相同。我得到第一个按钮的结果的问题但是当我从第二个按钮运行第二个活动时我得到一个错误。从logcat开始,这是因为第一次编辑文本的视图。我已经用logcat更新了我的帖子。

08-20 19:52:47.924: D/AndroidRuntime(237): Shutting down VM
08-20 19:52:47.958: W/dalvikvm(237): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-20 19:52:47.958: E/AndroidRuntime(237): Uncaught handler: thread main exiting due to uncaught exception
08-20 19:52:48.028: E/AndroidRuntime(237): java.lang.NullPointerException
08-20 19:52:48.028: E/AndroidRuntime(237):  at com.example.fleetmatcher.Main$2.onClick(Main.java:66)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.View.performClick(View.java:2364)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.View.onTouchEvent(View.java:4179)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.widget.TextView.onTouchEvent(TextView.java:6541)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.View.dispatchTouchEvent(View.java:3709)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-20 19:52:48.028: E/AndroidRuntime(237):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-20 19:52:48.028: E/AndroidRuntime(237):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-20 19:52:48.028: E/AndroidRuntime(237):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.os.Looper.loop(Looper.java:123)
08-20 19:52:48.028: E/AndroidRuntime(237):  at android.app.ActivityThread.main(ActivityThread.java:4363)
08-20 19:52:48.028: E/AndroidRuntime(237):  at java.lang.reflect.Method.invokeNative(Native Method)
08-20 19:52:48.028: E/AndroidRuntime(237):  at java.lang.reflect.Method.invoke(Method.java:521)
08-20 19:52:48.028: E/AndroidRuntime(237):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-20 19:52:48.028: E/AndroidRuntime(237):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-20 19:52:48.028: E/AndroidRuntime(237):  at dalvik.system.NativeStart.main(Native Method)
08-20 19:52:48.201: I/dalvikvm(237): threadid=7: reacting to signal 3
08-20 19:52:48.422: I/dalvikvm(237): Wrote stack trace to '/data/anr/traces.txt'
08-20 19:52:50.620: I/Process(237): Sending signal. PID: 237 SIG: 9

1 个答案:

答案 0 :(得分:0)

需要您的logcat才能知道确切的问题。但是有一些观察:

  1. 执行startActivity(pdty)后,不要尝试更新EditText。
  2. 您无需清除EditText来替换文本,即您不需要edittext.settext("");
  3. 如果您确实要清除Edittext,还有另一种方法:edittext.gettext.clear();
  4. 希望这很有用。