简体   繁体   English

Android应用程序崩溃数据库

[英]Android App Crashes Database

Me and my friend are trying to develop an app where it interacts with the database, basically adding deleting the items from the cart. 我和我的朋友正在尝试开发一个与数据库交互的应用程序,基本上是从购物车中删除商品。 We have a problem with the database connection with the app, I guess. 我想我们与该应用程序的数据库连接存在问题。

For now, we are actually using the following tutorial to develop the app with php and mysql: http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ 目前,我们实际上是在使用以下教程来使用php和mysql开发应用程序: http : //www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

I am hosting the files from the 000webhost.com with the php files on it and a database named "Products" to send the data to from the app. 我托管了来自000webhost.com的文件以及上面的php文件以及一个名为“产品”的数据库,用于将数据发送至该应用程序。

Everything we did, is same as explained in the tutorial, but instead of the url within the application for the php files, I've mentioned my domainname from the 000webhost.com where the files are resided. 我们所做的一切与本教程中说明的相同,但是我提到的是文件所在的000webhost.com的域名,而不是php文件应用程序中的url。 But, the app crashes and exits. 但是,该应用程序崩溃并退出。 Tried several urls and even from the localhost (XAMP), we still clueless. 尝试了几个URL,甚至尝试了来自localhost(XAMP)的URL,我们仍然一无所知。

I am thankful in advance for any suggestions and solutions to this issue! 提前感谢您对这个问题的任何建议和解决方案!

Thank you! 谢谢!

Below is the logcat I got from the Eclipse after running the application: 以下是运行该应用程序后从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)

you have problem with your web API response 您的Web API响应有问题

see the error log says 看到错误日志说

>  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

now since you are not getting a proper JSON from the URL, JSONObject json is getting null and then the code furthur goes down and throws null pointer exception mostly in (as per the sample code in the url you have given) 现在,由于您没有从URL获得正确的JSON,因此JSONObject json将变为null,然后代码furthur下降并主要在其中抛出null指针异常(根据您提供的url中的示例代码)

int success = json.getInt(TAG_SUCCESS);

log corresponding to it gives the line number as well. 与之对应的日志也给出了行号。 you can double check it in your code(AllProductsActivity.java line num 130) 您可以在代码中再次检查它(AllProductsActivity.java行号130)

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):由以下原因引起:java.lang.NullPointerException 11-03 18:21:25.950:E / AndroidRuntime(917):在com.example.database.AllProductsActivity $ LoadAllProducts .doInBackground(AllProductsActivity.java:130)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM