当前位置: 首页 > 面试题库 >

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

闻人修明
2023-03-14
问题内容

您好,我是学习android的新手,我正尝试在学习Android时制作一个半有用的应用程序(对我自己),基本上我是在第一时间接受有用的Java代码(ping
X,端口扫描)并添加将它们添加到我的应用中,我无法弄清楚 为什么
会发生此错误,我确实认为这与代码的第77行有关,但是我想了解为什么它无法正常工作,因此下次我可以更好地帮助自己。很抱歉出现罗word的问题,我不知道什么时候闭嘴。

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);
    }
}

问题答案:

该行抛出NPEIllegalStateException在异常链中产生一个:

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

因为您没有在方法中初始化stopPort(或startPortonCreate。您应该具有以下内容:

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

该声明

EditText stopPort;

只需 声明null默认情况下的变量即可。只有实例化的实例才能调用其方法。



 类似资料:
  • 我是一个相当新的Android程序员,在完成了几个教程后,我开始扩展我完成的BMI计算器教程。在此过程中,我需要删除并重新安装Eclipse。我还不得不切换工作区。由于我的错误,我只能保留应用程序的。java文件。我重新创建了。xml和清单,直到现在,当我尝试单击calculate按钮时,才得到了IllegalStateException。在切换和重新创建之前,一切都很好。我正在使用Nexus G

  • 我正在构建一个简单的客户机-服务器系统。我构建了一个Java服务器&一个运行在mine设备上的android客户端(两者连接到同一个LAN)。 当我试图建立一个连接(通过单击按钮)时,客户端失败并出现错误 Android客户端代码: manifest.xml: 布局文件:

  • 问题内容: 在添加异步任务之前,我已经对代码进行了一些更改,我的应用程序可以正常运行其远程服务器上的身份验证用户名和密码,但是在登录成功消息消失后​​无法启动其他活动。有人建议我现在添加一个异步任务,但是我输入正确的用户名和密码后它将停止工作。当我输入错误的用户名和密码时,其工作正常将显示错误的用户名密码消息。如果有人能够知道会出现什么错误,请帮助我。 码- 日志猫 QuestionnActivi

  • 我已经搜索了这个错误,并找到了许多解决方案,但我无法解决这个问题,因为我是Android的初学者 舱单在下面 安装应用程序后,它第一次工作,但当我们关闭并重新打开时,它崩溃了,不幸的是,应用程序已经关闭,你有任何想法,它将非常感谢:) 谢了!

  • xml文件 误差 05-21 21:31:39.665 135 9-1359/com.example.champ.remodme e/androidruntime:致命异常:main process:com.example.champ.remodme,pid:1359 java.lang.illegalstateException:无法执行Android方法:onclick at android.

  • 问题内容: 美好的一天,我尝试从另一个开始新的活动。但是它总是崩溃。这是我的代码。这是ListView上的事件。 向清单清单添加了活动 错误消息是 所有以前的活动,我添加的活动都很好… StudentInfoActivity 问题答案: 代替 改成 例如,活动actOne = null;