0

I wrote code to associate it with Firebase, because i want to build a database for Register accounts. but when i ( run "app" ) i find some error i can't fix it, and i dont know why show? And it prevents me from opening the app in the VM mobile as well.

I hope help me, as I have tried many solutions on the Internet, but they doesn't work.

1- MainActivity.java

package com.example.ksuers; 

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class MainActivity extends AppCompatActivity {

//anuther video say TextInputLayout
EditText nameu;
EditText emailu;
EditText pass;
//Spinner college;
RadioButton user;
Button btnsign;

FirebaseDatabase rootNode;
DatabaseReference reference;

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

    nameu=(EditText)findViewById(R.id.Uname);
    emailu=(EditText)findViewById(R.id.uni_email);
    pass=(EditText)findViewById(R.id.Upass);
    //college=(Spinner)findViewById(R.id.Ucollege);
    user=(RadioButton)findViewById(R.id.StudentUser);
    //user=(RadioButton)findViewById(R.id.AdminUser);
    btnsign=(Button)findViewById(R.id.btn_sign);

    //to save data in firebase
    btnsign.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            rootNode = FirebaseDatabase.getInstance();
            reference = rootNode.getReference("users");

            String name = nameu.getText().toString();
            String uniemail = emailu.getText().toString();
            String password = pass.getText().toString();
            String type = user.getText().toString();


            UserHelperClass helperClass = new UserHelperClass(name, uniemail, password, type);

            reference.setValue(helperClass);

            }
        });

    }
}

2- activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<!--suppress ALL -->
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/background">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/Uname"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        android:hint="Full name"
        android:inputType="textEmailAddress"
        android:selectAllOnFocus="true"
        app:layout_constraintBottom_toTopOf="@+id/Upass"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.871"
        tools:ignore="MissingConstraints"
        android:autofillHints="" >
    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/Upass"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        android:hint="Password"
        android:imeOptions="actionDone"
        android:importantForAutofill="no"
        android:inputType="textPassword"
        android:selectAllOnFocus="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.532"
        tools:ignore="MissingConstraints" >
    </com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/uni_email"
    android:layout_width="363dp"
    android:layout_height="50dp"
    android:layout_marginTop="28dp"
    android:ems="10"
    android:hint="University email"
    android:inputType="textEmailAddress"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.248"
    android:importantForAutofill="no" >
</com.google.android.material.textfield.TextInputLayout>


<Button
    android:id="@+id/btn_sign"
    android:layout_width="221dp"
    android:layout_height="52dp"
    android:layout_gravity="start"
    android:layout_marginStart="48dp"
    android:layout_marginEnd="48dp"
    android:background="@drawable/signup"
    android:enabled="false"
    android:text="Sign in"
    android:textColor="#fff"
    android:transitionName="button_tran"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.815" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Create an account"
    android:textColor="#FFFFFF"
    android:textSize="24sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.497"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.128" />

<RadioButton
    android:id="@+id/AdminUser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Admin"
    android:textColor="#041B70"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.672"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="54dp" />

<RadioButton
    android:id="@+id/StudentUser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="68dp"
    android:layout_marginRight="68dp"
    android:text="Student"
    android:textColor="#041B70"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.609"
    app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.672" />


</androidx.constraintlayout.widget.ConstraintLayout>

3- UserHelperClass.java

    package com.example.ksuers;

public class UserHelperClass {

    String name, uniemail, password, Type;

    public UserHelperClass() {

    }

    public UserHelperClass(String name, String uniemail, String password, String type) {
        this.name = name;
        this.uniemail = uniemail;
        this.password = password;
        Type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUniemail() {
        return uniemail;
    }

    public void setUniemail(String uniemail) {
        this.uniemail = uniemail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getType() {
        return Type;
    }

    public void setType(String type) {
        Type = type;
    }
}

And the Error is:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ksuers, PID: 7103
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ksuers/com.example.ksuers.MainActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class com.google.android.material.textfield.TextInputLayout
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class com.google.android.material.textfield.TextInputLayout
 Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class com.google.android.material.textfield.TextInputLayout
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.material.textfield.TextInputLayout" on path: DexPathList[[zip file "/data/app/com.example.ksuers-AD1q19UGUyfr67j28j6DBA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.ksuers-AD1q19UGUyfr67j28j6DBA==/lib/x86, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
    at com.example.ksuers.MainActivity.onCreate(MainActivity.java:31)
    at android.app.Activity.performCreate(Activity.java:7009)
    at android.app.Activity.performCreate(Activity.java:7000)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
KSUERS
  • 569
  • 1
  • 4
  • 5
  • What do you have in your build.gradle file? Make sure you have this dependency: com.google.android.material:material:1.2.1 – Gil Becker Sep 24 '20 at 11:29
  • what `Theme` are you using for `AppTheme` in `styles.xml`? – Ehsan msz Sep 24 '20 at 11:30
  • i have this in styles.xml ( ) – KSUERS Sep 24 '20 at 11:36
  • @KSUERS - You are missing overriding the Material Theme. Change the parent to "Theme.MaterialComponents.Light.DarkActionBar". It will work for you. – Mohit Ajwani Sep 24 '20 at 11:46
  • @MohitAjwani I change it, nut still does not work – KSUERS Sep 24 '20 at 12:00

4 Answers4

1

You are missing overriding the Material Theme.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">

This should solve the problem. If you want to stick to the existing theme, then you need to aadd a lot of styles for the Material Theme. Check the documentation website for more information.

Mohit Ajwani
  • 1,328
  • 12
  • 24
  • I change the style to this material theme but it also does not work – KSUERS Sep 24 '20 at 11:57
  • Check if this post helps you https://stackoverflow.com/questions/51957275/inflateexception-when-using-textinputlayout – Mohit Ajwani Sep 24 '20 at 12:36
  • Check if this post also helps you https://stackoverflow.com/questions/57134070/error-inflating-class-com-google-android-material-textfield-textinputlayout – Mohit Ajwani Sep 24 '20 at 14:24
  • I have read this post and most of the suggestions have been implemented from the beginning, but until now it does not work – KSUERS Sep 24 '20 at 15:05
  • I check the second post and when I try to implement, I find more errors... – KSUERS Sep 24 '20 at 15:42
  • Can you confirm if you are following all steps mentioned in https://material.io/develop/android/docs/getting-started. – Mohit Ajwani Sep 27 '20 at 09:25
  • Also, please check if you are using the AppTheme as the theme in the Android Manifest. android:theme="@style/AppTheme" This should be an attribute in the tag – Mohit Ajwani Sep 27 '20 at 09:26
0

make sure you are using Material Theme:

in styles.xml:

<!-- Material Theme --> 
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
Ehsan msz
  • 1,774
  • 2
  • 13
  • 26
0

Add this to your build file as a dependencies. implementation 'com.google.android.material:material:1.2.1'

Asad khan
  • 156
  • 7
  • I use it, and use (com.google.android.material:material:1.2.1) but it also doesn't work :( – KSUERS Sep 24 '20 at 11:49
  • can you share your projects dependencies? – Asad khan Sep 24 '20 at 11:51
  • ( implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'com.google.firebase:firebase-database:19.4.0' implementation 'com.google.android.material:material:1.2.1' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' ) – KSUERS Sep 24 '20 at 11:56
  • Now in styles.xml replace with – Asad khan Sep 24 '20 at 12:06
  • https://material.io/develop/android/docs/getting-started Read first 5 points. – Asad khan Sep 24 '20 at 12:08
  • I read this article and I make sure that all the aforementioned is implemented, but the application is not working until now :((((( – KSUERS Sep 24 '20 at 12:56
  • have you added this in your build.gradle allprojects { repositories { google() jcenter() } } – Asad khan Sep 24 '20 at 13:11
  • Yes it's there from the beginning – KSUERS Sep 24 '20 at 15:04
0

Try to enable multidex, maybe you have reached cap https://developer.android.com/studio/build/multidex

Autocrab
  • 3,474
  • 1
  • 15
  • 15
  • I read the article but they say "if" i have a (trouble writing output: Too many field references: 131000; max is 65536. You may try using --multi-dex option.) I can fix it but actually, I'm not having this problem – KSUERS Sep 24 '20 at 20:22