Reputation: 1367
This is similar to app crashes on JSON jparser make http request
After I made the app, I replaced the URL lines with
private static String url_all_products = "http://192.168.0.101:80/android_connect/get_all_products.php";
When i run the above url on my browser, I get a message saying that a method has been depracated, followed by a JSON object(I manually inserted a row)
However, when i run the app on my device, it crashes after i press the view products button
01-12 23:39:10.508 3681-3789/com.example.androidhive E/JSON Parser: Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject 01-12 23:39:10.510 3681-3789/com.example.androidhive E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
Process: com.example.androidhive, PID: 3681
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:130)
at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:105)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818) 01-12 23:39:10.510 3681-3681/com.example.androidhive D/AbstractTracker: Event success 01-12 23:39:10.511 3681-3789/com.example.androidhive E/AndroidRuntime: Error reporting crash
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.content.AsyncQueryHandler.<init>(AsyncQueryHandler.java:125)
at net.oneplus.odm.insight.tracker.AbstractTracker$TrackerAsyncQueryHandler.<init>(AbstractTracker.java:108)
at net.oneplus.odm.insight.tracker.AbstractTracker.<init>(AbstractTracker.java:60)
at net.oneplus.odm.insight.tracker.AppTracker.<init>(AppTracker.java:24)
at
com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:97)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) 01-12 23:39:10.511 3681-3789/com.example.androidhive I/Process: Sending signal. PID: 3681 SIG: 9
The NullPointerException
makes me believe that no JSON object is being returned, but I can see a JSON object when i run the url on my pc.
Upvotes: 0
Views: 118
Reputation: 2202
You're using deprecated php code and that generates a table inside your browser page saying that it's deprecated, and when you parse that page "with the table" means that you get not only the json but also html table contents and that cannot be parsed to json that's why you get an exception. I suggest following this w3schools tutorial on how to connect to mysql with non deprecated code.
Upvotes: 1