2014-10-11 53 views
0

代碼:無法動態使用上傳領域JSON的Android

btnSubmit.setOnClickListener(new OnClickListener() { 

     @Override 

     //http://********.***?user_id=11&address=Sanvordem%20-%20Dabal%20-%20Dharbandoda%20Road,%20Sanvordem,%20Goa%20403706,%20India&latitude=15.274322762603436&langtitude=74.11858866662601&property_id=Earth%20House&room_type=Shared%20Room&bedrooms=1&title=rttrrtrt&description=rtrtrtrtrtrtrt&capacity=Shared%20Room&price=45&currency=USD&phone=3453535&amenities=Pool,Heating&cancellation_policy=Strict 
     public void onClick(View v) { 
      String user="111"; 
      String prpoer="Earth House"; 
      String privicy="Shared Room"; 
      String beds="7"; 
      String tit="timothy"; 
      String descp="description test"; 
      String Accommodat="12"; 
      String pricerp="12"; 
      String priceusd="USD"; 
      String Cancelation="Strict"; 
      String phonenum="3434343434"; 


      //finalString url2 = "http://********************.***?user_id=111&address=Sanvordem%20-%20Dabal%20-%20Dharbandoda%20Road,%20Sanvordem,%20Goa%20403706,%20India&latitude=15.274322762603436&langtitude=74.11858866662601&property_id="+prpoer+"&room_type="+privicy+"&bedrooms="+beds+"&title="+tit+"&description="+descp+"&capacity="+Accommodat+"&price="+pricerp+"&currency="+priceusd+"&phone="+phonenum+"&amenities=Pool,Heating&cancellation_policy="+Cancelation; 
      //String url=url2.toString(); 
      //Log.d("URL IS:",url); 

      String url="http://********************.***?user_id=111&address=Sanvordem%20-%20Dabal%20-%20Dharbandoda%20Road,%20Sanvordem,%20Goa%20403706,%20India&latitude=15.274322762603436&langtitude=74.11858866662601&property_id=Earth%20House&room_type=Shared%20Room&bedrooms=7&title=timothy&description=description%20test&capacity=12&price=12&currency=USD&phone=3434343434&amenities=Pool,Heating&cancellation_policy=Strict"; 
      // Creating volley request obj 
      JsonArrayRequest movieReq = new JsonArrayRequest(url, 
        new Response.Listener<JSONArray>() { 
         @Override 
         public void onResponse(JSONArray response) { 
          Log.d(TAG, response.toString()); 


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

            JSONObject obj = response.getJSONObject(i); 
            String resu= obj.getString("reason_message"); 
            Log.d("OUTPUT IS",resu); 
            if(resu.matches("List added successfully.")) 
            { 
             AlertDialog alertDialog = new AlertDialog.Builder(listyourspace.this).create(); 
             alertDialog.setTitle("Data"); 
             alertDialog.setMessage("List added successfully...."); 
             alertDialog.show(); 
             Log.d("Success","success"); 
            } 



            // adding movie to movies array 


           } 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()); 


         } 
        }); 

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

    }); 
} 

logcat的輸出:

 
10-08 12:31:47.026: D/URL IS:(28292): http://********************.***?user_id=111&address=Sanvordem%20-%20Dabal%20-%20Dharbandoda%20Road,%20Sanvordem,%20Goa%20403706,%20India&latitude=15.274322762603436&langtitude=74.11858866662601&property_id=Earth House&room_type=Shared Room&bedrooms=7&title=timothy&description=description test&capacity=12&price=12&currency=USD&phone=3434343434&amenities=Pool,Heating&cancellation_policy=Strict 
10-08 12:31:48.470: E/Volley(28292): [26752] BasicNetwork.performRequest: Unexpected response code 500 for http://********************.***?user_id=111&address=Sanvordem%20-%20Dabal%20-%20Dharbandoda%20Road,%20Sanvordem,%20Goa%20403706,%20India&latitude=15.274322762603436&langtitude=74.11858866662601&property_id=Earth House&room_type=Shared Room&bedrooms=7&title=timothy&description=description test&capacity=12&price=12&currency=USD&phone=3434343434&amenities=Pool,Heating&cancellation_policy=Strict 
10-08 12:31:48.476: D/AndroidRuntime(28292): Shutting down VM 
10-08 12:31:48.479: E/AndroidRuntime(28292): FATAL EXCEPTION: main 
10-08 12:31:48.479: E/AndroidRuntime(28292): Process: info.androidhive.customlistviewvolley, PID: 28292 
10-08 12:31:48.479: E/AndroidRuntime(28292): java.lang.NullPointerException: format == null 
10-08 12:31:48.479: E/AndroidRuntime(28292): at java.lang.String.format(String.java:1960) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at com.android.volley.VolleyLog.buildMessage(VolleyLog.java:79) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at com.android.volley.VolleyLog.d(VolleyLog.java:55) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at info.androidhive.customlistviewvolley.listyourspace$6$2.onErrorResponse(listyourspace.java:404) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at com.android.volley.Request.deliverError(Request.java:563) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:101) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at android.os.Handler.handleCallback(Handler.java:733) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at android.os.Handler.dispatchMessage(Handler.java:95) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at android.os.Looper.loop(Looper.java:136) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at android.app.ActivityThread.main(ActivityThread.java:5086) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at java.lang.reflect.Method.invoke(Native Method) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
10-08 12:31:48.479: E/AndroidRuntime(28292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
+0

哎,你有沒有解決您的錯誤?如果是的話,請告訴我如何解決它,因爲我也面臨同樣的問題。謝謝 – 2015-04-21 06:07:42

回答

0

如果您收到一個HTTP狀態代碼後面(500),然後凌空正在按預期和你'很可能會發送您的服務器無法處理的請求。

我建議嘗試一個已知工作的公共API。我建議打開天氣圖。

http://openweathermap.org/api

感謝