2016-09-23 14 views
0

ローカルマシンで実行されるJSONデータを生成するスプリングブートWebサービスがありますhttp://localhost:8080/demo/services接続タイムアウトのためにJSONデータを取得できませんでした

私は私のIPアドレスを使用してJSONデータを取得しようとしましたが、それはLogCatに次のエラーを与えた:

09-23 15:18:27.897 2923-3540/com.example.palangou.foodie1 
    W/System.err: java.net.ConnectException: failed to connect to /192.168.1.9 
    (port 8080): connect failed: ETIMEDOUT (Connection timed out) 

関連するJavaコードは次のとおりです。

new JSONpart().execute("http://192.168.1.9:8080/demo/services"); 

public class JSONpart extends AsyncTask<String, Void, List<POJO>> { 


    @Override 
    protected List<POJO> doInBackground(String... urls) { 
     HttpURLConnection connection = null; 
     BufferedReader reader = null; 
     StringBuffer buffer = new StringBuffer(); 
     String place = "", name = ""; 
     List<POJO> arraylist = new ArrayList<>(); 
     try { 
      URL url = new URL(urls[0]); 
      try { 
       connection = (HttpURLConnection) url.openConnection(); 
       connection.connect(); 
       InputStream input = connection.getInputStream(); 
       reader = new BufferedReader(new InputStreamReader(input)); 

       String line = ""; 
       while ((line = reader.readLine()) != null) { 
        buffer.append(line); 
       } 

       Log.d("Recursive places",buffer.toString()); 
       String finalJSON = buffer.toString(); 
       try { 
        //JSONObject object = new JSONObject(finalJSON); 
        JSONArray array = new JSONArray(finalJSON); 

        for(int i=0;i< array.length();i++) 
        {//Log.d("Recursive places",  finalobject.getString("name")); 
         POJO pojo = new POJO(); 
         JSONObject finalobject = array.getJSONObject(i); 
         pojo.setName(finalobject.getString("service")); 
         pojo.setPlace(finalobject.getString("servicedesc")); 
         // 
         arraylist.add(pojo); 

        } 

       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 
       // Log.d("name", arraylist.get(1).getName().toString()); 

      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
      ; 
     } finally { 
      connection.disconnect(); 
      try { 
       reader.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
     // return buffer.toString(); 
     return arraylist; 
    } 

    @Override 
    protected void onPostExecute(List<POJO> s) { 
     super.onPostExecute(s); 
     // Log.d("OnPOST", s.get(1).getName().toString()); 
     FoodiesAdapater adapter = new FoodiesAdapater(getApplicationContext(),R.layout.row,s); 
     listView.setAdapter(adapter); 



    } 
} 
+0

あなたのAPIは動作していますか? –

+1

あなたのPCが接続されているのと同じ無線LANに接続しましたか? – user6556461

+0

あなたはサーバーがオンかどうかをチェックしてください! – W4R10CK

答えて

1

あなたのAPIまたはかどうかを確認してくださいURLが機能しています。あなたがこのhttp://myjson.com/にあなたのJsonファイルをアップロードして、このオンラインサーバからURLを取得すればよいでしょう。

+0

また、このリンクでJsonが動作しているかどうかを確認できます。 vishnumm93

+0

LogCatが問題を示していないためそれ。 @GouthamPalaniここで少し説明できますか? :) – Sufian

+0

@Sufian私はちょうどmyjson.comを使ってデータを取得しました。手動でJSONファイルをアップロードしました –

関連する問題