如何在JSON数据的编辑文本字段中设置文本

时间:2014-10-29 04:25:54

标签: java android

这是我使用的代码,但是当我进入页面时,它会自动停止。我使用了凌空请求对象,它也不支持facebook登录。我使用自定义列表视图谷来进行Web服务。

public void reload()
{
//final AlertDialog alertDialog = new AlertDialog.Builder(Editprofile.this).create();

   Log.d("url23",url23);
   // Creating volley request obj
  JsonArrayRequest movieReq = new JsonArrayRequest(url23,
          new Response.Listener<JSONArray>() {
              @Override
              public void onResponse(JSONArray response) {
                  String TAG = null;
                Log.d(TAG, response.toString());


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

                          JSONObject obj = response.getJSONObject(i);
                       /*   String fn= obj.getString("Fname"); 
                          String ln= obj.getString("Lname"); 
                         String em= obj.getString("email"); 
                          String ph= obj.getString("phnum"); 
                          String lk= obj.getString("live"); 
                          String wr= obj.getString("work"); 
                          String de= obj.getString("describe");
                          Log.d("OUTPUT IS",fn);*/


                    fname.setText(obj.getString("Fname"));  
                    lname.setText(obj.getString("Lname"));
                    /* email.setText(em,TextView.BufferType.EDITABLE);
                     phone.setText(ph,TextView.BufferType.EDITABLE);
                     live.setText(lk,TextView.BufferType.EDITABLE);
                     work.setText(wr,TextView.BufferType.EDITABLE);
                     desc.setText(de,TextView.BufferType.EDITABLE);*/




                          // 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) {
                  String TAG="";
                VolleyLog.d(TAG, "Error: " + error.getMessage());

              }
          });

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

这里是logcat错误

10-29 08:21:34.953: D/(3631): [{"work":"software","id":76,"username":"admin123","phnum":"90000000000","image_src":"http:\/\/demo.cogzidel.com\/dropinn\/images\/no_avatar.jpg","email":"admin@gmail.com","Fname":"admin","describe":"developer","Lname":"admin123","live":"chennai"}]
10-29 08:21:34.953: D/OUTPUT IS(3631): admin
10-29 08:21:34.953: D/AndroidRuntime(3631): Shutting down VM
10-29 08:21:34.953: W/dalvikvm(3631): threadid=1: thread exiting with uncaught exception (group=0xb0d0cb20)
10-29 08:21:34.953: E/AndroidRuntime(3631): FATAL EXCEPTION: main
10-29 08:21:34.953: E/AndroidRuntime(3631): Process: info.androidhive.customlistviewvolley, PID: 3631
10-29 08:21:34.953: E/AndroidRuntime(3631): java.lang.NullPointerException
10-29 08:21:34.953: E/AndroidRuntime(3631):     at com.example.dropinnnow.Editprofile$6.onResponse(Editprofile.java:690)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at com.example.dropinnnow.Editprofile$6.onResponse(Editprofile.java:1)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at android.os.Handler.handleCallback(Handler.java:733)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at android.os.Handler.dispatchMessage(Handler.java:95)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at android.os.Looper.loop(Looper.java:136)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at android.app.ActivityThread.main(ActivityThread.java:5017)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at java.lang.reflect.Method.invokeNative(Native Method)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at java.lang.reflect.Method.invoke(Method.java:515)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-29 08:21:34.953: E/AndroidRuntime(3631):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

试试这个,希望它可以帮到你,

fname.setText(obj.getString("Fname").toString());  
lname.setText(obj.getString("Lname").toString());