2017-12-27 3 views
0

그래서 Firebase 설정과 물건에서 모든 단계를 밟았지만 컨트롤이 내 createUserWithEmailAndPassword() 방법으로 움직이지 않습니다. 화면이 정지되고 동그라미가되는 progressBar 외에는 아무 것도 발생하지 않습니다. 여기 파이어베이스 액세스가 작동하지 않습니다.

내 Gradle을 build.app 파일입니다 : 여기

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    buildToolsVersion '26.0.2' 
    defaultConfig { 
     applicationId "com.example.parma.gareebcalculator" 
     minSdkVersion 23 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 

    implementation 'com.google.firebase:firebase-auth:11.0.4' 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:26.1.0' 
    compile 'com.android.support:support-v4:26.1.0' 

    testCompile 'junit:junit:4.12' 
} 

apply plugin: 'com.google.gms.google-services' 

그리고 것은 내 코드입니다 : -

public class RegsiterPage extends AppCompatActivity implements View.OnClickListener{ 

    private EditText userName; 
    private EditText email; 
    private EditText password; 
    private EditText repassword; 
    private Button signUp; 
    private ProgressBar progressBar; 
    private FirebaseAuth mAuth; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.activity_regsiter_page); 

     userName = (EditText) findViewById(R.id.usernameid); 
     email = (EditText) findViewById(R.id.emailid); 
     password = (EditText) findViewById(R.id.passwordid); 
     repassword = (EditText) findViewById(R.id.repasswordid); 
     signUp = (Button) findViewById(R.id.signupid); 
     progressBar = (ProgressBar) findViewById(R.id.progressBarid); 
     // Used to intialize the firebase object and register the user on the server:- 
     mAuth = FirebaseAuth.getInstance(); 

     signUp.setOnClickListener(this); 
    } 

    //Email constraints:- 
    //To check whether the entered email is of correct format: 
    private boolean isValidEmail(String email) 
    { 
     if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()) 
     { 
      return false; 
     } 
     return true; 
    } 

    //Username constraints:- 
    //To check whether the given username only contains letters or digits: 
    private boolean userNameCheck(String name){ 
     if(Character.isDigit(name.charAt(0))){ 
      return false; 
     } 
     for(int i=0;i<name.length();i++){ 
      if(!Character.isLetterOrDigit(name.charAt(i))){ 
       return false; 
      } 
     } 
     return true; 
    } 

    private boolean checkUserNameLength(String name){ 
     if(name.length()<8){ 
      return false; 
     } 
     return true; 
    } 

    //Password constraints:- 
    //To see whethter the password contains any special characters or not: 
    private boolean checkSpecial(String pass){ 
     byte[] bytes = pass.getBytes(); 
     for(byte temp:bytes){ 
      if(temp>=33 && temp<=47){ 
       return false; 
      } 
     } 
     return true; 
    } 

    //To see whethter the password is containing both alphabets and numbers: 
    private boolean checkPassword(String pass){ 
     if(pass.length()<8){ 
      return false; 
     } 
     for(int i=0;i<pass.length();i++){ 
      if(!Character.isLetterOrDigit((pass.charAt(i)))){ 
       return false; 
      } 
     } 
     return true; 
    } 

    private void onSignUp(){ 
     final String usernameString = userName.getText().toString().trim(); 
     final String emailString = email.getText().toString().trim(); 
     final String passwordString = password.getText().toString().trim(); 
     final String repasswordString = repassword.getText().toString().trim(); 

     /**If any of the either fields login or password are empty then the following couple actions might take place:- 
     * Also if the passwords mismatch then the user will be denied a successfull registeration*/ 
     if(TextUtils.isEmpty(usernameString)){ 
      userName.setError("Please enter Username"); 
      userName.requestFocus(); 
      return; 
     } 
     if(TextUtils.isEmpty(emailString)){ 
      email.setError("Please enter Email Id"); 
      email.requestFocus(); 
      return; 
     } 
     if(TextUtils.isEmpty(passwordString)){ 
      password.setError("Please enter Password"); 
      password.requestFocus(); 
      return; 
     }if(TextUtils.isEmpty(repasswordString)){ 
      repassword.setError("Please Re-enter Password"); 
      repassword.requestFocus(); 
      return; 
     } 
     if(!userNameCheck(usernameString)){ 
      userName.setError("Username can contain only alphabets or digits.Username cannot start with a number"); 
      userName.setText(""); 
      userName.requestFocus(); 
      return; 
     } 
     if(!checkUserNameLength(usernameString)){ 
      userName.setError("The username should atleast contain 8 charchacters"); 
      userName.setText(""); 
      userName.requestFocus(); 
      return; 
     } 
     if (userName.getText().toString().contains(" ")) { 
      userName.setError("Spaces NOT Allowed"); 
      userName.requestFocus(); 
      return; 
     } 
     if(!isValidEmail(emailString)){ 
      email.setError("Incorrect Email format"); 
      email.requestFocus(); 
      return; 
     } 
     if (!repasswordString.equals(passwordString)){ 
      //Toast.makeText(this,"Password Mismatch.Try Again",Toast.LENGTH_SHORT).show(); 
      password.setGravity(10); 
      password.setError("Passwords are incorrect"); 
      password.setText(""); 
      repassword.setText(""); 
      password.requestFocus(); 
      return; 
     } 
     if(!checkPassword(passwordString)){ 
      password.setError("The password should be alphanumeric and should be 8 characters long.No special symbols allowed"); 
      password.setText(""); 
      repassword.setText(""); 
      password.requestFocus(); 
      return; 
     } 
     if(!checkSpecial(passwordString)){ 
      password.setError("The password should not contain any special characters"); 
      password.setText(""); 
      repassword.setText(""); 
      password.requestFocus(); 
      return; 
     } 

     //If all, username,email,password and repassword have been entered then the following part takes place 
     progressBar.setVisibility(View.VISIBLE); 

     /*Here the user is created using a password and email and addonCompleteListener is optional part which states what to be 
     done when the user has successfully logged in*/ 
     mAuth.createUserWithEmailAndPassword(emailString,passwordString).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
      @Override 
      public void onComplete(@NonNull Task<AuthResult> task) { 
       progressBar.setVisibility(View.GONE); 
       if(task.isSuccessful()){ 
        Toast.makeText(RegsiterPage.this,"Registered Successfully.",Toast.LENGTH_SHORT).show(); 
        //To record the username in a the android application: 
        /*FirebaseUser user = mAuth.getCurrentUser(); 
        if(user!=null){ 
         UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder() 
           .setDisplayName(usernameString) 
           .build(); 

         user.updateProfile(profile).addOnCompleteListener(new OnCompleteListener<Void>() { 
          @Override 
          public void onComplete(@NonNull Task<Void> task) { 
           if(task.isSuccessful()){ 
            Toast.makeText(RegsiterPage.this,"Awesome Profile Created",Toast.LENGTH_SHORT).show(); 
           }else{ 
            Toast.makeText(RegsiterPage.this,task.getException().getMessage(),Toast.LENGTH_SHORT).show(); 
           } 
          } 
         }); 
        }*/ 
        Intent intent = new Intent(getApplicationContext(),LoginPage.class); 
        startActivity(intent); 
       } 
       else if(task.getException() instanceof FirebaseAuthUserCollisionException) { 
        Toast.makeText(RegsiterPage.this,"You are already Registered",Toast.LENGTH_SHORT).show(); 
        userName.setText(""); 
        email.setText(""); 
        password.setText(""); 
        repassword.setText(""); 
       }else{ 
        Toast.makeText(RegsiterPage.this,task.getException().getMessage(),Toast.LENGTH_SHORT).show(); 
        userName.setText(""); 
        email.setText(""); 
        password.setText(""); 
        repassword.setText(""); 
       } 
      } 
     }); 

    } 

    @Override 
    public void onClick(View v) { 
     if(v == signUp){ 
      onSignUp(); 
     } 
    } 
} 

편집 : -

여기

내 로그 캣입니다 : -

E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.example.parma.gareebcalculator, PID: 3149 
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task 
com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdd)' on a null object reference 
at com.google.android.gms.internal.zzdvv.zzb(Unknown Source) 
at com.google.android.gms.internal.zzdwc.zza(Unknown Source) 
at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(Unknown 
    Source) 
at com.example.parma.gareebcalculator.RegsiterPage.onsignup(RegsiterPage.java:192) 
at com.example.parma.gareebcalculator.RegsiterPage.onClick(RegsiterPage.java:241) 
at android.view.View.performClick(View.java:5610) 
at android.view.View$PerformClick.run(View.java:22265) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
내 전체 코드와 모든 피치 완벽했다 ... 누군가가 this..just 함께 오면 이렇게 ...하지만 잘못은 내 에뮬레이터로했다 ... :

솔루션

솔루션 발견 그것은 API 24에서 실행 중이었습니다 ... 그리고 이것은 실제로 응용 프로그램이 현금화되었지만 결코 말하지 않았기 때문에 추적 할 수 없었습니다 .... 그래서 API를 26 (나를 위해 일한)로 변경하고 새로운 API를 사용하거나 생성하십시오. 에뮬레이터

+0

firebase 콘솔에서 전자 메일 로그인 방법을 활성화 했습니까? 또한 onComplete 콜백과 함께 onFailure 콜백을 추가하면 무엇이 잘못되었는지에 대한 아이디어를 얻을 수 있습니다. – Kushan

+0

@ Kushan 예. 내가 한 일은 ... 무엇이 잘못되었는지에 대해 여전히 불명확합니다. –

+0

@Kushan .. 내 코드를 검토해 주셔서 감사합니다. . 편집 된 설명에 명시된 해결책이 있습니다. 감사합니다. –

답변

0

귀하의 mAuth가 Null이며이 충돌의 원인이 무엇입니까

chec 유지 k

if(mAuth !=null){ 

    } 
+0

그는 onCreate에서 초기화 중입니다. – Kushan

+0

얘들 아 ... 무슨 일이 일어 났는지 믿지 않을거야. 내 코드가 완벽 했어.하지만 내 에뮬레이터는 API 24에 대한 작업으로 모든 것이 올바르게 보였음에도 불구하고 방화 대와 연결하는 것을 허용하지 않았습니다. –

+0

예. – ABDevelopers

관련 문제