-3

The app I was working on so far was working fine until I added a couple of new activities and tried applied some changes to the theme.

The following is my styles.xml file. I looked into other results and added a parent to AppTheme as I was getting an error regarding AppCompat earlier. I also made AppTheme parent of NoActionBar. One thing I noticed was when I apply AppBarOverlay to Register User Activity it crashes and when I apply other it doesn't. Main Activity is crashing regardless.

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar" parent ="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

Below is the Android Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ati.activate">
<application
    android:allowBackup="true"
    android:icon="@drawable/footprintblue"
    android:label="@string/app_name"
    android:roundIcon="@drawable/footprintgreen"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

    <activity android:name=".UserManagement.LoginActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".UserManagement.RegisterUserActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.AppBarOverlay">
    </activity>

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
    </activity>

 </application>
</manifest>

I have applied AppTheme to android and then overridden the desired themes to other activities. Note: Login screen works and is using AppTheme.NoTitleBar, Register User works without AppBarOverLay theme but crashes when this theme is used.

This is my activity_main.xml file

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.ati.activate.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <!--android:paddingTop="@dimen/appbar_padding_top"-->

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:layout_scrollFlags="scroll|enterAlways">
    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/login_background" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

And this is the snippet of my MainActivity.Java file:

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.ati.activate.Fragments.SettingsFragment.AppSettingsFragment;
import com.ati.activate.Fragments.SettingsFragment.ProfileSettingsFragment;

public class MainActivity extends AppCompatActivity{
private AppPagerAdapter mAppPagerAdapter;
private ViewPager mViewPager;

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    createMenu();
}

I have tried every solution discussed on the internet but still have not found any solution. Could anyone please help? Thanking you in advance.

Below is the error when Register User Activity is opened with AppTheme.AppBarOverlay:

    12-08 04:55:08.217 17843-17850/? E/zygote: Failed writing handshake bytes (-1 
    of 14): Broken pipe
    12-08 04:55:16.704 17843-17986/com.ati.activate E/StudioProfiler: JVMTI 
    error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
    12-08 04:55:16.706 17843-17986/com.ati.activate E/StudioProfiler: JVMTI 
    error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
    12-08 04:55:16.818 17843-17843/com.ati.activate E/AndroidRuntime: FATAL 
    EXCEPTION: main
                                                                  Process: 
    com.ati.activate, PID: 17843

    java.lang.RuntimeException: Unable to start activity 

ComponentInfo{com.ati.activate/com.ati.activate.UserManagement.RegisterUserActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                      at android.os.Looper.loop(Looper.java:164)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                      at com.ati.activate.UserManagement.RegisterUserActivity.onCreate(RegisterUserActivity.java:13)
                                                                      at android.app.Activity.performCreate(Activity.java:6975)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                      at android.os.Looper.loop(Looper.java:164) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

And this is the error when Main Activity is opened:

12-08 04:59:50.431 21418-21586/com.ati.activate E/StudioProfiler: JVMTI 

error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
12-08 04:59:50.432 21418-21586/com.ati.activate E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
12-08 04:59:50.518 21418-21418/com.ati.activate E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.ati.activate, PID: 21418
                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ati.activate/com.ati.activate.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                      at android.os.Looper.loop(Looper.java:164)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                      at com.ati.activate.MainActivity.onCreate(MainActivity.java:26)
                                                                      at android.app.Activity.performCreate(Activity.java:6975)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                      at android.os.Looper.loop(Looper.java:164) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Saif
  • 723
  • 6
  • 21
Krishna Adhikari
  • 357
  • 1
  • 4
  • 9
  • please share your error – Shivam Oberoi Dec 08 '17 at 04:47
  • Hi @ShivamOberoi, I have updated the post to include the error. Thanks – Krishna Adhikari Dec 08 '17 at 05:01
  • Check this StackOverflow [thread](https://stackoverflow.com/q/21814825/5180017) – Shashanth Dec 08 '17 at 05:05
  • Try this link if error doesnt resolve the comment again. – Shivam Oberoi Dec 08 '17 at 05:08
  • Hi @ShivamOberoi, I am extending my activity to AppCompatActivity and using getSupport....() calls in my app. I do not want to switch to extending to Activity as the app was working earlier. I read through the link and tried to follow through but it did not solve my issue. I am guessing the problem lies in the style manifest and the xml file for main activity especially the theme around toolbar. I am not extending anything to ActionBar. No solutions in the internet seem to solve this issue :( – Krishna Adhikari Dec 08 '17 at 22:33

3 Answers3

0

change your manifest file :

<activity android:name=".UserManagement.RegisterUserActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.AppBarOverlay">
</activity>

to this :

<activity android:name=".UserManagement.RegisterUserActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
</activity>

i think your RegisterUserActivity problem will be solve...

UPDATE for your MainActivty Chnage style.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
Saif
  • 723
  • 6
  • 21
  • RegisterUserActivity is working with this fix however I am more concerned about the main activity as it is the one with the problem. :( – Krishna Adhikari Dec 08 '17 at 23:54
  • Hi @saif, Thanks for the reply. The answer didnot completely resolve the issue but did help me to ultimately find the solution. For some reason I had to use this : true true – Krishna Adhikari Dec 10 '17 at 08:04
0

Put this code in your style.xml

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

and don't add parent ="AppTheme" in the above code.

Paras Verma
  • 129
  • 9
  • That was the original code I had which was not working. I added the parent tag after reading a few stackoverflow threads. The app still crashes with this solution :( – Krishna Adhikari Dec 08 '17 at 23:53
0

It works with the following changes to the code:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>
Krishna Adhikari
  • 357
  • 1
  • 4
  • 9