I am trying to parse local url (http://192.168.1.94/wamp/up.php) to use it in my app android ( JSON parse ).
mainActivity android :
package itawfik.com.myapplication; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class MainActivity extends ActionBarActivity { Button btnHit; TextView txtJson; ProgressDialog pd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnHit = (Button) findViewById(R.id.btnHit); txtJson = (TextView) findViewById(R.id.name); btnHit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new JsonTask().execute("http://192.168.1.94/wamp/up.php"); } }); } private class JsonTask extends AsyncTask<String, String, String> { protected void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(MainActivity.this); pd.setMessage("Please wait"); pd.setCancelable(false); pd.show(); } protected String doInBackground(String... params) { HttpURLConnection connection = null; BufferedReader reader = null; try { URL url = new URL(params[0]); connection = (HttpURLConnection) url.openConnection(); connection.connect(); InputStream stream = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(stream)); StringBuffer buffer = new StringBuffer(); String line = ""; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); Log.d("Response: ", "> " + line); //here u ll get whole response...... :-) } return buffer.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (connection != null) { connection.disconnect(); } try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } return null; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); if (pd.isShowing()) { pd.dismiss(); } txtJson.setText(result); } } }
ERROR look like :
08-14 17:21:23.599 4201-4201/itawfik.com.myapplication E/SysUtils: ApplicationContext is null in ApplicationStatus 08-14 17:21:23.607 4201-4201/itawfik.com.myapplication E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY) 08-14 17:21:23.607 4201-4201/itawfik.com.myapplication E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
[ 08-14 17:21:23.608 4201: 4201 D/ ]
HostConnection::get() New Host Connection established 0xb07743d0, tid 4201 08-14 17:21:23.799 4201-4201/itawfik.com.myapplication E/DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp