4

每当我在模拟器中运行我的应用程序时,Logcat 都会说 - 应用程序可能在其主线程上做太多工作,并且错误消息说 - StringtoReal.invalidReal(string.boolean)line:63 在这里,我正在尝试添加 3 个文本视图的值并在另一个文本视图中使用复选框上的勾号显示它们的总数

10-12 17:23:21.074: W/ActivityThread(700): 
Application com.suvendu.tutorial.cb is waiting for the debugger on port 8100...
10-12 17:23:21.134: I/System.out(700): Sending WAIT chunk
10-12 17:23:21.143: I/dalvikvm(700): Debugger is active
10-12 17:23:21.334: I/System.out(700): Debugger has connected
10-12 17:23:21.334: I/System.out(700): waiting for debugger to settle...
10-12 17:23:21.545: I/System.out(700): waiting for debugger to settle...
10-12 17:23:21.744: I/System.out(700): waiting for debugger to settle...
10-12 17:23:21.943: I/System.out(700): waiting for debugger to settle...
10-12 17:23:22.155: I/System.out(700): waiting for debugger to settle...
10-12 17:23:22.353: I/System.out(700): waiting for debugger to settle...
10-12 17:23:22.554: I/System.out(700): waiting for debugger to settle...
10-12 17:23:22.754: I/System.out(700): waiting for debugger to settle...
10-12 17:23:22.954: I/System.out(700): waiting for debugger to settle...
10-12 17:23:23.164: I/System.out(700): debugger has settled (1368)
10-12 17:23:25.243: I/Choreographer(700): Skipped 46 frames!  
The application may be  doing too much work on its main thread.
10-12 17:23:25.533: D/gralloc_goldfish(700): Emulator without GPU emulation detected.

活动代码:-

OnClickListener checkBoxListener;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    text_regular_code=(TextView)findViewById(R.id.text_regular);
    text_small_code=(TextView)findViewById(R.id.text_small);
    text_large_code=(TextView)findViewById(R.id.text_large);

    text_check_regular_code=(TextView)findViewById(R.id.text_check_regular);
    text_check_small_code=(TextView)findViewById(R.id.text_check_small);
    text_check_large_code=(TextView)findViewById(R.id.text_check_large);

    text_price_regular_code=(TextView)findViewById(R.id.text_price_regular);
    text_price_small_code=(TextView)findViewById(R.id.text_price_small);
    text_price_large_code=(TextView)findViewById(R.id.text_price_large);



    edit_qty_regular_code=(EditText)findViewById(R.id.edit_qty_regular);
    edit_qty_small_code=(EditText)findViewById(R.id.edit_qty_small);
    edit_qty_large_code=(EditText)findViewById(R.id.edit_qty_large);



    chk_regular_code=(CheckBox)findViewById(R.id.chk_regular);
    chk_small_code=(CheckBox)findViewById(R.id.chk_small);
    chk_large_code=(CheckBox)findViewById(R.id.chk_large);



    checkBoxListener =new OnClickListener() {

        public void onClick(View v) {

            if(chk_regular_code.isChecked())
            {
                text_price_regular_code.setText
                (text_regular_code.getText().toString());
                text_check_regular_code.setText
                (chk_regular_code.getText().toString());

            }
            else {
                text_price_regular_code.setText("");
                text_check_regular_code.setText("");
                edit_qty_regular_code.setText("");
            }


            if(chk_small_code.isChecked())
            {
                text_price_small_code.setText
                (text_small_code.getText().toString());
                text_check_small_code.setText
                (chk_small_code.getText().toString());

            }
            else {
                text_price_small_code.setText("");
                text_check_small_code.setText("");
                edit_qty_small_code.setText("");
            }

            if(chk_large_code.isChecked())
            {
                text_price_large_code.setText
                (text_large_code.getText().toString());
                text_check_large_code.setText
                (chk_large_code.getText().toString());

            }
            else {
                text_price_large_code.setText("");
                text_check_large_code.setText("");
                edit_qty_large_code.setText("");
            }
            // whenever i use below code getting error "start"

            x=Double.parseDouble
                    (text_price_regular_code.getText().toString());
            y=Double.parseDouble
                    (text_price_small_code.getText().toString());
            z=Double.parseDouble
                    (text_price_large_code.getText().toString());           
            a=x+y+z;
            text_total_code.setText(Double.toString(a));
            // whenever i use below code getting error "end"
        }
    };

    chk_regular_code.setOnClickListener(checkBoxListener);
    chk_small_code.setOnClickListener(checkBoxListener);
    chk_large_code.setOnClickListener(checkBoxListener);
}
4

1 回答 1

23

我会忽略这一点。您看到的消息在手机上很重要,但在模拟器中不重要。模拟器非常慢。您所做的一切都不是资源密集型的,因此您的应用程序应该名义上在设备上执行。

在设备上,您可以在某些手机上使用开发人员选项来启用可见信号,表明您可能在前台做太多工作。在我的 Galaxy Nexus 上,我可以导航到设置 > 开发人员选项 > 启用严格模式。选中该框将导致红色边框在任何应用程序周围闪烁,当它导致出现您从 logcat 发布的消息时。

消除警告的解决方案是线程,但我觉得你可能正在努力解决一个非问题。唯一知道的方法是设备测试。

于 2012-10-12T12:31:15.617 回答