Skip to content Skip to sidebar Skip to footer

Invalid Ip Address Android Insert To Mysql

try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost('http://10.0.2.2/insert.php'); httppost.setEntity(new UrlEncoded

Solution 1:

You are trying to perform a networking operation on the main thread. See How to fix android.os.NetworkOnMainThreadException?

Solution 2:

@SuppressLint("NewApi")@OverridepublicvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicypolicy=newStrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.login);

add this code into you code then it will work

Solution 3:

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

here's my try catch

`try {
        // connectivity to databaseHttpClienthttpclient=newDefaultHttpClient();
        HttpPosthttppost=newHttpPost("http://xxx.xxx.x.xxx/cropkeeper/spinner/soilCategory.php");
        HttpResponseresponse= httpclient.execute(httppost);
        HttpEntityentity= 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();
    }`

where xxx.xxx.x.xxx is my IP Address.

Post a Comment for "Invalid Ip Address Android Insert To Mysql"