から値をフェッチしている間、私は、データベースから値を取得しようとしていますし、私はこれによるこのエラーを見ることができますフェッチしている間に、私の値は私の活動にデータベース
FATAL EXCEPTION: main
java.lang.NullPointerException
at java.util.Arrays$ArrayList.<init>(Arrays.java:38)
at java.util.Arrays.asList(Arrays.java:154)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:128)
at com.weavearound.schools.weavearound.CustomList.<init>(CustomList.java:21)
at com.weavearound.schools.weavearound.events.showJSON(events.java:61)
at com.weavearound.schools.weavearound.events.access$000(events.java:17)
at com.weavearound.schools.weavearound.events$1.onResponse(events.java:44)
at com.weavearound.schools.weavearound.events$1.onResponse(events.java:41)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:67)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
マイCustomListが表示されていないエラーを取得していますコード:
public class CustomList extends ArrayAdapter<String> {
private String[] ids;
private String[] names;
//private String[] emails;
private Activity context;
public CustomList(Activity context, String[] ids, String[] names) {
super(context, R.layout.list_view_layout,ids);
this.context = context;
this.ids = ids;
this.names= names;
// this.emails = emails;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.list_view_layout, null, true);
TextView textViewId = (TextView) listViewItem.findViewById(R.id.textViewId);
TextView textViewName = (TextView) listViewItem.findViewById(R.id.textViewName);
//TextView textViewEmail = (TextView) listViewItem.findViewById(R.id.textViewEmail);
textViewId.setText(ids[position]);
textViewName.setText(names[position]);
// textViewEmail.setText(emails[position]);
return listViewItem;
}
}
そして、ここでフェッチ値:
ます。private voidのsendRequest(){
StringRequest stringRequest = new StringRequest(JSON_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(events.this,error.getMessage(),Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void showJSON(String json){
ParseJSON pj = new ParseJSON(json);
pj.parseJSON();
CustomList cl = new CustomList(this, ParseJSON.ids, ParseJSON.names);
listView.setAdapter(cl);
}
ParseJSONクラス:
public ParseJSON(String json){
this.json = json;
}
protected void parseJSON(){
JSONObject jsonObject=null;
try {
jsonObject = new JSONObject(json);
users = jsonObject.getJSONArray(JSON_ARRAY);
ids = new String[users.length()];
names = new String[users.length()];
//emails = new String[users.length()];
for(int i=0;i<users.length();i++){
JSONObject jo = users.getJSONObject(i);
ids[i] = jo.getString(KEY_ID);
names[i] = jo.getString(KEY_NAME);
//emails[i] = jo.getString(KEY_EMAIL);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
コードスニペットを投稿できますか? – Chol
コードスニペットを提供していない場合は誰でもこのエラーが発生しますか? –
私はJSONを知らないが、CustomListであるべきではない。cl = new CustomList(this、pj.ids、pj.names); ?? – Chol