App restarts, Doesn't run due to AndroidRuntime Exception - java

Gradle build is successful logcat shows E/AndroidRuntime: FATAL EXCEPTION: main
--------Logcat Error-----------
07-27 23:04:54.813 21702-21702/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.inoalexander.justjava, PID: 21702
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.inoalexander.justjava/com.example.inoalexander.justjava.mainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1424)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1424) 
---------Java Code starts here----------
package com.example.inoalexander.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
---------XML code starts here-------------
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="16sp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:text="Quantity" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:text="0" />
<Button
android:id="#+id/button_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:text="Order"
android:onClick="submitOrder"/>
</LinearLayout>
I'm not to sure as this is one of the first apps I've built that isn't a card. I'm not sure why it isn't running on my phone. I'm using a Galaxy Note 5 to run my build.
The Gradle build is successful and gives me no errors but when I try to run it on my device it keeps trying to restart the app until it eventually crashes the app. I have looked at a few answers here and was instructed to look at my Logcat in android studio.
I honestly don't know were to even begin within Logcat or what it even tells me, there are a lot of variations of this error I have seen but not one specific to each of the errors in my Logcat.

set multidex true to app level build.gradle file like below
android {
compileSdkVersion 27
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.core.######"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true // here change
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
also add dependency
implementation 'com.android.support:multidex:1.0.3'
finally don't forget to clean and rebuild project.

The exception says it's trying to find class mainActivity but in your code you have MainActivity.
Make sure the activity class name in AndroidManifest.xml matches your code.

Related

Problem in opening an Activity from Fragment Activity

I have created a Fragment view in my Navigation Drawer and
I want to call an Activity from that Fragment view using an ImageView for that I have written this java code in My Fragment View class
But I don't know why whenever I click on my image the app gets crashed please help out
package com.example.gamesense.ui.Maps;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.example.gamesense.R;
public class MapsFragment extends Fragment {
private MapsViewModel mapsViewModel;
private ImageView erangle_image;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
mapsViewModel =
new ViewModelProvider(this).get(MapsViewModel.class);
View root = inflater.inflate(R.layout.fragment_maps, container, false);
//on click listener for image
erangle_image = root.findViewById(R.id.erangle_image);
erangle_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(getActivity(),ErangleMap.class));
}
});
return root;
}
}
And here is the XML for Fragment View and
from ImageView I want to open new Activity
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:paddingEnd="20dp"
android:background="#drawable/background"
android:paddingBottom="20dp"
android:paddingStart="20dp"
android:paddingRight="20dp"
android:orientation="vertical"
tools:context=".ui.Maps.MapsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/erangle"
android:background="#drawable/shape">
<ImageView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
android:id="#+id/erangle_image"
android:src="#drawable/erangel"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ERANGLE:"
android:textAlignment="viewStart"
android:background="#C59507"
android:textSize="24sp"
android:textColor="#FFFFFF"
android:paddingTop="7dp"
android:paddingLeft="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C59507"
android:paddingBottom="10dp"
android:text="Erangel is the first 8x8 km playable map created for PUBG."
android:textAlignment="textStart"
android:paddingLeft="15dp"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
Logcat
2021-03-23 09:48:47.556 10047-10047/com.example.gamesense E/Parcel: Reading a NULL string not supported here.
2021-03-23 09:48:47.586 10047-10086/com.example.gamesense E/libEGL: Invalid file path for libcolorx-loader.so
2021-03-23 09:48:47.596 10047-10047/com.example.gamesense D/AndroidRuntime: Shutting down VM
2021-03-23 09:48:47.597 10047-10047/com.example.gamesense E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gamesense, PID: 10047
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gamesense/com.example.gamesense.ui.Maps.ErangleMap}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3699)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:254)
at android.app.ActivityThread.main(ActivityThread.java:8202)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.gamesense.ui.Maps.ErangleMap.onCreate(ErangleMap.java:14)
at android.app.Activity.performCreate(Activity.java:8146)
at android.app.Activity.performCreate(Activity.java:8130)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3668)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:254) 
at android.app.ActivityThread.main(ActivityThread.java:8202) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006) 
2021-03-23 09:48:47.623 10047-10047/com.example.gamesense I/Process: Sending signal. PID: 10047 SIG: 92021-03-23 09:48:47.556 10047-10047/com.example.gamesense E/Parcel: Reading a NULL string not supported here.
2021-03-23 09:48:47.586 10047-10086/com.example.gamesense E/libEGL: Invalid file path for libcolorx-loader.so
2021-03-23 09:48:47.596 10047-10047/com.example.gamesense D/AndroidRuntime: Shutting down VM
2021-03-23 09:48:47.597 10047-10047/com.example.gamesense E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gamesense, PID: 10047
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gamesense/com.example.gamesense.ui.Maps.ErangleMap}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3699)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:254)
at android.app.ActivityThread.main(ActivityThread.java:8202)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.gamesense.ui.Maps.ErangleMap.onCreate(ErangleMap.java:14)
at android.app.Activity.performCreate(Activity.java:8146)
at android.app.Activity.performCreate(Activity.java:8130)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3668)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:254) 
at android.app.ActivityThread.main(ActivityThread.java:8202) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006) 
2021-03-23 09:48:47.623 10047-10047/com.example.gamesense I/Process: Sending signal. PID: 10047 SIG: 9```
it says "You need to use a Theme.AppCompat theme (or descendant) with this activity."
maybe you edited/removed the theme by mistake. check your manifest
have you declared this activity in your AndroidManifest.xml? check this one Check your manifest first and declare your activity
Add or modify existing theme with AppCompat theme in your styles.xml. like the following:
<style name="yourThemeName" parent="#style/Theme.AppCompat....">
//.... items will go here
</style>
And you can use this theme as global theme
<application
android:theme="#style/yourThemeName">
OR
For specific activity
<activity
android:name=".ErangleMap"
android:theme="#style/yourThemeName">
//....
</activity>

Error: inflating class com.google.android.material.navigation.NavigationView in androidX

My app working above API level 26 or higher but stoped working bellow API level 26. Please help me..
Why does XML returns error in inflating class, and stoped working in lower API level?
I tried these methods but it did not work:
Check your code for drawable and color resources used inside the com.google.android.material.navigation.NavigationView you've used, probably in activity_main.xml, if you're using the default Navigation Drawer template code from Android Studio.
Check that the drawable files are in res/drawable folder, not in res/drawable-v21.
Check if you've used android:backgroundTint() or android:src or similar inside your NavigationView. Since they don't work below android API Level 21, use app:backgroundTint or app:srcCompat instead.
...
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bozorgan/com.example.bozorgan.MainActivity}: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7223)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class com.google.android.material.navigation.NavigationView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.bozorgan.MainActivity.onCreate(MainActivity.java:63)
at android.app.Activity.performCreate(Activity.java:6877)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
at android.app.ActivityThread.access$1100(ActivityThread.java:223) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7223) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class com.google.android.material.navigation.NavigationView
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:id="#+id/navigation_drawer">
<include layout="#layout/activity_main"/>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/navigation_view"
android:layoutDirection="rtl"
app:headerLayout="#layout/navigation_header"
android:layout_gravity="end"
app:menu="#menu/menu" />
</androidx.drawerlayout.widget.DrawerLayout>
Be sure to add the Drawerlayout library to the build.gradle(:app) file so you can use Drawerlayout.
If not, open the build.gradle(:app) file and add:
implementation "androidx.drawerlayout: drawerlayout: 1.1.1"
in AndroidX NavigationView requires these dependencies and also check out Documentation for more Information here
// Java language implementation
implementation "androidx.navigation:navigation-fragment:2.3.2"
implementation "androidx.navigation:navigation-ui:2.3.2"
// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:2.3.2"
implementation "androidx.navigation:navigation-ui-ktx:2.3.2"

App crashing android studio after moving project folder

Three weeks ago, I decided to move my project from the downloads folder on my Mac to my desktop. After moving the project, I realized that I wasn't able to even see anything from the project. So I decided to move the project back into the downloads folder when it originally was in, and I was able to check my project again but unfortunately I am not able to run the project on my phone and I am getting a strange error message that I am not able to find a solution for on the internet. I will show you the error message and some XML code of the activity as well.
XML code:
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="427dp"
android:layout_height="82dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="413dp"
android:layout_height="49dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/nav_view"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:navGraph="#navigation/mobile_navigation" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/home_view_message"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/nav_host_fragment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027" />
<Spinner
android:id="#+id/channel_spinner"
android:layout_width="409dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6"
app:layout_constraintVertical_bias="0.162" />
<Button
android:id="#+id/check_button"
android:layout_width="157dp"
android:layout_height="58dp"
android:text="#string/home_button_text"
app:layout_constraintBottom_toTopOf="#+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/channel_spinner"
app:layout_constraintVertical_bias="0.418" />
</androidx.constraintlayout.widget.ConstraintLayout>
Error message:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mychannels/com.example.mychannels.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6990)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
Build.gradle (app level):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.mychannels"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha05'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
File -> Invalidate caches/restart & try to import it. File -> new -> import project
I think you missed to add implementation 'com.google.android.material:material:1.1.0-alpha1' In your app gradle file. Just add this gradle inside
dependencies { } black and sync your project. Now, this error should be removed and aproject will run successfully.
After some searches about my problem and after trying many times to fix it, I re tried to delete the android:background="?android:attr/windowBackground" statement from the XML code, the app opened and ran without any problems on my phone. I tried to do so the first time when I opened this discussion but it didn't work. Thank you for helping me to solve my problem!
I ran into this problem recently and the only thing that truly helped me open a project after having moved it to another folder was to completely delete the build folder (that one located inside app folder) before launching Android Studio. Tested on Android Studio 4.1.3 / Windows 10.

Implementing countries to spinner in activity

I am trying to implement: https://github.com/hbb20/CountryCodePickerProject to my project to show a list of all countries in a spinner.
I added code to my build.gradle (app):
implementation 'com.hbb20:ccp:2.3.4'
After that I added it to XML file (layout) as it state on https://github.com/hbb20/CountryCodePickerProject/wiki/Use-as-a-Country-Selector:
<com.hbb20.CountryCodePicker
android:id="#+id/country"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
app:ccp_showFullName="true"
app:ccp_showNameCode="false"
app:ccp_showPhoneCode="false"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="0dp" />
When I run my application it looks like:
But when I click on the spinner to select country application crash and in Logcat I get an error:
2019-12-27 14:47:00.619 13536-13536/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cryptowallet, PID: 13536
android.view.InflateException: Binary XML file line #78: Binary XML file line #78: Error inflating class com.futuremind.recyclerviewfastscroll.FastScroller
Caused by: android.view.InflateException: Binary XML file line #78: Error inflating class com.futuremind.recyclerviewfastscroll.FastScroller
Caused by: java.lang.reflect.InvocationTargetException
Add below 2 lines in gradle.properties file.
android.useAndroidX=true
android.enableJetifier=true

Android ClassNotFoundException with appcompat-v7:28.0.0

I'm developing an Android application and I try to use the toolbar to add some functionality on it; that's why I'm using appcompat-v7 module.
I have followed this tutorial (Sorry because it's in spanish) and I have updated my IDE with the Compatibility Support package, I also added the new module to my Gradle file and I have updated the design XML of my app with this new toolbar (I can see this toolbar in the design editor).
But, when I launch my application, I get following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/base.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_resources_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(...
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.gomar.gomar_sanidad"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
A sample of my activity_main.xml with the toolbar(Design XML):
<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=".NuevaFicha">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
app:layout_constraintVertical_bias="0.0">
....
I have tried what is said here (Checked ids, Cleaned project, Invalidated caches...) but none of these solutions had the desired results. Do you have any idea?
Thanks in advance.
you are using both androidx and AppCompat hence the error.consider using either.
implementation 'com.android.support:appcompat-v7:28.0.0' //this is appcompat
implementation 'androidx.appcompat:appcompat:1.0.0-beta01' //this is android x
you can not use androidx and android support at the same time.
see how to migrate to androidX
Your project is initialized as androidx project! if you dont want to use androidX components first remove this line from your gradle.properties file :
android.useAndroidX=true
Then replace all androidx dependencies with appcompat versions.
if you started a simple empty project you dont need to refactor this project simply create a new appcompat project instead of androidx project.
If your gradle.properties file has the property set as below
android.useAndroidX=true
Replace
android.support.v7.widget.Toolbar
With
androidx.appcompat.widget.Toolbar

Categories