0

I am new to android, i am trying to retrieve data from mysql database to android text field.when i add the below line to my java file

JSONObject json = jsonParser.makeHttpRequest(
                url_product_detials, "GET", params);

it shows the error. if i remove the above (jsonParser.makeHttpRequest) line it works fine. the error i got in log files are,

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

I have initialized url_product_detials as

private static final String url_product_detials = "http://localhost/connection/ggg.php";
2
  • 1
    It's telling you that nothing is being returned from that URL Commented Jan 2, 2014 at 6:01
  • can you put your complete code over here Commented Jan 2, 2014 at 6:20

1 Answer 1

1

In android localhost stands for the device/emulator . If you want to connect to your computer/local machine use IP 10.0.2.2

Change private static final String url_product_detials = "http://localhost/connection/ggg.php";

to private static final String url_product_detials = "http://10.0.2.2/connection/ggg.php";

Sign up to request clarification or add additional context in comments.

1 Comment

I'd recommend to use the host as a preference variable. If you ever want to install the app on a phone, the 10.0.2.2 or localhost won't work. Using a preference to change the hostname of the server should be the prefered way to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.