KSUERS
KSUERS

Reputation: 589

java.lang.RuntimeException: Unable to start activity in Androidstudio

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)

Upvotes: 0

Views: 103

Answers (4)

Autocrab
Autocrab

Reputation: 3757

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

Upvotes: 0

Mohit Ajwani
Mohit Ajwani

Reputation: 1338

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.

Upvotes: 1

Asad khan
Asad khan

Reputation: 156

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

Upvotes: 0

Ehsan Msz
Ehsan Msz

Reputation: 2164

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>

Upvotes: 0

Related Questions