我正在使用http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/ 。我在这里用 JSON 标记面临几个问题。我不知道现在该怎么办。我想补充一点,我的本地主机是 ar 端口 81。我只是分别更改了登录和注册 url 中的 localhost:81/android_login_api/ 和 localhost:81/android_login_api/ 。这是我的 logcat 错误-
02-24 11:17:58.000: E/JSON(1364): <br />
02-24 11:17:58.000: E/JSON(1364): <b>Parse error</b>: syntax error, unexpected $end in <b>C:\xampp\htdocs\android_login_api\include\DB_Connect.php</b> on line <b>46</b><br />
02-24 11:17:58.011: E/JSON Parser(1364): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
02-24 11:17:58.011: D/AndroidRuntime(1364): Shutting down VM
02-24 11:17:58.011: W/dalvikvm(1364): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-24 11:17:58.030: E/AndroidRuntime(1364): FATAL EXCEPTION: main
02-24 11:17:58.030: E/AndroidRuntime(1364): java.lang.NullPointerException
02-24 11:17:58.030: E/AndroidRuntime(1364): at com.example.androidhive.RegisterActivity$1.onClick(RegisterActivity.java:64)
02-24 11:17:58.030: E/AndroidRuntime(1364): at android.view.View.performClick(View.java:4202)
02-24 11:17:58.030: E/AndroidRuntime(1364): at android.view.View$PerformClick.run(View.java:17340)
02-24 11:17:58.030: E/AndroidRuntime(1364): at android.os.Handler.handleCallback(Handler.java:725)
02-24 11:17:58.030: E/AndroidRuntime(1364): at android.os.Handler.dispatchMessage(Handler.java:92)
02-24 11:17:58.030: E/AndroidRuntime(1364): at android.os.Looper.loop(Looper.java:137)
02-24 11:17:58.030: E/AndroidRuntime(1364): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-24 11:17:58.030: E/AndroidRuntime(1364): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 11:17:58.030: E/AndroidRuntime(1364): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 11:17:58.030: E/AndroidRuntime(1364): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-24 11:17:58.030: E/AndroidRuntime(1364): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-24 11:17:58.030: E/AndroidRuntime(1364): at dalvik.system.NativeStart.main(Native Method)
这是我的 php 代码——
<?php
class DB_Connect {
// constructor
function __construct() {
$sql = "CREATE TABLE IF NOT EXISTS users(
uid int(11) primary key auto_increment,
unique_id varchar(23) not null unique,
name varchar(50) not null,
email varchar(100) not null unique,
encrypted_password varchar(80) not null,
salt varchar(10) not null,
created_at datetime,
updated_at datetime null
);
mysql_query($sql);
}
// destructor
function __destruct() {
// $this->close();
}
// Connecting to database
public function connect() {
require_once 'include/config.php';
// connecting to mysql
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
// selecting database
mysql_select_db(DB_DATABASE);
// return database handler
return $con;
}
// Closing database connection
public function close() {
mysql_close();
}
}
?>