2013-02-20 60 views
2

來源的應用程序代碼http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/Android的登錄和註冊使用PHP,MySQL和SQLite被迫關閉

我跑在我的三星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項目,希望有專業知識可以幫助我解決這個問題。我努力解決這整整2天,但沒有。

我檢查了每一個代碼很多次,但我不知道強制關閉的原因。

請指導並告訴我真實的。 *謝謝*

+1

你明顯得到了404。你是否嘗試在瀏覽器中打開這些URL並查看它們是否真正可訪問? – kishu27 2013-02-21 01:03:47

回答

1

謝謝kishu27!你讓我專注於URL,最後我找到了解決方案。

正確的URL是"http://10.0.2.2/android_api/index.php"

因爲android_api的文件夾中有一個名爲「包括」和index.php的另一個文件夾。 我必須首先連接到index.php登錄並註冊

我現在超級快樂!