次のコードにAsyncTaskを(正常に)追加する方法を知りたいのですが。私はすでにAsyncTaskを実装しました(私の知る限り、ネット上で見つけた情報を使用して)が、クラッシュし続け、正確な理由はわかりません...どんな助けでも大歓迎です!
JAVA:
import org.json.JSONException;
import org.json.JSONObject;
import com.nfc.linked.DatabaseHandler;
import com.nfc.linked.UserFunctions;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class RegisterActivity extends Activity {
Button btnRegister;
Button btnLinkToLogin;
EditText inputFullName;
EditText inputEmail;
EditText inputPassword;
TextView registerErrorMsg;
// JSON Response node names
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
private static String KEY_UID = "uid";
private static String KEY_NAME = "name";
private static String KEY_EMAIL = "email";
private static String KEY_CREATED_AT = "created_at";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
private class RegisterActivity extends AsyncTask<string, jsonobject="" string,=""> {
@Override
protected JSONObject doInBackground(linkingmanager.comze.com) {
}
// Importing all assets like buttons, text fields
inputFullName = (EditText) findViewById(R.id.registerName);
inputEmail = (EditText) findViewById(R.id.registerEmail);
inputPassword = (EditText) findViewById(R.id.registerPassword);
btnRegister = (Button) findViewById(R.id.btnRegister);
btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);
registerErrorMsg = (TextView) findViewById(R.id.register_error);
// Register Button Click event
btnRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String name = inputFullName.getText().toString();
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.registerUser(name, email, password);
// check for login response
try {
if (json.getString(KEY_SUCCESS) != null) {
registerErrorMsg.setText("");
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
// user successfully registred
// 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));
// Launch Dashboard Screen
Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.class);
// Close all views before launching Dashboard
dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(dashboard);
// Close Registration Screen
finish();
}else{
// Error in registration
registerErrorMsg.setText("Error occured in registration");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
// Link to Login Screen
btnLinkToLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(i);
// Close Registration View
finish();
}
});
}
LOGCAT:
03-16 21:55:23.746: D/AndroidRuntime(483): Shutting down VM
03-16 21:55:23.746: W/dalvikvm(483): threadid=1: thread exiting with uncaught exception (group=0x41604930)
03-16 21:55:23.746: E/AndroidRuntime(483): FATAL EXCEPTION: main
03-16 21:55:23.746: E/AndroidRuntime(483): java.lang.Error: Unresolved compilation problems:
03-16 21:55:23.746: E/AndroidRuntime(483): Syntax error, insert "}" to complete ClassBody
03-16 21:55:23.746: E/AndroidRuntime(483): Syntax error on token(s), misplaced construct(s)
03-16 21:55:23.746: E/AndroidRuntime(483): The nested type RegisterActivity cannot hide an enclosing type
03-16 21:55:23.746: E/AndroidRuntime(483): Illegal modifier for the local class RegisterActivity; only abstract or final is permitted
03-16 21:55:23.746: E/AndroidRuntime(483): Syntax error on token(s), misplaced construct(s)
03-16 21:55:23.746: E/AndroidRuntime(483): Syntax error on token """", { expected
03-16 21:55:23.746: E/AndroidRuntime(483): Syntax error on token "=", delete this token
03-16 21:55:23.746: E/AndroidRuntime(483): Syntax error on tokens, delete these tokens
03-16 21:55:23.746: E/AndroidRuntime(483): The method doInBackground() of type RegisterActivity must override or implement a supertype method
03-16 21:55:23.746: E/AndroidRuntime(483): at com.nfc.linked.RegisterActivity.<init>(RegisterActivity.java:34)
03-16 21:55:23.746: E/AndroidRuntime(483): at java.lang.Class.newInstanceImpl(Native Method)
03-16 21:55:23.746: E/AndroidRuntime(483): at java.lang.Class.newInstance(Class.java:1319)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.os.Handler.dispatchMessage(Handler.java:99)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.os.Looper.loop(Looper.java:137)
03-16 21:55:23.746: E/AndroidRuntime(483): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-16 21:55:23.746: E/AndroidRuntime(483): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 21:55:23.746: E/AndroidRuntime(483): at java.lang.reflect.Method.invoke(Method.java:511)
03-16 21:55:23.746: E/AndroidRuntime(483): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-16 21:55:23.746: E/AndroidRuntime(483): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-16 21:55:23.746: E/AndroidRuntime(483): at dalvik.system.NativeStart.main(Native Method)
03-16 21:55:26.296: I/Process(483): Sending signal. PID: 483 SIG: 9