-1

Once I click on the connection button it quits instead of passing to the next activity... By the way, when I click on the button - the connection with Firebase is working but the application quits.

But when I click on the TextView to create an account - it's working and it takes me to the next activity "RegisterActivity"

Here is the Java code:

public class MainActivity extends AppCompatActivity {

    MaterialEditText val1, val2;
    TextView val3;
    Button val4 ;
    FirebaseAuth f ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        f = FirebaseAuth.getInstance();
        val1 = findViewById(R.id.edt_email);
        val2 = findViewById(R.id.edt_password);
        val3 = findViewById(R.id.tv_message);
        val4 = findViewById(R.id.bt_login);


        val4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String mail = val1.getText().toString();
                String password = val2.getText().toString();
                if (mail.isEmpty() || password.isEmpty()) {
                    Toast.makeText(getApplicationContext(),"Champs vides",Toast.LENGTH_LONG).show();
                } else {
                    Login(mail, password);
                }
            }
        });


    }


    private void Login(String mail, String password) {
        f.signInWithEmailAndPassword(mail, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    Passage();
                } else {
                    Toast.makeText(getApplicationContext(),"Vérifiez vos champs",Toast.LENGTH_LONG).show();
                }
            }
        });
    }




    private void Passage()
    {
        startActivity(new Intent(this,com.example.SeekMake.HomeFragment.class));
    }   

     public void registration (View w){
        Intent i = new Intent(this, RegisterActivity.class);
        startActivity(i);
    }
}

and that's the xml code :

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity"
 android:orientation="vertical"
 android:weightSum="4"
 >
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:layout_marginTop="0dp"
    android:layout_weight="2"> 
 <ImageView
        android:id="@+id/logo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:src="@drawable/capture" />
 </LinearLayout>
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_margin="18dp"
    android:padding="18dp">

<com.rengwuxian.materialedittext.MaterialEditText
    android:hint="Email"
    android:id="@+id/edt_email"
    android:inputType="textEmailAddress"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:met_iconPadding="0dp"
    app:met_iconRight= "@drawable/ic_email"
    />



<com.rengwuxian.materialedittext.MaterialEditText
    android:hint="Mot de passe"
    android:id="@+id/edt_password"
    android:inputType="textPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    app:met_iconPadding="0dp"
    app:met_iconRight="@drawable/ic_lock"

    />


    <Button
        android:id="@+id/bt_login"
        android:layout_width="150dp"
        android:layout_height="55dp"
        android:layout_marginLeft="70dp"
        android:layout_marginTop="30dp"
        android:text="Se connecter" />

    <TextView
    android:id="@+id/tv_message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="80dp"
    android:layout_marginRight="80dp"
    android:layout_marginTop="30dp"
    android:text="Créer un compte"
    android:onClick="registration"
    />


 </LinearLayout>
 </LinearLayout>

that's the logcat:

       2020-05-21 17:27:09.734 9785-9785/com.example.testing E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.testing, PID: 9785
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.testing/com.example.SeekMake.HomeFragment}: java.lang.ClassCastException: com.example.SeekMake.HomeFragment cannot be cast to android.app.Activity
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3215)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3429)
    at android.app.ActivityThread.-wrap12(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
    at android.os.Handler.dispatchMessage(Handler.java:109)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7555)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
 Caused by: java.lang.ClassCastException: com.example.SeekMake.HomeFragment cannot be cast to android.app.Activity
    at android.app.Instrumentation.newActivity(Instrumentation.java:1179)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3202)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3429) 
    at android.app.ActivityThread.-wrap12(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009) 
    at android.os.Handler.dispatchMessage(Handler.java:109) 
    at android.os.Looper.loop(Looper.java:166) 
    at android.app.ActivityThread.main(ActivityThread.java:7555) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963) 
 2020-05-21 17:27:09.755 9785-9785/com.example.testing I/Process: Sending 
signal. PID: 9785 SIG: 9
Ryan M
  • 18,333
  • 31
  • 67
  • 74

1 Answers1

0

You are trying to launch a Fragment as though it were an Activity:

startActivity(new Intent(this,com.example.SeekMake.HomeFragment.class));

Fragments are not Activitys and cannot be launched via startActivity. See here for how to create a second Activity to hold your Fragment, which you can then launch instead.

Ryan M
  • 18,333
  • 31
  • 67
  • 74