2017-07-14 1 views
0

Die Aktivität konnte nicht gestartet werden ComponentInfo {e_homes.app.com.e_homes/e_homes.app.com.e_homes.Location}: java.lang.NullPointerException. Dieser Fehler tritt in meinem Code auf. Ich habe Firebase-Authentifizierung verwendet, aber wenn ich mich anmelde gibt es den obigen Fehler. Hier ist der CodeDie Aktivität konnte nicht gestartet werden ComponentInfo: Fehler beim Verwenden der Firebase-Authentifizierung

public class MainActivity extends AppCompatActivity { 
private FirebaseAuth fb; 
private ProgressDialog progressDialog; 
private FirebaseAuth.AuthStateListener mAuthListener; 
Button txtRegister; 
EditText etEmail,etPassword; 
Button Register; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    fb = FirebaseAuth.getInstance(); 
    txtRegister = (Button) findViewById(R.id.signup); 
    etEmail = (EditText) findViewById(R.id.username); 
    etPassword = (EditText) findViewById(R.id.password); 
    Register = (Button) findViewById(R.id.signin); 
    progressDialog = new ProgressDialog(this); 
    mAuthListener=new FirebaseAuth.AuthStateListener() { 
     @Override 
     public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
      if(firebaseAuth.getCurrentUser()!=null) { 
       startActivity(new Intent(getApplicationContext(), 
Location.class)); 
      } 

     } 
    }; 

    Register.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      userLogin(); 
     } 
    }); 
    txtRegister.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) 
     { 
      Intent intent = new 
Intent(MainActivity.this,Registration.class); 
      startActivity(intent); 
     } 
    }); 
} 

    @Override 
    protected void onStart() { 
    fb.addAuthStateListener(mAuthListener); 
    super.onStart(); 
    } 

    private void userLogin() { 
    String email_id = etEmail.getText().toString().trim(); 
    String password = etPassword.getText().toString().trim(); 
    if (TextUtils.isEmpty(email_id)) { 
     Toast.makeText(this, "please enter your Email_Id", 
Toast.LENGTH_SHORT).show(); 
     return; 
    } else if (TextUtils.isEmpty(password)) { 
     Toast.makeText(this, "please enter your password", 
Toast.LENGTH_SHORT).show(); 
     return; 
    } else { 
     progressDialog.setMessage("Logining in....Please wait...."); 
     progressDialog.show(); 
     fb.signInWithEmailAndPassword(email_id, password). 
       addOnCompleteListener(this, new 
OnCompleteListener<AuthResult>() { 
        @Override 
        public void onComplete(@NonNull Task<AuthResult> task) { 
         progressDialog.dismiss(); 
         if (task.isSuccessful()) { 
          // startActivity(new 
Intent(getApplicationContext(), Location.class)); 
         // finish(); 
         } else { 
          Toast.makeText(MainActivity.this, "Invalid email 
Id or password", Toast.LENGTH_SHORT).show(); 
         } 
        } 
       }); 
    } 
    } 

} 

GANZE Fehler ist:

FATAL EXCEPTION: main 


    Process: e_homes.app.com.e_homes, PID: 7302 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{e_homes.app.com.e_homes/e_homes.app.com.e_homes.Location}: java.lang.NullPointerException 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
     at android.os.Handler.dispatchMessage(Handler.java:110) 
     at android.os.Looper.loop(Looper.java:193) 
     at android.app.ActivityThread.main(ActivityThread.java:5299) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 
     at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NullPointerException 
     at e_homes.app.com.e_homes.Location.onCreate(Location.java:31) 
     at android.app.Activity.performCreate(Activity.java:5264) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
     at android.os.Handler.dispatchMessage(Handler.java:110) 
     at android.os.Looper.loop(Looper.java:193) 
     at android.app.ActivityThread.main(ActivityThread.java:5299) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
+0

Ist die 'Location' Klasse etwas, das Sie erstellt haben? – kunruh

+0

Fügen Sie Ihre Standortklasse hinzu –

Antwort

0

Als ich von Ihrem logcat sehen, wird der Fehler nicht tatsächlich von Ihrem MainActivity kommt aus Ihrer Location Aktivität.

Sie müssen den folgenden Code zu Ihrer AndroidManifest.xml Datei hinzufügen.

<activity android:name=".start" android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.intent.action.MainActivity" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 
<activity android:name= ".Location"> 
</activity> 

Und versuchen unsing this anstelle von getApplicationContext().

Ich hoffe, es hilft.

Verwandte Themen