try
    {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2/insert.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        Log.e("pass 1", "connection success ");
    }
    catch(Exception e)
    {
        Log.e("Fail 1", e.toString());
        Toast.makeText(getApplicationContext(), "Invalid IP Address",
                Toast.LENGTH_LONG).show();
    }


我想从我的Android应用程序向mysql数据库插入一些值,并且显示错误“无效的IP地址”,请帮忙。提前致谢。

Logcat错误
09-21 12:57:12.084 912-912 / com.srg.ibc.appointmentapplication E / Fail 1:android.os.NetworkOnMainThreadException
09-21 12:57:12.114 912-912 / com.srg.ibc.appointmentapplication E / Fail 2:java.lang.NullPointerException:lock == null
09-21 12:57:12.114 912-912 / com.srg.ibc.appointmentapplication E / Fail 3:java.lang.NullPointerException

最佳答案

您正在尝试在主线程上执行联网操作。
How to fix android.os.NetworkOnMainThreadException?

10-06 06:11