简体   繁体   English

Android java.lang.IllegalStateException:无法执行活动的方法

[英]Android java.lang.IllegalStateException: Could not execute method of the activity

Hello I'm new to learning android and I'm trying to make a semi-useful app (to myself) while learning Android, I'm basically at the minute taking useful bits of Java code (ping X, Port Scan) and adding them to my app, I cannot figure out why this error is occurring, I do believe it is to do with Line 77 of the code but I want to learn why it is isn't working so I can better help myself next time. 你好我是新手学习android而我正在尝试制作一个半有用的应用程序(对我自己),同时学习Android,我基本上只需要花费大量的Java代码(ping X,Port Scan)并添加他们到我的应用程序,我无法弄清楚为什么会出现这个错误,我确实认为它与代码的第77行有关,但我想知道为什么它不起作用所以我下次可以更好地帮助自己。 Sorry for the wordy question, I don't know when to shut up. 抱歉这个罗嗦的问题,我不知道什么时候闭嘴。

01-25 20:42:42.139: E/AndroidRuntime(1307): FATAL EXCEPTION: main
01-25 20:42:42.139: E/AndroidRuntime(1307): java.lang.IllegalStateException: Could not execute method of the activity
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.view.View$1.onClick(View.java:3597)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.view.View.performClick(View.java:4202)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.view.View$PerformClick.run(View.java:17340)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.os.Handler.handleCallback(Handler.java:725)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.os.Looper.loop(Looper.java:137)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at dalvik.system.NativeStart.main(Native Method)
01-25 20:42:42.139: E/AndroidRuntime(1307): Caused by: java.lang.reflect.InvocationTargetException
01-25 20:42:42.139: E/AndroidRuntime(1307):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:42:42.139: E/AndroidRuntime(1307):     at android.view.View$1.onClick(View.java:3592)
01-25 20:42:42.139: E/AndroidRuntime(1307):     ... 11 more
01-25 20:42:42.139: E/AndroidRuntime(1307): Caused by: java.lang.NullPointerException
01-25 20:42:42.139: E/AndroidRuntime(1307):     at com.seven.up.MainActivity.OnClickPort(MainActivity.java:77)
01-25 20:42:42.139: E/AndroidRuntime(1307):     ... 14 more
01-25 20:44:42.549: E/MPL-storeload(511): calData from inv_save_mpl_states, size=2
01-25 20:45:39.759: E/InputDispatcher(511): channel '41b55368 com.seven.up/com.seven.up.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-25 20:45:50.279: E/AndroidRuntime(1625): FATAL EXCEPTION: main
01-25 20:45:50.279: E/AndroidRuntime(1625): java.lang.IllegalStateException: Could not execute method of the activity
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.view.View$1.onClick(View.java:3597)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.view.View.performClick(View.java:4202)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.view.View$PerformClick.run(View.java:17340)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.os.Handler.handleCallback(Handler.java:725)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.os.Looper.loop(Looper.java:137)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at dalvik.system.NativeStart.main(Native Method)
01-25 20:45:50.279: E/AndroidRuntime(1625): Caused by: java.lang.reflect.InvocationTargetException
01-25 20:45:50.279: E/AndroidRuntime(1625):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:45:50.279: E/AndroidRuntime(1625):     at android.view.View$1.onClick(View.java:3592)
01-25 20:45:50.279: E/AndroidRuntime(1625):     ... 11 more
01-25 20:45:50.279: E/AndroidRuntime(1625): Caused by: java.lang.NullPointerException
01-25 20:45:50.279: E/AndroidRuntime(1625):     at com.seven.up.MainActivity.OnClickPort(MainActivity.java:78)
01-25 20:45:50.279: E/AndroidRuntime(1625):     ... 14 more
01-25 20:46:32.409: E/InputDispatcher(511): channel '416e8e78 com.seven.up/com.seven.up.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-25 20:46:35.449: E/AndroidRuntime(1830): FATAL EXCEPTION: main
01-25 20:46:35.449: E/AndroidRuntime(1830): java.lang.IllegalStateException: Could not execute method of the activity
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.view.View$1.onClick(View.java:3597)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.view.View.performClick(View.java:4202)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.view.View$PerformClick.run(View.java:17340)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.os.Handler.handleCallback(Handler.java:725)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.os.Looper.loop(Looper.java:137)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at dalvik.system.NativeStart.main(Native Method)
01-25 20:46:35.449: E/AndroidRuntime(1830): Caused by: java.lang.reflect.InvocationTargetException
01-25 20:46:35.449: E/AndroidRuntime(1830):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:46:35.449: E/AndroidRuntime(1830):     at android.view.View$1.onClick(View.java:3592)
01-25 20:46:35.449: E/AndroidRuntime(1830):     ... 11 more
01-25 20:46:35.449: E/AndroidRuntime(1830): Caused by: java.lang.NullPointerException
01-25 20:46:35.449: E/AndroidRuntime(1830):     at com.seven.up.MainActivity.OnClickPort(MainActivity.java:77)
01-25 20:46:35.449: E/AndroidRuntime(1830):     ... 14 more
01-25 20:47:40.119: E/AndroidRuntime(2009): FATAL EXCEPTION: main
01-25 20:47:40.119: E/AndroidRuntime(2009): java.lang.IllegalStateException: Could not execute method of the activity
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.view.View$1.onClick(View.java:3597)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.view.View.performClick(View.java:4202)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.view.View$PerformClick.run(View.java:17340)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.os.Handler.handleCallback(Handler.java:725)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.os.Looper.loop(Looper.java:137)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at dalvik.system.NativeStart.main(Native Method)
01-25 20:47:40.119: E/AndroidRuntime(2009): Caused by: java.lang.reflect.InvocationTargetException
01-25 20:47:40.119: E/AndroidRuntime(2009):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:47:40.119: E/AndroidRuntime(2009):     at android.view.View$1.onClick(View.java:3592)
01-25 20:47:40.119: E/AndroidRuntime(2009):     ... 11 more
01-25 20:47:40.119: E/AndroidRuntime(2009): Caused by: java.lang.NullPointerException
01-25 20:47:40.119: E/AndroidRuntime(2009):     at com.seven.up.MainActivity.OnClickPort(MainActivity.java:77)
01-25 20:47:40.119: E/AndroidRuntime(2009):     ... 14 more
01-25 20:49:29.979: E/InputDispatcher(511): channel '414e7770 com.seven.up/com.seven.up.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-25 20:49:30.149: E/jdwp(2216): Failed sending reply to debugger: Broken pipe
01-25 20:49:41.599: E/MPL-storeload(511): calData from inv_save_mpl_states, size=2
01-25 20:50:12.539: E/InputDispatcher(511): channel '41c0a160 com.seven.up/com.seven.up.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-25 20:50:13.629: E/InputManager-JNI(511): An exception was thrown by callback 'interceptKeyBeforeQueueing'.
01-25 20:50:13.629: E/InputManager-JNI(511): java.lang.NullPointerException
01-25 20:50:13.629: E/InputManager-JNI(511):    at com.android.internal.policy.impl.PhoneWindowManager.interceptKeyBeforeQueueing(PhoneWindowManager.java:3948)
01-25 20:50:13.629: E/InputManager-JNI(511):    at com.android.server.wm.InputMonitor.interceptKeyBeforeQueueing(InputMonitor.java:337)
01-25 20:50:13.629: E/InputManager-JNI(511):    at com.android.server.input.InputManagerService.interceptKeyBeforeQueueing(InputManagerService.java:1346)
01-25 20:50:13.629: E/InputManager-JNI(511):    at dalvik.system.NativeStart.run(Native Method)
01-25 20:50:13.899: E/InputManager-JNI(511): An exception was thrown by callback 'interceptKeyBeforeQueueing'.
01-25 20:50:13.899: E/InputManager-JNI(511): java.lang.NullPointerException
01-25 20:50:13.899: E/InputManager-JNI(511):    at com.android.internal.policy.impl.PhoneWindowManager.interceptKeyBeforeQueueing(PhoneWindowManager.java:3948)
01-25 20:50:13.899: E/InputManager-JNI(511):    at com.android.server.wm.InputMonitor.interceptKeyBeforeQueueing(InputMonitor.java:337)
01-25 20:50:13.899: E/InputManager-JNI(511):    at com.android.server.input.InputManagerService.interceptKeyBeforeQueueing(InputManagerService.java:1346)
01-25 20:50:13.899: E/InputManager-JNI(511):    at dalvik.system.NativeStart.run(Native Method)
01-25 20:50:19.759: E/InputDispatcher(511): channel '41419b38 com.seven.up/com.seven.up.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-25 20:51:49.459: E/WeatherXmlParser(2522): Couldn't parse Yahoo weather XML
01-25 20:51:49.459: E/WeatherXmlParser(2522): java.lang.NumberFormatException: Invalid float: ""
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at java.lang.StringToReal.invalidReal(StringToReal.java:63)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at java.lang.StringToReal.parseFloat(StringToReal.java:289)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at java.lang.Float.parseFloat(Float.java:300)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at com.cyanogenmod.lockclock.weather.WeatherXmlParser.getFloatForAttribute(WeatherXmlParser.java:86)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at com.cyanogenmod.lockclock.weather.WeatherXmlParser.parseWeatherResponse(WeatherXmlParser.java:108)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at com.cyanogenmod.lockclock.weather.WeatherUpdateService$WeatherUpdateTask.doInBackground(WeatherUpdateService.java:210)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at com.cyanogenmod.lockclock.weather.WeatherUpdateService$WeatherUpdateTask.doInBackground(WeatherUpdateService.java:126)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-25 20:51:49.459: E/WeatherXmlParser(2522):   at java.lang.Thread.run(Thread.java:856)
01-25 20:52:24.619: E/MPL-storeload(511): calData from inv_save_mpl_states, size=2
01-25 20:57:07.229: E/AndroidRuntime(2410): FATAL EXCEPTION: main
01-25 20:57:07.229: E/AndroidRuntime(2410): java.lang.IllegalStateException: Could not execute method of the activity
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.view.View$1.onClick(View.java:3597)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.view.View.performClick(View.java:4202)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.view.View$PerformClick.run(View.java:17340)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.os.Handler.handleCallback(Handler.java:725)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.os.Looper.loop(Looper.java:137)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at dalvik.system.NativeStart.main(Native Method)
01-25 20:57:07.229: E/AndroidRuntime(2410): Caused by: java.lang.reflect.InvocationTargetException
01-25 20:57:07.229: E/AndroidRuntime(2410):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:57:07.229: E/AndroidRuntime(2410):     at android.view.View$1.onClick(View.java:3592)
01-25 20:57:07.229: E/AndroidRuntime(2410):     ... 11 more
01-25 20:57:07.229: E/AndroidRuntime(2410): Caused by: java.lang.NullPointerException
01-25 20:57:07.229: E/AndroidRuntime(2410):     at com.seven.up.MainActivity.OnClickPort(MainActivity.java:77)
01-25 20:57:07.229: E/AndroidRuntime(2410):     ... 14 more
01-25 20:59:12.549: E/AndroidRuntime(3168): FATAL EXCEPTION: main
01-25 20:59:12.549: E/AndroidRuntime(3168): java.lang.IllegalStateException: Could not execute method of the activity
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.view.View$1.onClick(View.java:3597)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.view.View.performClick(View.java:4202)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.view.View$PerformClick.run(View.java:17340)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.os.Handler.handleCallback(Handler.java:725)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.os.Looper.loop(Looper.java:137)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at dalvik.system.NativeStart.main(Native Method)
01-25 20:59:12.549: E/AndroidRuntime(3168): Caused by: java.lang.reflect.InvocationTargetException
01-25 20:59:12.549: E/AndroidRuntime(3168):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 20:59:12.549: E/AndroidRuntime(3168):     at android.view.View$1.onClick(View.java:3592)
01-25 20:59:12.549: E/AndroidRuntime(3168):     ... 11 more
01-25 20:59:12.549: E/AndroidRuntime(3168): Caused by: java.lang.NullPointerException
01-25 20:59:12.549: E/AndroidRuntime(3168):     at com.seven.up.MainActivity.OnClickPort(MainActivity.java:76)
01-25 20:59:12.549: E/AndroidRuntime(3168):     ... 14 more
01-25 21:01:13.939: E/MPL-storeload(511): calData from inv_save_mpl_states, size=2


package com.seven.up;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
    EditText ip_address_field;
    TextView scan_out;
    TextView port_results;
    EditText startPort;
    EditText stopPort;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ip_address_field = (EditText) findViewById(R.id.ip_address_field);
        ip_address_field.getText();
        scan_out = (TextView) findViewById(R.id.scan_out);

        Button scan_button = (Button) findViewById(R.id.scan_button);
        scan_button.setOnClickListener(this);
    }

    public void onClick(View v) {
        Editable host = ip_address_field.getText();

        switch (v.getId()) {

        case R.id.scan_button:
            try {
                String pingCmd = "ping -c 5 " + host;
                String pingResult = "";
                Runtime r = Runtime.getRuntime();
                Process p = r.exec(pingCmd);
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        p.getInputStream()));
                String inputLine;
                while ((inputLine = in.readLine()) != null) {
                    System.out.println(inputLine);
                    scan_out.setText(inputLine + "\n" + "\n");
                    pingResult += inputLine;
                    scan_out.setText("/n" + pingResult);
                }
                in.close();
            }// try
            catch (IOException e) {
                System.out.println(e);
            }
            break;

        default:
            break;
        }

    }

    public void OnClickPort(View v) {
        switch (v.getId()) {
        case R.id.button1:

        int startPortRange = Integer.parseInt(startPort.getText().toString());
        int stopPortRange = Integer.parseInt(stopPort.getText().toString());

        for (int i = startPortRange; i <= stopPortRange; i++) {
            try {
                Socket ServerSok = new Socket("192.168.0.1", i);

                Toast.makeText(getApplicationContext(), "Port in use: " + i, Toast.LENGTH_LONG).show();

                ServerSok.close();
            } catch (Exception e) {
            }
            System.out.println("Port not in use: " + i);
        } 
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_main, menu);
        return super.onCreateOptionsMenu(menu);
    }
}

This line is throwing an NPE , producing an IllegalStateException in the exception chain: 这一行抛出一个NPE ,在异常链中产生一个IllegalStateException

int stopPortRange = Integer.parseInt(stopPort.getText().toString());

as you don't initialize stopPort (or startPort ) in your onCreate method. 因为你没有在onCreate方法中初始化stopPort (或startPort )。 You should have something like: 你应该有类似的东西:

stopPort = (EditText) findViewById(R.id.stop_port_field);

The statement 该声明

EditText stopPort;

simply declares the variable which is null by default. 简单地声明默认为null的变量。 Only instances that have been instantiated can have their methods invoked. 只有已实例化的实例才能调用其方法。

Kind of late reply but still, @Pheonix2105, As mentioned by Reimeus, 有点迟到但仍然,@ Pheonix2105,正如Reimeus所说,

EditText startPort, stopPort;

just declares the variables. 只是声明变量。 This does not initialize the values for these declared variables. 这不会初始化这些声明的变量的值。 Hence the value of these variables are currently 'null'. 因此,这些变量的值目前为“空”。

stopPort = (EditText) findViewById (R.id.stop_port_field)

initializes (or in your terms, ties the stopPort to a UI component) the value of stopPort, thereby avoiding the NullPointerException (which in turn causes the IllegalStatementException in your case). 初始化(或者用你的术语,将stopPort绑定到UI组件)stopPort的值,从而避免NullPointerException(在你的情况下反过来导致IllegalStatementException)。

Hope that clarifies your doubt. 希望澄清你的疑问。

Either

  • Didn't initialise a variable or 没有初始化变量或
  • Initialised a variable and overwrote it when you were declaring them 初始化变量并在声明它时覆盖它

Often people duplicate the same line in anticipation to change one variable name in each line, to try and make it faster for you, but might forget one line, or miss one word change 通常人们会复制相同的行,以期在每行中更改一个变量名称,尝试让它更快,但可能会忘记一行,或者错过一个单词更改

EditText stopPort;

That is your problem 那是你的问题

I had the same issue: 我遇到过同样的问题:

Just initialize/declare you View fields below these lines in the onCreate Fuction: 只需初始化/声明你在onCreate Fuction中查看这些行下方的字段:

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

Eg 例如

protected void onCreate(Bundle savedInstanceState) 
 {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    bart = (ImageView) findViewById(R.id.bartView);
    homer = (ImageView) findViewById(R.id.homerView);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:java.lang.IllegalStateException:无法执行活动的方法 - Android: java.lang.IllegalStateException: Could not execute method of the activity java.lang.IllegalStateException:无法执行活动的方法 - java.lang.IllegalStateException: Could not execute method of the activity java.lang.IllegalStateException:无法执行活动的方法,如何解决? - java.lang.IllegalStateException: Could not execute method of the activity, how to solve? java.lang.IllegalStateException:无法执行活动的方法 - java.lang.IllegalStateException: Could not execute method of the activity java.lang.IllegalStateException:无法执行活动的方法(共享首选项) - java.lang.IllegalStateException: Could not execute method of the activity (Shared Preferences) Android sqlite更新方法; java.lang.IllegalStateException:无法执行活动的方法 - Android sqlite update method; java.lang.IllegalStateException: Could not execute method of the activity java.lang.IllegalStateException:在Android Studio中执行Retrofit GET方法时,无法执行活动的方法 - java.lang.IllegalStateException: Could not execute method of the activity while executing Retrofit GET method in Android studio java.lang.IllegalStateException:无法为 android 执行方法:onClick / ZE84E30B9390CDB67ZDDB6 - java.lang.IllegalStateException: Could not execute method for android:onClick / Android java.lang.IllegalStateException:无法执行android:onClick的方法 - java.lang.IllegalStateException: Could not execute method for android:onClick in android 错误:java.lang.IllegalStateException:无法执行android:onClick的方法 - Error: java.lang.IllegalStateException: Could not execute method for android:onClick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM