gpt4 book ai didi

java - Android 应用程序崩溃数据库

转载 作者:搜寻专家 更新时间:2023-10-30 23:05:47 24 4
gpt4 key购买 nike

我和我的 friend 正在尝试开发一个与数据库交互的应用程序,主要是添加从购物车中删除项目。我猜我们与应用程序的数据库连接有问题。

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

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

我们所做的一切都与教程中解释的相同,但我提到了文件所在的 000webhost.com 的域名,而不是应用程序中 php 文件的 url。但是,该应用程序崩溃并退出。尝试了几个 url,甚至从本地主机 (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)

最佳答案

您的 Web 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 变为空,然后代码进一步下降并主要抛出空指针异常(根据您提供的 url 中的示例代码)

int success = json.getInt(TAG_SUCCESS);

对应的log也给出了行号。你可以在你的代码中仔细检查它(AllProductsActivity.java line num 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)

关于java - Android 应用程序崩溃数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26725177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com