一段时间后应用程序停止工作

时间:2013-11-13 09:34:37

标签: android nullpointerexception http-post

我遇到了奇怪的问题。我是android的新手,我编写了一些随机应用程序,它将一些数据发送到我的外部数据库。一切都运转正常,几天前就停止了。它不会有什么特别的但是......我做了0次更改,我没有触及代码。它没有任何理由停止工作。这是我(我知道,不好)代码的一部分。我在 client.execute(hp)行上获得NullPointerEx(如果我理解了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

0 个答案:

没有答案