Android应用程序崩溃数据库

时间:2014-11-03 23:27:53

标签: java android mysql database phpmyadmin

我和我的朋友正在尝试开发一个与数据库交互的应用程序,基本上是添加删除购物车中的商品。我想,我们遇到了与应用程序的数据库连接问题。

目前,我们实际上正在使用以下教程使用php和mysql开发应用程序: http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

我正在托管来自000webhost.com的文件,上面有php文件和一个名为“Products”的数据库,用于从应用程序发送数据。

我们所做的一切与教程中所解释的相同,但不是php文件的应用程序中的url,我已经提到了来自000webhost.com的文件所在的域名。但是,应用程序崩溃并退出。尝试了几个网址,甚至从本地主机(XAMP),我们仍然无能为力。

我提前感谢任何有关此问题的建议和解决方案!

谢谢!

下面是我在运行应用程序后从Eclipse获得的logcat:

    11-03 18:21:25.790: E/JSON Parser(917): Error parsing data org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject
11-03 18:21:25.950: E/AndroidRuntime(917): FATAL EXCEPTION: AsyncTask #1
11-03 18:21:25.950: E/AndroidRuntime(917): Process: com.example.database, PID: 917
11-03 18:21:25.950: E/AndroidRuntime(917): java.lang.RuntimeException: An error occured while executing doInBackground()
11-03 18:21:25.950: E/AndroidRuntime(917):  at android.os.AsyncTask$3.done(AsyncTask.java:300)
11-03 18:21:25.950: E/AndroidRuntime(917):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
11-03 18:21:25.950: E/AndroidRuntime(917):  at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
11-03 18:21:25.950: E/AndroidRuntime(917):  at java.util.concurrent.FutureTask.run(FutureTask.java:242)
11-03 18:21:25.950: E/AndroidRuntime(917):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
11-03 18:21:25.950: E/AndroidRuntime(917):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-03 18:21:25.950: E/AndroidRuntime(917):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
11-03 18:21:25.950: E/AndroidRuntime(917):  at java.lang.Thread.run(Thread.java:841)
11-03 18:21:25.950: E/AndroidRuntime(917): Caused by: java.lang.NullPointerException
11-03 18:21:25.950: E/AndroidRuntime(917):  at com.example.database.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:130)
11-03 18:21:25.950: E/AndroidRuntime(917):  at com.example.database.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
11-03 18:21:25.950: E/AndroidRuntime(917):  at android.os.AsyncTask$2.call(AsyncTask.java:288)
11-03 18:21:25.950: E/AndroidRuntime(917):  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-03 18:21:25.950: E/AndroidRuntime(917):  ... 4 more
11-03 18:21:31.810: E/WindowManager(917): android.view.WindowLeaked: Activity com.example.database.AllProductsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b4de64a0 V.E..... R.....ID 0,0-383,96} that was originally added here
11-03 18:21:31.810: E/WindowManager(917):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:348)
11-03 18:21:31.810: E/WindowManager(917):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
11-03 18:21:31.810: E/WindowManager(917):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.Dialog.show(Dialog.java:286)
11-03 18:21:31.810: E/WindowManager(917):   at com.example.database.AllProductsActivity$LoadAllProducts.onPreExecute(AllProductsActivity.java:117)
11-03 18:21:31.810: E/WindowManager(917):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
11-03 18:21:31.810: E/WindowManager(917):   at android.os.AsyncTask.execute(AsyncTask.java:535)
11-03 18:21:31.810: E/WindowManager(917):   at com.example.database.AllProductsActivity.onCreate(AllProductsActivity.java:57)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.Activity.performCreate(Activity.java:5231)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-03 18:21:31.810: E/WindowManager(917):   at android.os.Handler.dispatchMessage(Handler.java:102)
11-03 18:21:31.810: E/WindowManager(917):   at android.os.Looper.loop(Looper.java:136)
11-03 18:21:31.810: E/WindowManager(917):   at android.app.ActivityThread.main(ActivityThread.java:5017)
11-03 18:21:31.810: E/WindowManager(917):   at java.lang.reflect.Method.invokeNative(Native Method)
11-03 18:21:31.810: E/WindowManager(917):   at java.lang.reflect.Method.invoke(Method.java:515)
11-03 18:21:31.810: E/WindowManager(917):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-03 18:21:31.810: E/WindowManager(917):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-03 18:21:31.810: E/WindowManager(917):   at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

您的网络API响应存在问题

请参阅错误日志

>  11-03 18:21:25.790: E/JSON Parser(917): Error parsing data
> org.json.JSONException: Value <br><table of type java.lang.String
> cannot be converted to JSONObject

现在因为你没有从URL获得正确的JSON, JSONObject json 变为null,然后代码更低,并且主要抛出空指针异常(根据您给出的url中的示例代码)

int success = json.getInt(TAG_SUCCESS);
对应的

日志也给出了行号。您可以在代码中仔细检查它(AllProductsActivity.java第130行)

  

11-03 18:21:25.950:E / AndroidRuntime(917):引起:   java.lang.NullPointerException 11-03 18:21:25.950:   E / AndroidRuntime(917):at   com.example.database.AllProductsActivity $ LoadAllProducts.doInBackground(AllProductsActivity.java:130)