public class PropHolder {
public static Properties prop;
static {
//code for loading properties from file
}
}
// Referencing the class somewhere else:
Pr
I had the same exception, this is how I solved the problem:
Preconditions:
Junit class (and test), that extended another class.
ApplicationContext initialized using spring, that init the project.
The Application context was initialized in @Before method
Solution:
Init the application context from @BeforeClass method, since the parent class also required some classes that were initialized from within the application context.
Hope this will help.
I had the same exception - but only while running in debug mode, this is how I solved the problem (after 3 whole days): in the build.gradle i had : "multiDexEnabled true" set in the defaultConfig section.
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 15
targetSdkVersion 28
versionCode 5123
versionName "5123"
// Enabling multidex support.
multiDexEnabled true
}
but apparently this wasn't enough. but when i changed:
public class MyAppClass extends Application
to:
public class MyAppClass extends MultiDexApplication
this solved it. hope this will help someone
If you're working on an Android project, make sure you aren't calling any static methods on any Android classes. I'm only using JUnit + Mockito, so maybe some other frameworks might help you avoid the problem altogether, I'm not sure.
My problem was calling Uri.parse(uriString)
as part of a static initializer for a unit test. The Uri class is an Android API, which is why the unit test build couldn't find it. I changed this value to null
instead and everything went back to normal.
As mentioned above, this could be a number of things. In my case I had a statically initialized variable which relied on a missing entry in my properties file. Added the missing entry to the properties file and the problem was solved.