画像と画像名を持つリスト ビューがあり、JSON Web サービスからデータを読み込んでリスト ビューに表示しています。
public class AndroidJSONParsingActivity extends ListActivity {
// url to make request
private static String url = "my url";
// JSON Node names
String Doctors = "Doctors";
String DoctorName = "DoctorName";
String ImageName = "ImageName";
// contacts JSONArray
JSONArray Doctor = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView image = (ImageView)findViewById(R.id.ImageView);
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
Doctor = json.getJSONArray(Doctors);
// looping through All Contacts
for(int i = 0; i < Doctor.length(); i++){
JSONObject c = Doctor.getJSONObject(i);
Log.d("TAG", "JSON IS: " + Doctor.toString());
String imageBaseDirectory = "http://92.253.101.239:81/sudandoctors/UploadedFiles/";
String imageName = c.getString(ImageName);//get image name from json parsing;
System.err.println("imageBaseDirectory = "+imageBaseDirectory);
System.err.println("imageName = "+imageName);
System.err.println("two = "+imageBaseDirectory+imageName);
image.setImageURI(Uri.parse(imageBaseDirectory+imageName));
String n = imageBaseDirectory+imageName;
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put("DoctorName", c.getString("DoctorName"));
map.put("ImageName", n);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.list_item,
new String[] { DoctorName, ImageName }, new int[] {
R.id.name, R.id.ImageView });
setListAdapter(adapter);
}
}
このエラーが発生しました
12-13 14:06:07.793: E/AndroidRuntime(1148): FATAL EXCEPTION: main
12-13 14:06:07.793: E/AndroidRuntime(1148): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.jsonparsing/com.androidhive.jsonparsing.AndroidJSONParsingActivity}: java.lang.NullPointerException
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.os.Looper.loop(Looper.java:123)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-13 14:06:07.793: E/AndroidRuntime(1148): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 14:06:07.793: E/AndroidRuntime(1148): at java.lang.reflect.Method.invoke(Method.java:507)
12-13 14:06:07.793: E/AndroidRuntime(1148): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-13 14:06:07.793: E/AndroidRuntime(1148): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-13 14:06:07.793: E/AndroidRuntime(1148): at dalvik.system.NativeStart.main(Native Method)
12-13 14:06:07.793: E/AndroidRuntime(1148): Caused by: java.lang.NullPointerException
12-13 14:06:07.793: E/AndroidRuntime(1148): at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:61)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-13 14:06:07.793: E/AndroidRuntime(1148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-13 14:06:07.793: E/AndroidRuntime(1148): ... 11 more
ブラウザでリンクを使用すると、実際に写真が表示されるので、問題は何ですか