我是android的新手,我正在尝试将数据从mysql数据库检索到android文本字段。当我将以下行添加到我的java文件
JSONObject json = jsonParser.makeHttpRequest(
url_product_detials, "GET", params);
它显示错误。如果我删除上面的(jsonParser.makeHttpRequest)行,它工作正常。我在日志文件中得到的错误是,
01-02 11:16:50.418: W/System.err(968): ... 17 more
01-02 11:16:50.418: E/Buffer Error(968): Error converting result java.lang.NullPointerException
01-02 11:16:50.418: E/JSON Parser(968): Error parsing data org.json.JSONException: End of input at character 0 of
01-02 11:16:50.428: D/AndroidRuntime(968): Shutting down VM
01-02 11:16:50.428: W/dalvikvm(968): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-02 11:16:50.428: E/AndroidRuntime(968): FATAL EXCEPTION: main
01-02 11:16:50.428: E/AndroidRuntime(968): java.lang.NullPointerException
01-02 11:16:50.428: E/AndroidRuntime(968): at com.example.matrixarc.Syl$GetProductDetails$1.run(Syl.java:153)
01-02 11:16:50.428: E/AndroidRuntime(968): at android.os.Handler.handleCallback(Handler.java:587)
01-02 11:16:50.428: E/AndroidRuntime(968): at android.os.Handler.dispatchMessage(Handler.java:92)
01-02 11:16:50.428: E/AndroidRuntime(968): at android.os.Looper.loop(Looper.java:130)
01-02 11:16:50.428: E/AndroidRuntime(968): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-02 11:16:50.428: E/AndroidRuntime(968): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 11:16:50.428: E/AndroidRuntime(968): at java.lang.reflect.Method.invoke(Method.java:507)
01-02 11:16:50.428: E/AndroidRuntime(968): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-02 11:16:50.428: E/AndroidRuntime(968): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-02 11:16:50.428: E/AndroidRuntime(968): at dalvik.system.NativeStart.main(Native Method)
01-02 11:16:52.808: I/Process(968): Sending signal. PID: 968 SIG: 9
我初始化了url_product_detials 为
private static final String url_product_detials = "http://localhost/connection/ggg.php";
答案 0 :(得分:1)
在android localhost
中代表设备/模拟器。如果要连接到计算机/本地计算机,请使用IP 10.0.2.2
更改private static final String url_product_detials = "http://localhost/connection/ggg.php";
到private static final String url_product_detials = "http://10.0.2.2/connection/ggg.php";