作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我使用的代码,但是当我进入页面时,它会自动停止。我使用了 volley request 对象,它也不支持 facebook 登录。我已将自定义 ListView 山谷用于网络服务。
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)
最佳答案
试试这个,希望对你有帮助
fname.setText(obj.getString("Fname").toString());
lname.setText(obj.getString("Lname").toString());
关于java - 如何从 JSON 数据在编辑文本字段中设置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26622772/
我是一名优秀的程序员,十分优秀!