我的按钮点击时出现了一个我从未见过的错误。按下i按钮后显示。
码
public class RegisterUser extends Activity implements OnClickListener {
EditText dispName;
EditText emailAddr;
EditText passwd;
EditText rl_name;
Button reg_btn;
Spinner ctry_spinner;
String choice;
ImageButton go_back;
Boolean check_email_exit = false;
TextView set_fail;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Firebase.setAndroidContext(this);
setContentView(R.layout.sign_up);
dispName = (EditText) findViewById(R.id.uid);
emailAddr = (EditText) findViewById(R.id.email_add);
passwd = (EditText) findViewById(R.id.pwd);
set_fail = (TextView)findViewById(R.id.fail_text);
ctry_spinner = (Spinner) findViewById(R.id.country_sel);
reg_btn = (Button)findViewById(R.id.sign_up_btn);
reg_btn.setOnClickListener(this);
//language selection list
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.country_list, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ctry_spinner.setAdapter(adapter);
ctry_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
choice = ctry_spinner.getSelectedItem().toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
};
});
go_back = (ImageButton)findViewById(R.id.go_back);
go_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent toStart_appActivity = new Intent(getApplicationContext(), start_appActivity.class);
startActivity(toStart_appActivity);
}
});
}
@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.sign_up_btn:
String email = emailAddr.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
if(dispName.getText().toString().trim().length() == 0){
set_fail.setText("Enter display name to be shown");
}
else if(emailAddr.getText().toString().trim().length() == 0){
set_fail.setText("Enter your email address");
}
else if(passwd.getText().toString().trim().length() == 0){
set_fail.setText("Enter your login password");
}
else if(passwd.getText().toString().trim().length() != 0){
int pwlength = passwd.getText().length();
if(pwlength < 6){
set_fail.setText("Your password must contain 6 characters or more");
}
}
else{
// onClick of button perform this simplest code.
System.out.print("1 break");
if (email.matches(emailPattern))
{
set_fail.setText("Valid email address");
set_fail.setTextColor(Color.parseColor("#00FF00"));
System.out.print("first break");
check_mail_exist(emailAddr.getText().toString());
System.out.print("third break");
}
else
{
set_fail.setText("Invalid email address");
set_fail.setTextColor(Color.parseColor("#FF3300"));
}
}
break;
}
}
private void check_mail_exist(final String ent_email) {
Firebase f_user = new Firebase("https://myapp.firebaseio.com/User/");
f_user.addListenerForSingleValueEvent(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot snap_user) {
System.out.print("second break");
// TODO Auto-generated method stub
Iterable<DataSnapshot> rs = snap_user.getChildren();
Iterator<DataSnapshot> irs = rs.iterator();
long allNum2 = snap_user.getChildrenCount();
int maxNum2 = (int)allNum2;
int count_user = 1;
while(irs.hasNext())
{
if(count_user <= maxNum2)
{
Map<String, Object> nPost = (Map<String, Object>) irs.next().getValue();
String db_email = nPost.get("email_addr").toString();
if(ent_email.equals(db_email))
{
set_fail.setText("This email has already exist!");
set_fail.setTextColor(Color.parseColor("#FF3300"));
}
else
{
Firebase f = new Firebase("https://myapp.firebaseio.com/");
Firebase userData = f.child("User");
//save into login & auth of email and password SUCCESS
//create custom email and password for this app using Firebase as host.
userData.createUser(emailAddr.getText().toString(), passwd.getText().toString(), new Firebase.ValueResultHandler<Map<String, Object>>() {
@Override
public void onSuccess(Map<String, Object> result) {
System.out.println("Successfully created user account with uid: " + result.get("uid"));
}
@Override
public void onError(FirebaseError firebaseError) {
// there was an error
}
});
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
String today_date = dateFormat.format(calendar.getTime());
Firebase set_user = userData.push();
String user_id = set_user.getKey();
Map<String, Object> save_user = new HashMap<String, Object>();
save_user.put("disp_name", dispName.getText().toString());
save_user.put("real_name", "");
save_user.put("dob", "");
save_user.put("date_created", today_date);
save_user.put("userDesc", "");
save_user.put("email_addr", emailAddr.getText().toString());
save_user.put("user_pwd", passwd.getText().toString());
save_user.put("lastProfChange", "");
save_user.put("country", choice);
save_user.put("id",user_id);
set_user.setValue(save_user);
Toast.makeText(getBaseContext(), "Registration success!", Toast.LENGTH_LONG).show(); ;
Intent toStartupActivity = new Intent(getApplicationContext(), start_appActivity.class);
startActivity(toStartupActivity);
}
} else {
System.out.println("Failed");
}
count_user++;
}
}
@Override
public void onCancelled(FirebaseError arg0) {
// TODO Auto-generated method stub
}
});
}
}
这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/regbg"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/title_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/regi_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Registration"
android:textSize="30dp"
android:maxLines="1"
android:layout_marginLeft="70dp"
android:layout_marginTop="10dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="50dp"
android:background="@drawable/round_edges_layout">
<TextView
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Email"
android:layout_marginLeft="10dp"
android:textStyle="bold">
</TextView>
<EditText
android:id="@+id/email_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:maxLines="1"
android:inputType="textEmailAddress|textNoSuggestions"
android:layout_marginLeft="5dp"
android:hint="Email" />
<View
android:layout_width="280dp"
android:layout_height="2dp"
android:background="#c0c0c0"/>
<TextView
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:maxLines="1"
android:text="Password"
android:layout_marginLeft="10dp"
android:textStyle="bold">
</TextView>
<EditText
android:id="@+id/pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword|textNoSuggestions"
android:layout_marginLeft="5dp"
android:hint="Password" />
<View
android:layout_width="280dp"
android:layout_height="2dp"
android:background="#c0c0c0"/>
<TextView
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Display Name"
android:layout_marginLeft="10dp"
android:textStyle="bold">
</TextView>
<EditText
android:id="@+id/uid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:maxLines="1"
android:layout_marginLeft="5dp"
android:hint="Display Name" />
<View
android:layout_width="280dp"
android:layout_height="2dp"
android:background="#c0c0c0"/>
<TextView
android:id="@+id/editText5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Country selection"
android:layout_marginLeft="10dp"
android:textStyle="bold">
</TextView>
<Spinner
android:id="@+id/country_sel"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linere"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/fail_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginLeft="50dp"
android:textColor="#FF1919"
android:textStyle="bold">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="60dp"
android:layout_marginLeft="120dp">
<Button
android:id="@+id/sign_up_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/btn_text_click"
android:background="@drawable/greenbtn"
android:text="Confirm" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/up"
android:layout_marginLeft="258dp">
<ImageButton
android:id="@+id/go_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back_btn" />
</LinearLayout>
</LinearLayout>
</ScrollView>
当我点击sign_up_btn时发生了这种情况。我尝试了键盘更改,但它们不起作用,我不确定是什么问题,因为它在我交给我的主管之前工作,现在它无法工作。
获得以下错误也....
任何信息都会有所帮助。
答案 0 :(得分:0)
好的,我发现错误,不应该是错误。我的密码长度少于6个字符导致错误。但它不应该因为当用户输入超过6个字符并且第二次点击按钮时应该跳过它。任何人都可以提供一些见解吗?