单击按钮

时间:2017-05-21 13:49:23

标签: java android

我有这个RemoteCar应用程序,它有按钮,

  • “LOCK” - >引导你进入另一个活动。
  • “LOCATION” - >引导您进入另一项活动。
  • “START ENGINE” - >让您单击它,它将txt更改为 “发动机运行”。
  • “REFUEL” - >让你加油并增加我的ProgressBar(FuelBar)。

所以我遇到的问题是我不能再单击START ENGINE或REFUEL了,因为App仍然因为我无法解决的原因而崩溃。我可以轻松点击LOCATION并锁定那些完美无缺的工作。

这里我有ErrorMessage:

    05-21 13:39:52.887 1869-1869/? W/gralloc_ranchu: Gralloc pipe failed 05-21 13:39:52.897 1869-1869/? D/OpenGLRenderer: Enabling debug mode 0 05-21 13:39:53.097 1402-1429/system_process I/ActivityManager: Displayed com.example.schwarzerritter.remotecv02/.MainActivity: +546ms 05-21 13:39:53.297 1402-1429/system_process D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread) 05-21 13:39:56.857 1402-1486/system_process E/ThrottleService: problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory) 05-21 13:42:00.387 1869-1869/? D/AndroidRuntime: Shutting down VM 05-21 13:42:00.387 1869-1869/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa6661228) 05-21 13:42:00.387 1869-1869/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                         java.lang.IllegalStateException: Could not execute method for android:onClick
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
    at android.view.View.performClick(View.java:4084)
    at android.view.View$PerformClick.run(View.java:16966)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
    at android.view.View.performClick(View.java:4084) 
    at android.view.View$PerformClick.run(View.java:16966) 
    at android.os.Handler.handleCallback(Handler.java:615) 
    at android.os.Handler.dispatchMessage(Handler.java:92) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4745) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NumberFormatException: Invalid int: "AC : 18"
    at java.lang.Integer.invalidInt(Integer.java:138)
    at java.lang.Integer.parse(Integer.java:375)
    at java.lang.Integer.parseInt(Integer.java:366)
    at java.lang.Integer.parseInt(Integer.java:332)
    at com.example.schwarzerritter.remotecv02.MainActivity.onClick(MainActivity.java:41)

at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:4084) 
at android.view.View$PerformClick.run(View.java:16966) 
at android.os.Handler.handleCallback(Handler.java:615) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511)

MainActivity.Java:

public class MainActivity extends AppCompatActivity {
    public ProgressBar fuelBar;
    public Button lockButton;
    public Button engButton;
    public Button refuelButton;
    public Button plusButton;
    public Button minusButton;
    public Button locationButton;
    public SeekBar seekBarButton;
    public TextView seekText;
    int incFuel = 0;
    int acNum = 0;


    public void onClick(View v) {
        engButton = (Button) findViewById(R.id.engB);
        refuelButton = (Button) findViewById(R.id.refuelB);
        fuelBar = (ProgressBar) findViewById(R.id.fuelProgressBar);
        seekBarButton = (SeekBar) findViewById(R.id.seekBar);
        seekText = (TextView) findViewById(R.id.seekText);
        acNum = Integer.parseInt(seekText.getText().toString());



        switch (v.getId()) {
            case engB:
                if (engButton.getText() == "ENGINE RUNNING") {
                    engButton.setText("START ENGINE");
                } else {
                    if (fuelBar.getProgress() > 0) {
                        Toast.makeText(MainActivity.this,"Starting engine..",Toast.LENGTH_SHORT).show();
                        engButton.setText("ENGINE RUNNING");
                        if (fuelBar.getProgress() >= 10) {
                            incFuel = fuelBar.getProgress();
                            incFuel -= 10;
                            fuelBar.setProgress(incFuel);
                            if (fuelBar.getProgress() < 100)
                                refuelButton.setText("REFUEL");
                        }
                    } else
                        if(fuelBar.getProgress() == 0) {
                            Toast.makeText(MainActivity.this, "No fuel", Toast.LENGTH_SHORT).show();
                            engButton.setText("EMPTY GASTANK");
                        }else
                            engButton.setText("START ENGINE");
                }
                break;
            case refuelB:
                if (fuelBar.getProgress() == 0) {
                    engButton.setText("START ENGINE");
                    incFuel = fuelBar.getProgress();
                    incFuel += 10;
                    fuelBar.setProgress(incFuel);
                } else if (fuelBar.getProgress() < 100) {
                    incFuel = fuelBar.getProgress();
                    incFuel += 10;
                    fuelBar.setProgress(incFuel);
                } else {
                    Toast.makeText(MainActivity.this,"Tank is full",Toast.LENGTH_SHORT).show();
                    refuelButton.setText("FULL");
                }
                break;
        }
    }

    public void seek_bar(){
        seekBarButton = (SeekBar) findViewById(R.id.seekBar);
        seekText = (TextView) findViewById(R.id.seekText);
        seekText.setText("AC : " + (seekBarButton.getProgress() + 18));
        seekText.setText("AC : " + (seekBarButton.getProgress() + 18));
        seekBarButton.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            int progressNum;
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                progressNum = progress;
                seekText.setText("AC : " + (seekBarButton.getProgress() + 18) + "°");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                seekText.setText("AC : " + (seekBarButton.getProgress() + 18) + "°");
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                seekText.setText("AC : " + (seekBarButton.getProgress() + 18) + "°");
            }
        });
    }

    public void lockPage() {
        lockButton = (Button) findViewById(R.id.lockB);
        lockButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent lockPage = new Intent(MainActivity.this, lockDoor.class);
                startActivity(lockPage);
            }
        });
    }

    public void locationPage() {
        locationButton = (Button) findViewById(R.id.locationB);
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent locationPage = new Intent(MainActivity.this, location.class);
                startActivity(locationPage);
            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        locationButton = (Button) findViewById(R.id.locationB);
        lockButton = (Button) findViewById(R.id.lockB);
        engButton = (Button) findViewById(R.id.engB);
        refuelButton = (Button) findViewById(R.id.refuelB);
        fuelBar = (ProgressBar) findViewById(R.id.fuelProgressBar);
        fuelBar.setMax(100);
        fuelBar.setProgress(30);
        refuelButton.setText(R.string.refuelB);
        lockButton.setText(R.string.lockB);
        locationButton.setText(R.string.locationB);
        engButton.setText(R.string.engB);
        seekBarButton = (SeekBar) findViewById(R.id.seekBar);
        seekText = (TextView) findViewById(R.id.seekText);
        int acNum;
        seek_bar();
        lockPage();
        locationPage();

    }
}

1 个答案:

答案 0 :(得分:1)

java.lang.NumberFormatException: Invalid int: "AC : 18"
   at com.example.schwarzerritter.remotecv02.MainActivity.onClick(MainActivity.java:41)

您正尝试将字符串AC : 18转换为MainActivity.java第41行中的整数。

(阅读错误信息有帮助)