我正在尝试注册我的用户并且标签说成功。但我有一个错误,我不知道问题出在哪里。
这是我的代码:
// Registration in background
protected String doInBackground(String... params) {
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.registerUser(name, email, password);
try {
String resu = json.getString(KEY_ERROR);
if (Integer.parseInt(resu) == 3) {
usernameExist = true;
} else if (json.getString(KEY_SUCCESS) != null) {
String res = json.getString(KEY_SUCCESS);
if (Integer.parseInt(res) == 1) {
registered = true;
// user successfully registered
// Store user details in SQLite
// Database
DatabaseHandler db = new DatabaseHandler(
getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
// Clear all previous data in
// database
userFunction.logoutUser(getApplicationContext());
db.addUser(json_user.getString(KEY_NAME),
json_user.getString(KEY_EMAIL),
json.getString(KEY_UID),
json_user.getString(KEY_CREATED_AT));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
// After completing background task Dismiss the progress dialog
protected void onPostExecute(String file_url) {
if (usernameExist == true) {
registerErrorMsg.setText("Username already existed");
} else if (registered == true) {
registerErrorMsg.setText("");
Intent homepage = new Intent(getApplicationContext(),
RegisterSuccessActivity.class);
homepage.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homepage);
finish();
} else {
// Error in registration
registerErrorMsg.setText("Email address already existed");
}
// dismiss the dialog once done
pDialog.dismiss();
}
这是我的日志:
09-13 13:39:45.455: E/JSON(868): {"tag":"register","success":1,"error":0,"uid":"5051e1dac29176.90742708","user":{"name":"user","email":"user@gmail.com","created_at":"2012-09-13 21:38:34","updated_at":null}}
09-13 13:39:46.225: E/AndroidRuntime(868): FATAL EXCEPTION: AsyncTask #2
09-13 13:39:46.225: E/AndroidRuntime(868): java.lang.RuntimeException: An error occured while executing doInBackground()
09-13 13:39:46.225: E/AndroidRuntime(868): at android.os.AsyncTask$3.done(AsyncTask.java:278)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-13 13:39:46.225: E/AndroidRuntime(868): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.lang.Thread.run(Thread.java:856)
09-13 13:39:46.225: E/AndroidRuntime(868): Caused by: android.database.sqlite.SQLiteException: Can't downgrade database from version 2 to 1
09-13 13:39:46.225: E/AndroidRuntime(868): at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:307)
09-13 13:39:46.225: E/AndroidRuntime(868): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:168)
09-13 13:39:46.225: E/AndroidRuntime(868): at com.stts.sparetimetradingsystem.library.DatabaseHandler.addUser(DatabaseHandler.java:60)
09-13 13:39:46.225: E/AndroidRuntime(868): at com.stts.sparetimetradingsystem.RegisterActivity$Register.doInBackground(RegisterActivity.java:150)
09-13 13:39:46.225: E/AndroidRuntime(868): at com.stts.sparetimetradingsystem.RegisterActivity$Register.doInBackground(RegisterActivity.java:1)
09-13 13:39:46.225: E/AndroidRuntime(868): at android.os.AsyncTask$2.call(AsyncTask.java:264)
09-13 13:39:46.225: E/AndroidRuntime(868): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-13 13:39:46.225: E/AndroidRuntime(868): ... 5 more
有人可以教我让我学习吗?谢谢!