I'm building a weather app using MVVM and retrofit and i recently added a PreferencesFragmentCompat subclass to implement some user settings using the preferences lib. After doing so, my app won't run and i keep getting these few lines of errors :
2020-04-08 00:54:12.346 18079-18079/? E/de.flogaweathe: Unknown bits set in runtime_flags: 0x8000
2020-04-08 00:54:12.410 18079-18079/com.nesoinode.flogaweather E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list com.nesoinode.flogaweather
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list oat
2020-04-08 00:54:12.422 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
I've got no idea what these are and i can't find any specific answers on stack or google.There are no indications on what is causing the error so i can't figure out if i'm doing something wrong or if it is a library issue. Any ideas?
Here's the SettingsFragment where i'm adding the preferences from an xml resource file :
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.settings_prefs)
}
}
And here's how i'm reading some values from the sharedPrefs:
class UnitProviderImpl(context: Context) : UnitProvider {
private val appContext = context.applicationContext
private val preferences:SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(appContext)
override fun getUnitSystem(): String {
val selectedUnitSystemName = preferences.getString(UNIT_SYSTEM_KEY,
UnitSystem.SI.name.toLowerCase(Locale.ROOT))
return selectedUnitSystemName!!
}
}
I managed to figure out a solution to the issue after doing some more research. Firstly, i commented out all the code related to the preferences library (and the lib itself) and run the app again. The run was successful without any errors so that narrowed it down to the androidx.preference:preference-ktx:1.1.0 library itself since my code was reviewed and couldn't find any issues with it. Looking through the preference docs i figured i could try out a beta or alpha version that may have fixed this issue. And lo and behold, after using the androidx.preference:preference-ktx:1.1.0-beta01 beta version and uncommenting the relative code, everything worked once again.
Related
With the first patch for AS Arctic Fox Jetpack Compose previews stopped working.
I'm getting this error for all previews - even older ones, which worked fine a while back:
android.content.res.Resources$NotFoundException: Could not resolve resource value: [some hex value]
Are here any quick fixes for this? Clearing caches and the usual stuff did not work.
EDIT:
Looks like the problem is not always present. Some preview started working, while other are still failing.
EDIT 2:
This is happening in dynamic feature modules, when there's a need for resources from the main module or painterResource() is being used (even is resource from the same module is to be displayed).
Same problem here with dynamic-modules project.
Inspired by above answer, I've made another temporary workaround while waiting for Compose team to fix this.
import androidx.compose.ui.res.stringResource as originalStringResource
#Composable
#ReadOnlyComposable
fun stringResourceSafe(#StringRes id: Int): String =
if (BuildConfig.DEBUG) {
val resources = LocalContext.current.resources
try {
resources.getString(id)
} catch (e: Resources.NotFoundException) {
"missing res."
}
} else {
originalStringResource(id)
}
This got fixed in AS Bumblebee, patch 2.
As a temporary hack workaround I did this to get past the error and preview the UI elements.
//import androidx.compose.ui.res.stringResource
fun stringResource(id: Int): String {
when (id) {
R.string.res_id -> return "Foo"
...
}
return "missing res_id"
}
After I updated Android Studio to 3.5, I am facing below warning whenever I build my Project.
Missing class: com.fasterxml.jackson.core.type.TypeReference
My project is using AndroidX. Here is the gist for my build.gradle(app)
https://gist.github.com/Arkar009/4ae5a05ff3435636bc605fee1fbdb050 . Can anyone know why this error occurs or alternative ideas to solve this error? Thanks in advances.
If you're super sure you will remember this line if you include Jackson later in your project, this does the trick (add it in your project's proguard-project.[txt|pro] file):
-dontwarn com.fasterxml.jackson.core.type.TypeReference
That class gets included somehow in the missing classes Set in R8 (I didn't go that far in R8's code), but you can skip the warning if you get that class in the list of patterns for "Don't Warn" rules (see com/android/tools/r8/R8.java):
List<ProguardConfigurationRule> synthesizedProguardRules = new ArrayList<>();
timing.begin("Strip unused code");
Set<DexType> classesToRetainInnerClassAttributeFor = null;
try {
Set<DexType> missingClasses = appView.appInfo().getMissingClasses();
missingClasses = filterMissingClasses(
missingClasses, options.getProguardConfiguration().getDontWarnPatterns());
if (!missingClasses.isEmpty()) {
missingClasses.forEach(
clazz -> {
options.reporter.warning(
new StringDiagnostic("Missing class: " + clazz.toSourceString()));
});
TBH, I was also bugged enough by this warning to get into R8, hope it helps!
I wrote my first Cucumber program today, and it fails. I wrote a very basic one, a simple scenario and it's step definition. Below is the feature file code and the step definition code.
Step Definiton code:
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
public class Testing_Example1 {
#When("^I am on x page$")
public void i_am_on_x_page() throws Throwable {
System.out.println("I am on xPage");
}
#Then("^I see that element$")
public void i_see_that_element() throws Throwable {
System.out.println("I can see that page");
}
}
Feature File Code:
Feature: Testing
Scenario: s1
When I am on x page
Then I see that element
I have added the system variables as well - The JAVA_HOME and the maven variables as well and linked it to the PATH variable I system variables.
I have added dependencies in the POM file, such as the Cucumber-Java, Cucumber-Junit and for selenium as well and yet my program fails and says the steps are undefined.
Output:
1 Scenarios (1 undefined)
2 Steps (2 undefined)0m0.000s
You can implement missing steps with the snippets below:
#When("^I am on x page$")
public void i_am_on_x_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#Then("^I see that element$")
public void i_see_that_element() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Undefined step: When I am on x page
Undefined step: Then I see that element
Process finished with exit code 0
I guess it's because my feature file is not getting linked with the step definition file, but I don't understand what is missing that the feature file does not execute properly and scenarios fail. Someone who has knowledge about this, do help.
Thank You!
I found the solution to this. I just edited the configuration of the feature file - > edit configurations -> Paste the path of the package in which your step definition file is present -> apply.
I just has to link the feature file to the step definition using Glue.
Specify the stepdefintion & feature file details in your cucumber runner class.
#CucumberOptions(
plugin={"pretty", "html:target/cucumber-html-report","json:target/cucumber-report.json"},
features = "src/test/resources",
glue ="com.vg.pw.ui.stepdefinitions",
)
public class CucumberRunner {
...
}
I just received an exception when I try to reference a static variable in another class, which is also statically initialized. This worked before, and for some reason it fails now. The only changes I made were resetting Visual Studio (2010) to its default setting, which I can't imagine to be the reason for this. Any other code I added didn't touch any of the affected parts either.
This is my code
WinForms class 'MainForm':
partial class MainForm : Form
{
// ...
private RefClass convMan;
private Dictionary<EnumType, string> LogNames = RefClass.LogNames;
// ...
public MainForm() { .... }
}
Referenced class 'RefClass':
class RefClass
{
// ...
public enum EnumType { TypeOne = 0, TypeTwo = 1, TypeThree = 2 };
public static Dictionary<EnumType, string> LogNames = new Dictionary<EnumType, string>()
{
{ EnumType.TypeOne, "Text0" },
{ EnumType.TypeTwo, "Text1" },
{ EnumTypy.TypeThree, "Text2" }
};
}
The error I get now is (translated from German):
An unhandled exception of type "System.TypeInitializationException" occurred.
Additional information: The type initializer for "RefClass" threw an exception.
which has the InnerException
System.ArgumentException
So, as far as I'm concerned, my static dictionary should be initialized once it gets accessed, thus when my Form class references it. I tried debugging to see if the static dictionary is initialized before it gets referenced in the Form class, which is not the case. Also, when I stop at a breakpoint for the reference line, the variable LogNames is null.
I'm really confused as to why this happens, it all worked before.
I found my error, the exceptions I got were quite misleading though. It was a problem with a different dictionary than the one I referenced. It probably didn't get initialized in the first place because something before that failed (If someone can clear this up, please feel free to do so!). Basically what I did wrong was using a two-directional dictionary and adding a value twice. This should normally produce a normal exception, but since it was done statically it got wrapped into a TypeInitializationException. I had a deeper look into the exact stacktrace of the inner exception and found where the exception originated from. Maybe this helps someone in the future...
I had a simular issue getting the same exception. Found that my static constructor for my utility class was generating the exception. Took some time locating since the description of the exception was misleading.
As #Yeehaw mentioned, it appears that the exception gets wrapped, so the common denominator here I would say is that the class/object is static.
We recently placed an MVC application in production that sometimes gives us unhandled errors that we cannot reproduce in our development environment. The web app keeps crashing on the same line but the inner exception gives different error messages. The line where it crashes is when a particular property is accessed (property accessor). But the inner exception gives us the following different errors:
Unable to cast object of type 'System.Int32' to type 'System.String'.
Index was outside the bounds of the array.
There is already an open DataReader associated with this Command which must be closed first.
We have a large number of users so I'm assuming that this has to do with concurrency or some type of thread problem? Can someone guide me in the right direction on how to find the problem?
By the way, it crashes always when accessing the same property. Sometimes it works other times it fails.
Here is the code for the accessor:
public string DepartementSelectionne
{
get
{
if (string.IsNullOrEmpty(m_departementSelectionne) == true)
if (ListeDepartements.FirstOrDefault() != null)
m_departementSelectionne = ListeDepartements.First().CodeDepartement;
return m_departementSelectionne;
}
set
{
m_departementSelectionne = value;
}
}
Thanks!