2013-11-26 79 views
0

从logcat的:应用程序崩溃将下一个页面时(意向)

11-25 18:49:03.244: D/gralloc_goldfish(1269): Emulator without GPU emulation detected. 
11-25 18:49:13.403: D/AndroidRuntime(1269): Shutting down VM 
11-25 18:49:13.403: W/dalvikvm(1269): threadid=1: thread exiting with uncaught exception (group=0x41465700) 
11-25 18:49:13.643: D/dalvikvm(1269): GC_FOR_ALLOC freed 97K, 7% free 2921K/3136K, paused 65ms, total 84ms 
11-25 18:49:13.643: E/AndroidRuntime(1269): FATAL EXCEPTION: main 
11-25 18:49:13.643: E/AndroidRuntime(1269): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sqlassignmentb/com.example.sqlassignmentb.SignUpActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.os.Handler.dispatchMessage(Handler.java:99) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.os.Looper.loop(Looper.java:137) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.ActivityThread.main(ActivityThread.java:5103) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at java.lang.reflect.Method.invoke(Method.java:525) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at dalvik.system.NativeStart.main(Native Method) 
11-25 18:49:13.643: E/AndroidRuntime(1269): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at com.example.sqlassignmentb.SignUpActivity.onCreate(SignUpActivity.java:27) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.Activity.performCreate(Activity.java:5133) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 
11-25 18:49:13.643: E/AndroidRuntime(1269):  ... 11 more 

LoginActivity.java - 几乎什么都不做,现在,除了它应该带我去注册页面

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class LoginActivity extends Activity implements OnClickListener { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login); 

    Button signUpButton = (Button) findViewById(R.id.buttonSignUp); 
    signUpButton.setOnClickListener(this); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.login, menu); 
    return true; 
} 

@Override 
public void onClick(View arg0) { 
    Intent signupPage = new Intent(LoginActivity.this, SignUpActivity.class); 
    startActivity(signupPage); 

} 

} 

最后是注册页面。

import android.content.Intent; 

import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class SignUpActivity extends LoginActivity implements OnClickListener { 
Button back; 
Button create; 
TextView message; 

EditText username; 
EditText firstname; 
EditText lastname; 
EditText password; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.signup); 
    // Text Fields 
    username = (EditText) findViewById(R.id.textViewSignUpUsername); 
    firstname = (EditText) findViewById(R.id.editTextSignUpFirstName); 
    lastname = (EditText) findViewById(R.id.editTextSignUpLastName); 
    password = (EditText) findViewById(R.id.editTextSignUpUsername); 
    // Buttons 
    back = (Button) findViewById(R.id.buttonBack); 
    create = (Button) findViewById(R.id.buttonSignUpButtonCreate); 
    // Message to display if user is created or not 
    message = (TextView) findViewById(R.id.textViewMessage); 
    // Button listeners 
    back.setOnClickListener(this); 
    create.setOnClickListener(this); 

} 

@Override 
public void onClick(View v) { 

    switch (v.getId()) { 
    case R.id.buttonBack: 
     Intent homepage = new Intent(SignUpActivity.this, 
       LoginActivity.class); 
     startActivity(homepage); 

     break; 
    case R.id.buttonSignUpButtonCreate: 
     if (username.getText().length() == 0 
       || firstname.getText().length() == 0 
       || lastname.getText().length() == 0 
       || password.getText().length() == 0) { 
      message.setText("Error. User not created. Please make sure all fields are filled in. "); 
     } else { 

      message.setText("User Created."); 
     } 

     break; 

    } 
} 


} 

从我可以从日志猫则说明它是混合/混乱的TextView和EditText上的东西

回答

1

通过你的命名约定明白,我将承担这一行是罪魁祸首:

username = (EditText) findViewById(R.id.textViewSignUpUsername); 

我会想象textViewSignUpUsername实际上是一个TextView,而不是EditText

+0

谢谢。这是问题所在 – user1570011

相关问题