1

"android..com" is my url that i publish my website on subdomain my android work well in my system that i use 192.168.1.8/ and in browsers when i call url that my app calls work well and shows the correct json

public class  downloadTask extends AsyncTask<String,Void,String> {

        @Override
        protected String doInBackground(String... urls) {
            String result="";
            URL url;
            HttpURLConnection httpURLConnection=null;
            try {
                url=new URL(urls[0]);

                httpURLConnection=(HttpURLConnection)url.openConnection();
                InputStream inputStream =httpURLConnection.getInputStream();
                InputStreamReader reader=new InputStreamReader(inputStream);
                int data=reader.read();
                while (data!=-1){
                    char ch=(char)data;
                    result+=ch;
                    data=reader.read();
                }


            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }

        @Override
        protected void onPostExecute(String s) {
            Log.i("res",s);
            super.onPostExecute(s);
            try {
                JSONArray jObj = new JSONArray(s);
                for(int i=0; i < jObj.length(); i++) {
                    JSONObject jsonobject = jObj.getJSONObject(i);
                    MessageStruct msg=new MessageStruct();
                    msg.isRead        = jsonobject.getString("isRead");
                    msg.subject      = jsonobject.getString("subject");
                    msg.image      = jsonobject.getString("image");
                    msg.body      = jsonobject.getString("body");
                    msg.messageId      = jsonobject.getString("messageId");
                    msg.senderId      = jsonobject.getString("senderId");
                    msg.senderUsername      = jsonobject.getString("username");
                    messageStructs.add(msg);

                }
            } catch (JSONException e) {
                Log.e("JSON Parser", "Error parsing data " + e.toString());
            }
            ListView lstContent=(ListView) findViewById(R.id.lstContent);

            // Log.i("ss",arrayList.get(4).title);
            adapter=new MessageAdapter(messageStructs);
            lstContent.setAdapter(adapter);

            adapter.notifyDataSetChanged();

        }
    }


     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_message_inbox);
            downloadTask task=new downloadTask();
            Log.i("url",G.HostUrl+"Message/Inbox/"+G.username);
            task.execute(G.HostUrl+"Message/Inbox/"+G.username);
        }

i dont Know why is happen i use this permissions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

but when i set local url is work correctly

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
aliyousefian
  • 449
  • 5
  • 14

1 Answers1

1

This error means the URL you trying to call is not accessible in the network that, you are using.

Muhammad Noman
  • 1,842
  • 19
  • 14