2

应用代码来源http ://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

我在我的 samsung s2 和 android 2.2 模拟器上运行应用程序,在我使用随机用户名和密码登录后都被迫关闭。在我尝试注册后它也会强制关闭。

logcat(详细):

02-21 03:09:15.800: W/KeyCharacterMap(563): No keyboard for id 0
02-21 03:09:15.800: W/KeyCharacterMap(563): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
02-21 03:09:23.480: D/Button(563): Login
02-21 03:09:23.829: E/JSON(563): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
02-21 03:09:23.829: E/JSON(563): <html><head>
02-21 03:09:23.829: E/JSON(563): <title>404 Not Found</title>
02-21 03:09:23.829: E/JSON(563): </head><body>
02-21 03:09:23.829: E/JSON(563): <h1>Not Found</h1>
02-21 03:09:23.829: E/JSON(563): <p>The requested URL /android_login_api/ was not found on this server.</p>
02-21 03:09:23.829: E/JSON(563): </body></html>
02-21 03:09:23.829: E/JSON Parser(563): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
02-21 03:09:23.829: D/AndroidRuntime(563): Shutting down VM
02-21 03:09:23.829: W/dalvikvm(563): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-21 03:09:23.849: E/AndroidRuntime(563): FATAL EXCEPTION: main
02-21 03:09:23.849: E/AndroidRuntime(563): java.lang.NullPointerException
02-21 03:09:23.849: E/AndroidRuntime(563):  at com.example.androidhive.LoginActivity$1.onClick(LoginActivity.java:65)
02-21 03:09:23.849: E/AndroidRuntime(563):  at android.view.View.performClick(View.java:2408)
02-21 03:09:23.849: E/AndroidRuntime(563):  at android.view.View$PerformClick.run(View.java:8816)
02-21 03:09:23.849: E/AndroidRuntime(563):  at android.os.Handler.handleCallback(Handler.java:587)
02-21 03:09:23.849: E/AndroidRuntime(563):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 03:09:23.849: E/AndroidRuntime(563):  at android.os.Looper.loop(Looper.java:123)
02-21 03:09:23.849: E/AndroidRuntime(563):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-21 03:09:23.849: E/AndroidRuntime(563):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 03:09:23.849: E/AndroidRuntime(563):  at java.lang.reflect.Method.invoke(Method.java:521)
02-21 03:09:23.849: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-21 03:09:23.849: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-21 03:09:23.849: E/AndroidRuntime(563):  at dalvik.system.NativeStart.main(Native Method)
02-21 03:14:23.920: I/Process(563): Sending signal. PID: 563 SIG: 9
02-21 03:49:40.550: W/KeyCharacterMap(600): No keyboard for id 0
02-21 03:49:40.550: W/KeyCharacterMap(600): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
02-21 03:49:45.180: D/Button(600): Login
02-21 03:49:46.750: E/JSON(600): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
02-21 03:49:46.750: E/JSON(600): <html><head>
02-21 03:49:46.750: E/JSON(600): <title>404 Not Found</title>
02-21 03:49:46.750: E/JSON(600): </head><body>
02-21 03:49:46.750: E/JSON(600): <h1>Not Found</h1>
02-21 03:49:46.750: E/JSON(600): <p>The requested URL /android_login_api/ was not found on this server.</p>
02-21 03:49:46.750: E/JSON(600): </body></html>
02-21 03:49:46.750: E/JSON Parser(600): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
02-21 03:49:46.750: D/AndroidRuntime(600): Shutting down VM
02-21 03:49:46.760: W/dalvikvm(600): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-21 03:49:46.760: E/AndroidRuntime(600): FATAL EXCEPTION: main
02-21 03:49:46.760: E/AndroidRuntime(600): java.lang.NullPointerException
02-21 03:49:46.760: E/AndroidRuntime(600):  at com.example.androidhive.LoginActivity$1.onClick(LoginActivity.java:65)
02-21 03:49:46.760: E/AndroidRuntime(600):  at android.view.View.performClick(View.java:2408)
02-21 03:49:46.760: E/AndroidRuntime(600):  at android.view.View$PerformClick.run(View.java:8816)
02-21 03:49:46.760: E/AndroidRuntime(600):  at android.os.Handler.handleCallback(Handler.java:587)
02-21 03:49:46.760: E/AndroidRuntime(600):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 03:49:46.760: E/AndroidRuntime(600):  at android.os.Looper.loop(Looper.java:123)
02-21 03:49:46.760: E/AndroidRuntime(600):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-21 03:49:46.760: E/AndroidRuntime(600):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 03:49:46.760: E/AndroidRuntime(600):  at java.lang.reflect.Method.invoke(Method.java:521)
02-21 03:49:46.760: E/AndroidRuntime(600):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-21 03:49:46.760: E/AndroidRuntime(600):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-21 03:49:46.760: E/AndroidRuntime(600):  at dalvik.system.NativeStart.main(Native Method)
02-21 03:49:46.840: D/dalvikvm(600): GC_FOR_MALLOC freed 3724 objects / 212248 bytes in 76ms
02-21 03:49:52.790: I/Process(600): Sending signal. PID: 600 SIG: 9
02-21 03:51:55.399: W/KeyCharacterMap(748): No keyboard for id 0
02-21 03:51:55.399: W/KeyCharacterMap(748): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
02-21 03:52:03.429: D/Button(748): Login
02-21 03:52:03.759: E/JSON(748): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
02-21 03:52:03.759: E/JSON(748): <html><head>
02-21 03:52:03.759: E/JSON(748): <title>404 Not Found</title>
02-21 03:52:03.759: E/JSON(748): </head><body>
02-21 03:52:03.759: E/JSON(748): <h1>Not Found</h1>
02-21 03:52:03.759: E/JSON(748): <p>The requested URL /android_login_api/ was not found on this server.</p>
02-21 03:52:03.759: E/JSON(748): </body></html>
02-21 03:52:03.770: E/JSON Parser(748): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
02-21 03:52:03.770: D/AndroidRuntime(748): Shutting down VM
02-21 03:52:03.770: W/dalvikvm(748): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-21 03:52:03.779: E/AndroidRuntime(748): FATAL EXCEPTION: main
02-21 03:52:03.779: E/AndroidRuntime(748): java.lang.NullPointerException
02-21 03:52:03.779: E/AndroidRuntime(748):  at com.example.androidhive.LoginActivity$1.onClick(LoginActivity.java:65)
02-21 03:52:03.779: E/AndroidRuntime(748):  at android.view.View.performClick(View.java:2408)
02-21 03:52:03.779: E/AndroidRuntime(748):  at android.view.View$PerformClick.run(View.java:8816)
02-21 03:52:03.779: E/AndroidRuntime(748):  at android.os.Handler.handleCallback(Handler.java:587)
02-21 03:52:03.779: E/AndroidRuntime(748):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 03:52:03.779: E/AndroidRuntime(748):  at android.os.Looper.loop(Looper.java:123)
02-21 03:52:03.779: E/AndroidRuntime(748):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-21 03:52:03.779: E/AndroidRuntime(748):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 03:52:03.779: E/AndroidRuntime(748):  at java.lang.reflect.Method.invoke(Method.java:521)
02-21 03:52:03.779: E/AndroidRuntime(748):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-21 03:52:03.779: E/AndroidRuntime(748):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-21 03:52:03.779: E/AndroidRuntime(748):  at dalvik.system.NativeStart.main(Native Method)
02-21 03:52:03.869: D/dalvikvm(748): GC_FOR_MALLOC freed 3885 objects / 218072 bytes in 88ms
02-21 03:57:03.939: I/Process(748): Sending signal. PID: 748 SIG: 9

我的数据库名称是 android_api,我使用 WAMP 服务器就像 androidhive 所做的一样。Androidhive 使用以下代码:

private static String loginURL = "http://10.0.2.2/ah_login_api/";
private static String registerURL = "http://10.0.2.2/ah_login_api/";

但我用这个:

private static String loginURL = "http://10.0.2.2/android_login_api/";
private static String registerURL = "http://10.0.2.2/android_login_api/";

我也试试这个:

private static String loginURL = "http://10.0.2.2/android_api/";
private static String registerURL = "http://10.0.2.2/android_api/";

我尝试了上面的 3 个 URL,但都不起作用。

我也对config.php感到好奇:

<?php

define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_DATABASE", "android_api");
?>

我应该就这样离开 DB_PASSWORD 吗?因为我不知道/没有密码。

我在 android 2.2 模拟器上成功运行了这个应用程序http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ 。

但是这个登录和注册应用程序出现问题。

这是我第一次开发android项目,希望有专业人士可以帮助我解决这个问题。我整整两天都在努力解决这个问题,但什么也没有。

我多次检查每个代码,但我不知道强制关闭的原因。

请指导并告诉我真相。 *谢谢*

4

1 回答 1

1

谢谢kishu27!你让我专注于 URL,最后我找到了解决方案。

正确的网址是"http://10.0.2.2/android_api/index.php"

因为在 android_api 的文件夹中有另一个名为“include”和 index.php 的文件夹。我必须先连接到 index.php 才能登录和注册

我现在超级开心!!

于 2013-02-21T10:17:37.707 回答