Unable to run JUnit Test… Java.lang.ExceptionInInitializerError (Android Studio)

Unable to run JUnit Test… Java.lang.ExceptionInInitializerError (Android Studio)

Questions : Unable to run JUnit Test… Java.lang.ExceptionInInitializerError (Android Studio)

177

I’m trying to implement a JUnit test in in4codes_android-studio Android Studio. I’m constantly getting in4codes_android-studio those errors:

java.lang.ExceptionInInitializerError at de.dhbw.camfinder.activities.FilterSurveillanceCameraOnMapActivity.onCreate(FilterSurveillanceCameraOnMapActivity.java:67) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:730) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 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:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.Context.getAssets()' on a null object reference at de.dhbw.camfinder.enums.SurveillanceObjectEnum.<init>(SurveillanceObjectEnum.java:27) at de.dhbw.camfinder.enums.SurveillanceObjectEnum.<clinit>(SurveillanceObjectEnum.java:12) 

My test file:

import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import de.dhbw.camfinder.R; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; @RunWith(AndroidJUnit4.class) public class FilterSurveillanceCameraOnMapActivityTest { @Rule public ActivityScenarioRule<FilterSurveillanceCameraOnMapActivity> activityRule = new ActivityScenarioRule<>(FilterSurveillanceCameraOnMapActivity.class); @Test public void test_isCameraIconVisible(){ onView(withId(R.id.textView)).check(matches(isDisplayed())); } } 

My gradle file:

apply plugin: 'com.android.application' android { signingConfigs { release { keyAlias = 'release' storePassword 'I+f+rm#t7kDhbwStut*gar#Projekto4Le#n+and+tuhlT5epp#Le2ne*Ba+hel2rM+ste3*a14ee' keyPassword 'I+f+rm#t7kDhbwStut*gar#Projekto4Le#n+and+tuhlT5epp#Le2ne*Ba+hel2rM+ste3*a14ee' storeFile file('\Users\NoName\Documents\My_Documents\Duales_Studium\5_Semester\Studienarbeit\camfinder\documentation\Camfinder-App_Keystore\Camfinder-App_Key.jks') } } compileSdkVersion 29 defaultConfig { applicationId "dhbw.de.camfinder" minSdkVersion 23 targetSdkVersion 29 versionCode 1 versionName '5.2' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" signingConfig signingConfigs.release } buildTypes { debug { applicationIdSuffix ".debug" debuggable true } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { // Allows the logging tag to be more than 23 characters long. Normally the logging tag is limited to the length of maximum 23 characters disable 'LongLogTag' } } dependencies { implementation 'androidx.appcompat:appcompat:1.2.0-alpha02' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation "androidx.preference:preference:1.1.0" implementation 'com.google.android.material:material:1.2.0-alpha05' implementation 'com.google.android.material:material:1.1.0' implementation 'com.google.android.gms:play-services-maps:17.0.0' //implementation fileTree(dir: 'libs', include: ['*.jar']) //testImplementation 'junit:junit:4.13' //androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' //TODO remove implementation 'com.github.MKergall:osmbonuspack:6.4' implementation 'com.github.uin3566:AllAngleExpandableButton:v1.2.0' implementation 'com.github.clans:fab:1.6.4' implementation 'com.github.MKergall:osmbonuspack:6.4' implementation 'org.osmdroid:osmdroid-android:5.6.5' implementation 'androidx.test.ext:junit:1.1.3' //implementation 'androidx.test.ext:junit:1.1.3' //implementation 'androidx.test.ext:junit:1.1.3' //implementation 'org.osmdroid:osmdroid-android:[email protected]' //Testing dependencies androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:rules:1.4.0' } 

The tests are always failing. I tried in4codes_android-studio anything I can think of, but I´m in4codes_android-studio quite new to the whole world of testing and in4codes_android-studio android development. If you need more in4codes_android-studio information on something, just point it out.

Thanks in advance for your help.

Total Answers 0