ActivityThread.performLaunchActivity(ActivityThread $ ActivityClientRecord,Intent) - 错误在哪里?

时间:2014-05-31 11:46:12

标签: java android eclipse

我的项目有点问题。 我每次使用

btnLinkToCreateSession.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(),
                   CreateSessionActivity.class);
            startActivity(i);
            finish();
        }
    });

出现错误:

" ActivityThread.performLaunchActivity(ActivityThread $ ActivityClientRecord,Intent)"

当我拿出来的时候,一切都有效了。代码中是否有任何错误,或者必须是其他地方的错误?

 btnLinkToCreateSession.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(),
                   CreateSessionActivity.class);
            startActivity(i);
            finish();
        }
    });

    // Link to Register Screen
    btnLinkToRegister.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent j = new Intent(getApplicationContext(),
                RegisterActivity.class);
            startActivity(j);
            finish();
        }
    });

编辑:+ CreateSessionActivity.java

package com.game;

import org.json.JSONException;
import org.json.JSONObject;


 import com.game.library.DatabaseHandler;
import com.game.library.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 CreateSessionActivity extends Activity {
Button btnCreateSession;
Button btnLinkToLogin;
EditText inputNameOfSession;
EditText inputUserMax;
EditText inputBetAmount;
TextView createSessionErrorMsg;

// 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_SID = "sid";
private static String KEY_SNAME = "sname";
private static String KEY_SMAX = "smax";
private static String KEY_SBET = "sbet";
private static String KEY_CREATED_AT = "created_at";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.session);

    // Importing all assets like buttons, text fields
    inputNameOfSession = (EditText) findViewById(R.id.sessionName);
    inputUserMax = (EditText) findViewById(R.id.sessionMax);
    inputBetAmount = (EditText) findViewById(R.id.sessionBet);
    btnCreateSession = (Button) findViewById(R.id.btnCreateSession);
    btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);
    createSessionErrorMsg = (TextView) findViewById(R.id.session_error);

    // Register Button Click event
    btnCreateSession.setOnClickListener(new View.OnClickListener() {            
        public void onClick(View view) {
            String sname = inputNameOfSession.getText().toString();
            String smax = inputUserMax.getText().toString();
            String sbet = inputBetAmount.getText().toString();

            UserFunctions userFunction = new UserFunctions();
            JSONObject json = userFunction.openSession(sname, smax,      sbet);

            // check for login response
            try {
                if (json.getString(KEY_SUCCESS) != null) {
                    createSessionErrorMsg.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_session_u = json.getJSONObject("session");

                        // Clear all previous data in database
                        userFunction.logoutSession(getApplicationContext());
                        db.addSession(json_session_u.getString(KEY_SNAME), json_session_u.getString(KEY_SMAX), json.getString(KEY_SBET), json_session_u.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
                        createSessionErrorMsg.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插入到这里有点麻烦:

http://androidprojekt.esy.es/android_login_api/loggo.txt

我认为我解决了它 - 它有效

    inputEmail = (EditText) findViewById(R.id.loginEmail);
    inputPassword = (EditText) findViewById(R.id.loginPassword);
    btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
    /* I had forgotten to add this: */
    btnLinkToCreateSession = (Button) findViewById(R.id.btnLinkToCreateSession);
    loginErrorMsg = (TextView) findViewById(R.id.login_error);

1 个答案:

答案 0 :(得分:0)

您应该使用活动的上下文而不是getApplicationContext()来启动活动。更改用于启动Activity的所有意图,如下所示:

Intent dashboard = new Intent(YourActivity.this, DashboardActivity.class);

您还应该阅读this帖子以获得更深入的见解。