Getting InstantiationException: Unable to instantiate fragment Error after changing system font - java

The app is crashing when the app is in the background and I changed the font and open the app again.
Getting Below error
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment could not find Fragment constructor
Steps
Open the bottom sheet dialog CategoriesBottomSheetDialog
Minimize the application (in the background)
Changed font
Open the app again
I can provide a fix using bundle but I want to know if using kotlin plugin no-arg concept can apply this annotation on CategoriesBottomSheetDialog and allow the class to be invoked with the empty constructor.
#NoArg
class CategoriesBottomSheetDialog(
override val di: DI,
screenType: MainScreenType
) : DIAware, BottomSheetDialogFragment() {}
I tried but not working even though the root cause is unable to invoke an empty constructor. Any inputs on this note to kind of solve without using bundle?

Related

Android Studio show me the Error load: id=gralloc != hmi->id=gralloc

My IDE shows me the error even is empty project. As you can see I create the new project with empty activity. App is launched in mobile successfully and work fine. but logcat isn't working properly or any thing else I'm stuck help me out. And when I connect my mobile even I didn't build the project logcat is full of instruction/logs.
UPDATE:
First, gralloc stands for the low-level graphics buffer allocator.
The gralloc is part of the HAL (Hardware Abstraction Layer) which
means that the implementation is platform-specific. You can find the
interface definitions in
hardware/libhardware/include/hardware/gralloc.h. As expected from a
HAL component, the interface is divided into a module interface
(gralloc_module_t) and a device interface (alloc_device_t).
The error is very low level and related with OpenGLRenderer. Your device is trying to open some 64-bit library files, but if fails. Then the error occurs.
I did very deep search about this but nothing useful came up.
Try running apps on another devices and see the error occurs again.
Continue developing if the error is not causing crash or other important issue. If you find a solution, you will try again.
in my case, I tried to use Application class static context for calling new Activity and I changed it to local static Activity and problem solved.
Notice that this problem doesn't happen in all devices it just occur in some cases.
private static MainActivity u_static;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);
u_static = this;
}
public static void new(int id, String name){
Intent i = new Intent(u_static, NewActivity.class);
u_static.startActivity(i);
}
And something I notice that in some devices when an application stops working instead of showing error, this error happens. Trace and debug your codes.
About the crazy E/HAL: load: id=gralloc != hmi->id=gralloc
Reason for error: Generally, it is caused by the fact that the control object is not fetched, the click event of the control is executed, and the null value is related to the initialization control.
As
private Button bt;
bt.setOnclickListener(new OnClickLisenter(){....});
Is there a problem? Yes!
xml layout control
Check if the findViewById() is missing in the java code!
    The above leaked bt = (Button) findViewById(R.id...);
java dynamic new control / custom control error
     Check if you forgot to create the object!
     The above leaked bt = new Button();
So the correct way to change the above code is:
private Button bt;
bt=(Button)findViewById(R.id...);
I encountered this issue while using runnable and passing an unassigned view.
This is caused by an empty view object where findViewById returns a null value.
Instead of passing the view object passing the value the view holds resolved the issue.

Android EditTextPreference custom dialog: Add functionality to button

I am trying to add a preference which will store a top level path so that they app can auto-discover some files in that directory on the phone. I have added an EditTextPreference and changed the dialog of it so that it has a button as well as a text box.
<EditTextPreference android:id="#+id/etpTopLevelAutoDiscoverPath"
android:key="settings_top_level_AutoDiscover_path"
android:summary=""
android:title="Location to search for custom configurations"
android:dialogLayout="#layout/preference_browse_to_path"
android:defaultValue=""/>
I am struggling however gaining access to the button to add a click listener to it. I think my main problem is that I can't instantiate the custom dialogs view because I don't know when the dialog for EditTextPreference is displayed.
This is how I am attempting to set the get the button object but obviously when it gets to creating the button it crashes because the view doesn't exist.
View browseToPathView = this.findViewById(R.id.browseToPathView);
Button browse = (Button)browseToPathView.findViewById(R.id.btnRootBrowse);
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dtg.cinet/com.dtg.cinet.PreferencesScreen}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
I am fairly new to android and have come into a project midway so it is entirely possible that I am just not doing it in the right way but I am fairly stuck at the moment and can't figure out what to do.

android.widget.TextView.setTextAlignment(): java.lang.NoSuchMethodError

Situation:
I have a TextView that have the property
android:textAlignment="center"
I am generating another TextView dinamically, based on my TextView from XML Layout, using a clone, cloning all the basic properties to work the way above.
Problem:
To do this i need to use this method:
this.myTextView.setMyTextViewProperty(MyTextView.getMyTextViewProperty());
for example:
this.MyTextView.setText(MyTextView.getText());
Note that this.MyTextViewis a local variable and MyTextView is a private var declared on the top of the file, under class name.
I do this on all the properties of the TextView but when i hit the following line of code from the TextAlignment property...:
this.myTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
I tried to set it to a Custom Aligment instead of getting from my XML TextView It gives me an error:
11-20 15:27:04.460: E/AndroidRuntime(9185): FATAL EXCEPTION: main
11-20 15:27:04.460: E/AndroidRuntime(9185): java.lang.NoSuchMethodError: android.widget.TextView.setTextAlignment
But i see on Ctrl + Space that the method exists, so i cant understand what is happening.
A second try was, to set my TextView property to the property that comes from my TextView:
this.myTextView.setTextAlignment(MyTextView.getTextAlignment());
With no success, too.
Obs: i do not want a Android XML Layout solution, i want a solution on code, because i generate the TextView dinamically on the Activity
I'm using API Level 15
Any help?
The setTextAlignment method was added in API level 17. Maybe your compiler in the IDE is above 17 and the device/emulator which you are testing is less than that. Here the link to setTextAlignment.
Added from the comments:
For API level 15 and below, you want setGravity, per this question.

java/nio/charset/Charsets error in Android Studio using DatePicker

I receive this error in Android Studio when I try to render a DatePicker:
Rendering Problems Exception raised during rendering: java/nio/charset/Charsets
When I delete the DataPicker from raw XML the error dissappears and I can work normally with my layout, but as soon as I try to add a DataPicker this error appears and I cannot see any component in the Component Tree, nor any activity in the activity view (where I operate with the design of my layout).
I'm using API 16 to render the layout (since APIs 17 & 18 are broken with CalendarView & DataPicker) and for locale I have es-ES.
What can I do to solve this error or, at least, be able to work in Design view with a DataPicker?

Custom multitab FormEditor - resource change

In my Eclipse-RCP I'm using a custom implementation of the FormEditor which consists of two parts/tabs, a normal TextEditor and a custom FormPage. Saving and everything works fine, however if the tabs are switched (and the resources/file has been saved before) I don't get the changes (usually eclipse displays a message like "Resource... has been changed... Reload"). I registered a ResourceChangeListener on the workspace and I get the changes from the TextEditor (but not from the FormPage), but I still don't get a message when I switch tabs.
Thanks

Categories