2014-09-19 36 views
0

如何在解析string = null時烘烤消息? 這裏是我的json解析代碼。 基本上我需要這個當沒有互聯網服務解析消息彈出與結果沒有網絡服務。解析string = null時,我該如何烘烤消息?

JsonArrayRequest movieReq = new JsonArrayRequest(url, 
      new Response.Listener<JSONArray>() { 
       @Override 
       public void onResponse(JSONArray response) { 
        Log.d(TAG, response.toString()); 
        hidePDialog(); 

        // Parsing json 
        for (int i = 0; i < response.length(); i++) { 
         try { 

          JSONObject obj = response.getJSONObject(i); 
          Movie movie = new Movie(); 
          movie.setTitle(obj.getString("title")); 
          movie.setThumbnailUrl(obj.getString("image")); 
          movie.setRating(((Number) obj.get("rating")) 
            .doubleValue()); 
          movie.setYear(obj.getInt("releaseYear")); 

          // Genre is json array 
          JSONArray genreArry = obj.getJSONArray("genre"); 
          ArrayList<String> genre = new ArrayList<String>(); 
          for (int j = 0; j < genreArry.length(); j++) { 
           genre.add((String) genreArry.get(j)); 
          } 
          movie.setGenre(genre); 

          // adding movie to movies array 
          movieList.add(movie); 

         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 

        } 

        // notifying list adapter about data changes 
        // so that it renders the list view with updated data 
        adapter.notifyDataSetChanged(); 
       } 
      }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        VolleyLog.d(TAG, "Error: " + error.getMessage()); 
        hidePDialog(); 

       } 
      }); 

    // Adding request to request queue 
    AppController.getInstance().addToRequestQueue(movieReq); 
} 
+0

與你想要的東西更加清晰.. – 2014-09-19 09:24:04

+0

究竟不起作用?只要調用Toast.makeText(),無論您註冊錯誤...?你需要一個上下文來交給makeText()方法,所以你需要確保你有一個... – 2014-09-19 09:24:07

+0

如前所述,請更清楚。這裏是一個使用吐司的例子:http://stackoverflow.com/a/15198378/1990536 – Rai 2014-09-19 09:32:09

回答

0

嘗試這樣的:

Toast.makeText(Classname, "Message you want", Toast.LENGTH_LONG).show(); 
+0

我如何在json string = null中實現這個toast – 2014-09-19 10:05:36