これは私が試したものです、
JSONObject jsonObject;
JSONParser jParser = new JSONParser();
jsonObject = jParser.getJSONFromUrl("http://shoppersays.com/mypromocheck/api/v1/users?&username=avinash&password=avinash2");
try {
String Authen_status = jsonObject.getString("Authen_status");
Toast.makeText(getApplicationContext(), Authen_status, Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Unable to connect", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
しかし、私はNullPointerException
. 私はこれをAndroid 2.2で実行し、正常に実行された後、4.0で試してみました。行にヌルポインタ例外が発生しましたgetstring()
。助けてください!!
編集1:
ログ
03-28 23:46:52.641: E/AndroidRuntime(1694): FATAL EXCEPTION: main
03-28 23:46:52.641: E/AndroidRuntime(1694): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.viralmo.readjson/com.viralmo.readjson.ReadJson}: java.lang.NullPointerException
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.ActivityThread.access$600(ActivityThread.java:122)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.os.Looper.loop(Looper.java:137)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-28 23:46:52.641: E/AndroidRuntime(1694): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 23:46:52.641: E/AndroidRuntime(1694): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 23:46:52.641: E/AndroidRuntime(1694): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-28 23:46:52.641: E/AndroidRuntime(1694): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-28 23:46:52.641: E/AndroidRuntime(1694): at dalvik.system.NativeStart.main(Native Method)
03-28 23:46:52.641: E/AndroidRuntime(1694): Caused by: java.lang.NullPointerException
03-28 23:46:52.641: E/AndroidRuntime(1694): at com.viralmo.readjson.ReadJson.onCreate(ReadJson.java:23)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.Activity.performCreate(Activity.java:4465)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-28 23:46:52.641: E/AndroidRuntime(1694): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
03-28 23:46:52.641: E/AndroidRuntime(1694): ... 11 more