I am using NoNonsense-FilePicker for filtering the sd card for pdf files by extending the FilePickerActivity and creating a FilteredFilePickerFragment instance through it but i get an error related to an Image button in it's resources.
this is the File Picker Fragment Extender:
public class FilePickerFragmentExtender extends FilePickerActivity {
public FilePickerFragmentExtender() {
super();
}
#Override
protected AbstractFilePickerFragment<File> getFragment(#Nullable String startPath, int mode, boolean allowMultiple, boolean allowCreateDir, boolean allowExistingFile, boolean singleClick) {
AbstractFilePickerFragment<File> fragment = new FilteredFilePickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick);
return fragment;
}
}
and this is the Filtered File Picker Fragment:
public class FilteredFilePickerFragment extends FilePickerFragment {
private static final String TAG = "FilteredFilePickerFragm";
// File extension to filter on
private static final String EXTENSION = ".pdf";
public FilteredFilePickerFragment() {
super();
}
/**
* #param file
* #return The file extension. If file has no extension, it returns null.
*/
private String getExtension(#NonNull File file) {
String path = file.getPath();
int i = path.lastIndexOf(".");
if (i < 0) {
return null;
} else {
return path.substring(i);
}
}
#Override
protected boolean isItemVisible(final File file) {
boolean ret = super.isItemVisible(file);
if (ret && !isDir(file) && (mode == MODE_FILE || mode == MODE_FILE_AND_DIR)) {
String ext = getExtension(file);
return ext != null && EXTENSION.equalsIgnoreCase(ext);
}
return ret;
}
}
the error:
FATAL EXCEPTION: main
Process: com.pdfviewer.debug, PID: 15693
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pdfviewer.debug/com.pdfviewer.FilePickerFragmentExtender}: android.view.InflateException: Binary XML file line #90: Binary XML file line #90: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2684)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2751)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6186)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: android.view.InflateException: Binary XML file line #90: Binary XML file line #90: Error inflating class ImageButton
Caused by: android.view.InflateException: Binary XML file line #90: Error inflating class ImageButton
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f010031 a=-1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:528)
at android.widget.ImageView.<init>(ImageView.java:180)
at android.widget.ImageButton.<init>(ImageButton.java:84)
at android.widget.ImageButton.<init>(ImageButton.java:80)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:60)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:118)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:192)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at com.nononsenseapps.filepicker.AbstractFilePickerFragment.inflateRootView(AbstractFilePickerFragment.java:239)
at com.nononsenseapps.filepicker.AbstractFilePickerFragment.onCreateView(AbstractFilePickerFragment.java:165)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2239)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1332)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2063)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
com.pdfviewer.debug E/AndroidRuntime: at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:554)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1249)
at android.app.Activity.performStart(Activity.java:6701)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2751)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6186)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
I searched and found that it's related to the theme of the file-picker but also i didn't find anything wrong in the theme:
<style name="FilePickerTheme" parent="NNF_BaseTheme">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- Setting a divider is entirely optional -->
<item name="nnf_list_item_divider">?android:attr/listDivider</item>
<!-- Need to set this also to style create folder dialog -->
<item name="alertDialogTheme">#style/FilePickerAlertDialogTheme</item>
</style>
<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
colorss.xml:
<color name="colorPrimary">#3f51b5</color>
<color name="colorPrimaryDark">#303f9f</color>
<color name="colorAccent">#5495fd</color>
The problem was actually related to the theme I am applying to the parent activity of this fragment android:theme="#style/AppTheme" was causing the app to crash because the layout wasn't finding it's appropriate attributes and debugging xml is kinda tricky.
The ImageButton in the resources:
<ImageButton
android:id="#+id/nnf_button_ok_newfile"
// this style line is the cause
style="?attr/borderlessButtonStyle"
android:layout_width="48dp"
android:layout_height="48dp"
android:hint="#android:string/ok"
app:srcCompat="#drawable/nnf_ic_save_black_24dp"
android:tint="?attr/nnf_save_icon_color"/>
and the solution to this problem was to either change your Activity theme in the manifest to android:theme="#style/FilePickerTheme" which is bad for user experience to user different themes between activities, or the other solution which is to Override the onCreate method and set the theme before the creation of the activity happens as follows:
FilteredFilePickerFragment
#Override
public void onCreate(Bundle savedInstanceState) {
getActivity().setTheme(R.style.FilePickerTheme);
super.onCreate(savedInstanceState);
}
Related
I am working on an app in Android Studio, and after adding buttons to MainActivity to move to other activities, despite the fact that the layout shows up properly in the editor, I get the error which will be posted at the end. There are other activities in my project which I did not include, because the error refers to activity_main.xml, but I will include them if they are necessary to solve the problem.
Here is activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<ImageView
android:id="#+id/view_img_main_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/grocery_img_1" />
<Button
android:id="#+id/btn_inventory"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_below="#id/view_img_main_menu"
android:text="#string/btn_my_groceries_text"
android:theme="#style/BtnTheme" />
<Button
android:id="#+id/btn_shopping_list"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_below="#id/btn_inventory"
android:text="#string/btn_shopping_list_text"
android:theme="#style/BtnTheme" />
</RelativeLayout>
Here is MainActivity:
public class MainActivity extends AppCompatActivity {
private Button btnInventory;
private Button btnShopList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnInventory = findViewById(R.id.btn_inventory);
btnShopList = findViewById(R.id.btn_shopping_list);
btnInventory.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent inventoryIntent = new Intent(MainActivity.this, Inventory.class);
startActivity(inventoryIntent);
}
});
btnShopList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent shopListIntent = new Intent(MainActivity.this, ShoppingList.class);
startActivity(shopListIntent);
}
});
}
Here is the error I get awhen I try to run the code:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.grocerystatusapplication/com.example.grocerystatusapplication.MainActivity}: android.view.InflateException: Binary XML file line #15 in com.example.grocerystatusapplication:layout/activity_main: Binary XML file line #15 in com.example.grocerystatusapplication:layout/activity_main: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3344)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3488)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
at android.os.Handler.dispatchMessage(Han
E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:956)
Here is styles.xml:
<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>
<item name="android:windowBackground">#color/colorLayoutBackground</item>
</style>
<style name="BtnTheme" parent="TextAppearance.AppCompat.Widget.Button.Colored">
<item name="colorButtonNormal">#color/colorViewBackground</item>
</style>
<style name="TextViewTheme" parent="">
<item name="android:background">#drawable/rounded_corners</item>
<item name="android:textColor">#android:color/white</item>
</style>
I have tried changing the attributes of the Button that the error refers to (line 15, btn_inventory), but I did not get anywhere. Did not come across this error before and don't really understand what is the problem. What can I change to make it work? After looking through posts about the same error, I did not get an answer to my question, there seemed to be a quite a few reasons this error came up.
In both Button tags change
android:theme="#style/BtnTheme"
to
style="#style/BtnTheme"
This question already has answers here:
This Activity already has an action bar supplied by the window decor
(25 answers)
Closed 3 years ago.
I want change app theme from code but it doesn't work .
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.NightMode);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar)
Errors
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.w7orld.animex, PID: 23421
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.w7orld.animex/com.w7orld.animex.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
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: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.support.v7.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:345)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
at com.w7orld.animex.MainActivity.onCreate(MainActivity.java:70)
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)
I found way to do that. In onCreate i put this
setTheme(Designs.getThemeNoActionBar(this));
setContentView(R.layout.activity_main);
get the theme from shared preferences and return theme without actionbar.
public static int getThemeNoActionBar(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences("Designs", Context.MODE_PRIVATE);
int theme = sharedPreferences.getInt("theme", R.style.AppTheme);
if (theme == nightModeTheme)
return R.style.NightMode_NoActionBar;
else if (theme == theme1)
return R.style.Theme1_NoActionBar;
else
return R.style.AppTheme_NoActionBar;
}
In style res
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="NightMode.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme1.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
We set the Night-mode like this:
public class App extends Application {
public static final String TAG = "App";
private boolean isNightModeEnabled = false;
#Override
public void onCreate() {
super.onCreate();
// We load the Night Mode state here
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
this.isNightModeEnabled = mPrefs.getBoolean(“NIGHT_MODE”, false);
}
public boolean isNightModeEnabled() {
return isNightModeEnabled;
}
public void setIsNightModeEnabled(boolean isNightModeEnabled) {
this.isNightModeEnabled = isNightModeEnabled;
}
}
As this instance will be launched before everything else, you will be able to call isNightModeEnabled() whenever you want and as such, in any Activity once your app is opened.
public final class FeedActivity extends AppCompatActivity {
private final static String TAG = “FeedActivity”;
#Override
protected void onCreate(Bundle savedInstanceState) {
if (MyApplication.getInstance().isNightModeEnabled()) {
setTheme(R.style.FeedActivityThemeDark);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feed);
}
}
How to work with night-mode in Android is posted here
Here is some example pictures showing the difference between cycling though light and night mode:
The first problem that's visible is the placement of these lines:
setTheme(R.style.NightMode);
setContentView(R.layout.activity_main);
You must always place the setContentView(layout) call immediately after the super.onCreate(savedInstanceState);. Because this is the code that's generating the layout and its views.
I tried to create a game show the pictures and list of character name it. But when I run the app, it keeps crashing and show the error:
Error inflating class android.support.design.widget.AppBarLayout.
Here is the log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.celebguess, PID: 3166
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.celebguess/com.example.user.celebguess.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.AppBarLayout
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: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.AppBarLayout
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.design.widget.AppBarLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.AppBarLayout" on path: DexPathList[[zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/base.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.user.celebguess.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
E/AndroidRuntime: 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)
Here is the activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.example.user.celebguess.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
/>
Also here is the styles.xml:
<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">
<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" />
Also here is the main_activity.java for the Java part:
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
private GridView gridView;
private SharedPreferences preferences;
private ArrayAdapter<String> names;
private Toast currentToast;
private ImageView img;
private int numberOfChoice;
private ArrayList<String> nameList;
private ArrayList<Integer> photos;
private ArrayList<String> nameForChoose;
private Map<String,Integer> nameMap;
private int currentPicNumber;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
#Override
protected void onStart() {
super.onStart();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
int orientation = getResources().getConfiguration().orientation;
if(orientation== Configuration.ORIENTATION_PORTRAIT) {
getMenuInflater().inflate(R.menu.menu_main, menu);
}
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
Intent intent = new Intent(this,Settings.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
For latest version of android, in build.gradle(app)
implementation 'com.android.support:design:30.0.0'
and for usage, in your .xml:
<com.google.android.material.appbar.AppBarLayout
Add below to bulid.gradle:app module :
implementation 'com.android.support:design:28.0.0'
## design library here you can copy and add to your build.gradle file
implementation 'com.android.support:design:28.0.0'
I have a CustomEditText extends EmojiEditText which extends AppCompatEditText and deriving https://github.com/vanniktech/Emoji library.
I used to ComposeEditText style for CustomEditText. But if I add this style, app is crashing. Please help me.
My edittext style:
<style name="ComposeEditText" parent="#style/Widget.AppCompat.EditText">
<item name="android:padding">2dp</item>
<item name="android:background">#null</item>
<item name="android:maxLines">4</item>
<item name="android:maxLength">2000</item>
<item name="android:capitalize">sentences</item>
<item name="android:autoText">true</item>
<item name="android:gravity">center_vertical</item>
<item name="android:imeOptions">flagNoEnterAction</item>
<item name="android:inputType">textAutoCorrect|textCapSentences|textMultiLine</item>
</style>
My edittext in xml:
<com.android.android.util.view.CustomEditText
android:id="#+id/editText"
style="#style/ComposeEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
app:emojiSize="#dimen/emojiSize" />
in code:
public class CustomEditText extends EmojiEditText {
public CustomEditText(Context context) {
super(context);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
#SuppressLint("DrawAllocation")
#Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
}
Error log:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.android.android/com.android.android.conversation.a.PRofile}:
android.view.InflateException: Binary XML file line #0:
Binary XML file line #0: Error inflating class com.android.android.util.view.CustomEditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
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:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.android.android.util.view.CustomEditText
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.android.android.util.view.CustomEditText
Caused by: java.lang.reflect.InvocationTargetException
Seeing your CustomEditText which is EmojiEditText, please try to set the parent of your style to EmojiEditText's style. I think the issue is your style is inheriting from wrong style
I just remove "#style/" and it is solved. Thank you for your help
instead of
<style name="ComposeEditText" parent="#style/Widget.AppCompat.EditText">
use
<style name="ComposeEditText" parent="Widget.AppCompat.EditText">
I keep on getting this error when I try to setErrorEnabled on my textInputLayout :
03-12 12:29:03.206 5706-5706/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 5706
java.lang.RuntimeException: Failed to resolve attribute at index 24
at android.content.res.TypedArray.getColor(TypedArray.java:401)
at android.widget.TextView.<init>(TextView.java:696)
at android.widget.TextView.<init>(TextView.java:632)
at android.widget.TextView.<init>(TextView.java:628)
at android.widget.TextView.<init>(TextView.java:624)
at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
at com.bekwaai.popupwindow.RGNamePopUp$1.onClick(RGNamePopUp.java:48)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
This is the scenario - I have a textInputLayout inside a popupwindow. This is the code inside the popupwidow.
public class NamePopUp extends PopupWindow {
android.support.v7.widget.AppCompatEditText name;
TextInputLayout nameInput;
public NamePopUp(final Context context) {
super(context);
View popupView = LayoutInflater.from(context).inflate(R.layout.popup_rg_confirm, null);
nameInput = (TextInputLayout) popupView.findViewById(R.id.name_input_layout);
}
}
This is my xml for the popupwindow layout:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:theme="#style/TextLabel"
app:backgroundTint="#color/white"
app:rippleColor="#color/white"
android:id="#+id/name_input_layout"
android:layout_marginBottom="8dp"
android:paddingRight="24dp"
android:paddingLeft="24dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/enter_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textCursorDrawable="#drawable/color_cursor"
android:hint="#string/groupname"/>
</android.support.design.widget.TextInputLayout>
This is the style I'm using:
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textSize">20sp</item>
<item name="android:textColorHint">#color/white</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/white</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
</style>
The popupwindow is called inside a android.support.v4.app.Fragment and the fragment is inside a AppCompatActivity.
The error occurs here when the user clicks the ok button but the name edittext is blank. In other words, the user has not entered anything in the edittext and have clicked ok:
button_ok.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (StringUtils.isNotEmpty(name.getText().toString())) {
nameInput.setErrorEnabled(false);
groupNameEvent.doEvent(name.getText().toString());
} else {
nameInput.setErrorEnabled(true); //ERROR OCCURS HERE!
nameInput.setError(context.getString(R.string.no_name));
}
}
});
How do I get this error to disappear?
Just change the base theme for TextLabel to Widget.Design.TextInputLayout
<style name="TextLabel" parent="Widget.Design.TextInputLayout">
For me a following works (https://stackoverflow.com/a/42779409/2914140):
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="textColorError">#color/design_textinput_error_color_light</item>
</style>