I'm developing a basic equation balancing app and am new to android dev. The app does not run on the phone at all. I had a splash screen as launcher previously and that used to pop and the app would shut off after that. I removed the Splash Screen and now the app won't open. I'm guessing there is an error in MainActivity (the splash screen used to intent to it and now it is the launcher activity). But on running the logcat alongside ADB emulation, it shows error in onCreate method of MainActivity. There are some more errors in logcat but I don't know what they mean(I guess the only error that matters is the onCreate one with a blue underline). Please Please do Help.
MainActivity.java
public class MainActivity extends AppCompatActivity implements DialogCloseListener {
private RecyclerView taskRecyclerView;
private EqBalAdapter tasksAdapter;
private List<EqBalModel> taskList;
private DatabaseHandler db;
private FloatingActionButton fab;
private FloatingActionButton fab2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00d024")));
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.nav_bottom);
navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_home:
break;
case R.id.nav_aboutus:
Intent a = new Intent(MainActivity.this, AboutUs.class);
startActivity(a);
break;
case R.id.nav_help:
Intent b = new Intent(MainActivity.this,HelpGuide.class);
startActivity(b);
break;
}
return false;
}
});
db = new DatabaseHandler(this);
db.openDatabase();
taskList = new ArrayList<>();
taskRecyclerView = findViewById(R.id.reacRecyclerView);
taskRecyclerView.setLayoutManager(new LinearLayoutManager(this));
tasksAdapter = new EqBalAdapter(db, this);
taskRecyclerView.setAdapter(tasksAdapter);
fab = findViewById(R.id.fab);
ItemTouchHelper itemTouchHelper = new
ItemTouchHelper(new RecyclerItemTouchHelper(tasksAdapter));
itemTouchHelper.attachToRecyclerView(taskRecyclerView);
taskList = db.getAllTasks();
Collections.reverse(taskList);
tasksAdapter.setTasks(taskList);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AddNewTask.newInstance().show(getSupportFragmentManager(), AddNewTask.TAG);
}
});
fab2=findViewById(R.id.newactivity);
ItemTouchHelper itemTouchHelper2 = new
ItemTouchHelper(new RecyclerItemTouchHelper(tasksAdapter));
itemTouchHelper2.attachToRecyclerView(taskRecyclerView);
fab2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent2 = new Intent(MainActivity.this, eleView.class);
startActivity(intent2);
}
});
}
@Override
public void handleDialogClose(DialogInterface dialog) {
taskList = db.getAllTasks();
Collections.reverse(taskList);
tasksAdapter.setTasks(taskList);
tasksAdapter.notifyDataSetChanged();
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/ReactantText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="Equation Balancer"
android:textColor="@android:color/black"
android:textSize="32dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/reacRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/ReactantText"
android:nestedScrollingEnabled="true"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="183dp"
android:backgroundTint="@android:color/holo_green_dark"
android:src="@drawable/ic_baseline_add" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/newactivity"
android:layout_width="86dp"
android:layout_height="82dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="56dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="34dp"
android:layout_marginBottom="97dp"
android:backgroundTint="@android:color/holo_green_dark"
android:src="@drawable/ic_baseline_elements" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nav_bottom"
android:layout_alignParentBottom="true"
app:itemTextColor="@android:color/black"
app:menu="@menu/drawer_view" />
</RelativeLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chemicalequationbalancer">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ChemicalEquationBalancer">
<activity android:name="com.example.chemicalequationbalancer.AboutUs" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<activity android:name="com.example.chemicalequationbalancer.HelpGuide" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<activity android:name="com.example.chemicalequationbalancer.eleView" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<activity
android:name="com.example.chemicalequationbalancer.MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.ChemicalEquationBalancer.ActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle(app):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chemicalequationbalancer">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ChemicalEquationBalancer">
<activity android:name="com.example.chemicalequationbalancer.AboutUs" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<activity android:name="com.example.chemicalequationbalancer.HelpGuide" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<activity android:name="com.example.chemicalequationbalancer.eleView" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<activity
android:name="com.example.chemicalequationbalancer.MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.ChemicalEquationBalancer.ActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat
Here's the underlined line in logcat: com.example.chemicalequationbalancer.MainActivity.onCreate(MainActivity.java:51)
2021-02-16 02:07:50.712 13502-13502/com.example.chemicalequationbalancer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.chemicalequationbalancer, PID: 13502
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chemicalequationbalancer/com.example.chemicalequationbalancer.MainActivity}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3197)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3334)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2025)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:226)
at android.app.ActivityThread.main(ActivityThread.java:7191)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Caused by: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:652)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:817)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:890)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:851)
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 com.android.internal.policy.DecorView.onResourcesLoaded(DecorView.java:2239)
at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2761)
at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2868)
at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2133)
at androidx.appcompat.app.AppCompatActivity.initViewTreeOwners(AppCompatActivity.java:198)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:173)
at **com.example.chemicalequationbalancer.MainActivity.onCreate(MainActivity.java:51)**
at android.app.Activity.performCreate(Activity.java:7376)
at android.app.Activity.performCreate(Activity.java:7367)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3177)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3334)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2025)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:226)
at android.app.ActivityThread.main(ActivityThread.java:7191)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
2021-02-16 02:07:50.714 13502-13502/com.example.chemicalequationbalancer E/AndroidRuntime: Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x1010433 a=1}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
at android.view.View.<init>(View.java:5108)
at android.view.ViewGroup.<init>(ViewGroup.java:665)
at android.widget.FrameLayout.<init>(FrameLayout.java:92)
at android.widget.FrameLayout.<init>(FrameLayout.java:87)
at android.widget.FrameLayout.<init>(FrameLayout.java:82)
at com.android.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:61)
... 32 more
If any other files are needed, I am ready to provide. I just want to know what is happening and sort it out. Thanks!
EDIT: themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ChemicalEquationBalancer" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@android:color/transparent</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.ChemicalEquationBalancer.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.ChemicalEquationBalancer.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.ChemicalEquationBalancer.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
</style>
<style name="Theme.ChemicalEquationBalancer.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="DialogStyle" parent="Theme.Design.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
</resources>
Your MainActivity is extending AppCompatActivity which means it inherits the default action bar.
ThemeOverlay.AppCompat(parent for Theme.ChemicalEquationBalancer.ActionBar) is used to override (or “overlay”) that theme for specific views, especially the Toolbar.
If you want to customize this ActionBar (you are probably doing that), you add one of the NoActionBar themes in your activity's manifest and then supply a toolbar to your activity's layout.
<activity
android:name="com.example.chemicalequationbalancer.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.Light.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In your activity_main.xml, you can add whatever theme you want
<androidx.appcompat.widget.Toolbar
...
android:background="?attr/colorPrimary"
android:theme="@style/Theme.ChemicalEquationBalancer.ActionBar />
And not in the manifest file