1

我遇到了奇怪的问题。我是 android 新手,我编写了一些随机应用程序,将一些数据发送到我的外部数据库。一切正常,几天前它停止了。这没什么特别的,但是……我做了 0 次更改,我没有触及代码。它只是无缘无故停止工作。这是我(我知道,不好的)代码的一部分。我正在进入NullPointerExclient.execute (hp)行(如果我很好地理解 logcat)。

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    double latitude = loc.getLatitude();
    double longitude = loc.getLongitude();

    Intent intent = new Intent(this, LoggedInSys.class);
    EditText editText = (EditText) findViewById(R.id.editTextUsername);
    String username = editText.getText().toString();

    try {
        DefaultHttpClient client = new DefaultHttpClient();
        HttpPost hp = new HttpPost("LINK TO MY PHP SCRIPT");
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("lat", String.valueOf(latitude)));
        params.add(new BasicNameValuePair("lon", String.valueOf(longitude)));            
        params.add(new BasicNameValuePair("name", username));                   
        hp.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse response = client.execute(hp);

        HttpEntity entity = response.getEntity();
        isr = entity.getContent();


    }catch(Exception ex){

        ex.printStackTrace();
    }


    BufferedReader reader = new BufferedReader(new InputStreamReader(isr));
    StringBuilder sb = new StringBuilder();
    String line;

    try {
        while((line=reader.readLine())!=null){
            sb.append(line);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        isr.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    result = sb.toString();


    intent.putExtra(EXTRA_LATITUDE, String.valueOf(latitude));
    intent.putExtra(EXTRA_LONGITUDE, String.valueOf(longitude));

    intent.putExtra(EXTRA_USERNAME, username);
    intent.putExtra(EXTRA_DEVID, result);
    startActivity(intent);

真的很奇怪,我什么都没改怎么会停止工作?请问有什么建议吗?

日志:

 11-13 10:42:52.689: D/AndroidRuntime(26259): Shutting down VM
11-13 10:42:52.689: W/dalvikvm(26259): threadid=1: thread exiting with uncaught exception (group=0x2aac8578)
11-13 10:42:52.689: E/AndroidRuntime(26259): FATAL EXCEPTION: main
11-13 10:42:52.689: E/AndroidRuntime(26259): java.lang.IllegalStateException: Could not execute method of the activity
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.view.View$1.onClick(View.java:2168)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.view.View.performClick(View.java:2552)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.view.View$PerformClick.run(View.java:9229)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.os.Handler.handleCallback(Handler.java:587)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.os.Looper.loop(Looper.java:130)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.app.ActivityThread.main(ActivityThread.java:3701)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at java.lang.reflect.Method.invokeNative(Native Method)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at java.lang.reflect.Method.invoke(Method.java:507)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at dalvik.system.NativeStart.main(Native Method)
11-13 10:42:52.689: E/AndroidRuntime(26259): Caused by: java.lang.reflect.InvocationTargetException
11-13 10:42:52.689: E/AndroidRuntime(26259):    at java.lang.reflect.Method.invokeNative(Native Method)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at java.lang.reflect.Method.invoke(Method.java:507)
11-13 10:42:52.689: E/AndroidRuntime(26259):    at android.view.View$1.onClick(View.java:2163)
11-13 10:42:52.689: E/AndroidRuntime(26259):    ... 11 more
11-13 10:42:52.689: E/AndroidRuntime(26259): Caused by: java.lang.NullPointerException
11-13 10:42:52.689: E/AndroidRuntime(26259):    at com.example.mojaapka.MainActivity.logInSystem(MainActivity.java:61)
11-13 10:42:52.689: E/AndroidRuntime(26259):    ... 14 more
11-13 10:42:54.539: I/Process(26259): Sending signal. PID: 26259 SIG: 9
4

0 回答 0