问题描述
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地址",请帮忙.预先感谢.
I want to insert some value from my android application to mysql database and it showed an error "Invalid Ip Address" Please help. Thanks in advance.
Logcat错误09-21 12:57:12.084 912-912/com.srg.ibc.appointmentapplication E/Fail 1:android.os.NetworkOnMainThreadException09-21 12:57:12.114 912-912/com.srg.ibc.appointmentapplication E/Fail 2:java.lang.NullPointerException:lock == null09-21 12:57:12.114 912-912/com.srg.ibc.appointmentapplication E/Fail 3:java.lang.NullPointerException
Logcat error09-21 12:57:12.084 912-912/com.srg.ibc.appointmentapplication E/Fail 1﹕ android.os.NetworkOnMainThreadException09-21 12:57:12.114 912-912/com.srg.ibc.appointmentapplication E/Fail 2﹕ java.lang.NullPointerException: lock == null09-21 12:57:12.114 912-912/com.srg.ibc.appointmentapplication E/Fail 3﹕ java.lang.NullPointerException
推荐答案
我使用愤怒的IP扫描程序扫描路由器中的主机,获取路由器分配给我的机器的IP地址,然后将其替换为URL; http://xxx.xxx.x.xxx/cropkeeper/spinner/soilCategory.php
I used Angry IP scanner to scan my router for hosts, got the IP address the router assigns to my machine , and replaced it in the URL thus ; http://xxx.xxx.x.xxx/cropkeeper/spinner/soilCategory.php
这是我的尝试
`try {
// connectivity to database
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxx.xxx.x.xxx/cropkeeper/spinner/soilCategory.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e) {
Log.e("Fail 3", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address", Toast.LENGTH_LONG).show();
finish();
}`
其中xxx.xxx.x.xxx
是我的IP地址.
这篇关于无效的IP地址Android插入到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!