android.content.res.Resources $ NotFoundException:资源ID#0x7f0d0034错误

时间:2019-07-19 14:09:56

标签: java android firebase robolectric

您好,我有以下代码:

App.java

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        MessiSDK.getInstance().setContext(this);
        FirebaseApp.initializeApp(this);
    }

}

Junit测试

@RunWith(RobolectricTestRunner.class)
public class CallTest {

    @Before
    public void setUp() throws Exception {}

    @Test
    @Config(application = App.class)
    public void connectToSocketTest() {
        if (BuildConfig.FLAVOR.equals("dev")) {

            Context context = MessiSDK.getInstance().getContext();

            assertNotNull(context);
            ...

AndroidManigest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="apps.dialoga.com.trident">

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.actions"
            android:resource="@xml/lint" />

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

问题是我执行该测试时遇到以下错误:

  

android.content.res.Resources $ NotFoundException:资源ID

     

0x7f0d0034

     在

  org.robolectric.shadows.ShadowLegacyAssetManager.getResName(ShadowLegacyAssetManager.java:1259)     在   org.robolectric.shadows.ShadowLegacyAssetManager.getResourcePackageName(ShadowLegacyAssetManager.java:1271)     在   android.content.res.AssetManager.getResourcePackageName(AssetManager.java)     在   android.content.res.Resources.getResourcePackageName(Resources.java:1665)     在   com.google.android.gms.common.internal.StringResourceValueReader。(未知   来源)   com.google.firebase.FirebaseOptions.fromResource(com.google.firebase:firebase-common @@ 17.0.0:160)     在   com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common @@ 17.0.0:296)     在apps..App.onCreate(App.java:18)在   org.robolectric.android.internal.AndroidEnvironment.lambda $ installAndCreateApplication $ 0(AndroidEnvironment.java:253)     在   org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:75)     在   org.robolectric.android.internal.AndroidEnvironment.installAndCreateApplication(AndroidEnvironment.java:253)     在   org.robolectric.android.internal.AndroidEnvironment.setUpApplicationState(AndroidEnvironment.java:149)     在   org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:298)     在   org.robolectric.internal.SandboxTestRunner $ 2.lambda $ evaluate $ 0(SandboxTestRunner.java:247)     在   org.robolectric.internal.bytecode.Sandbox.lambda $ runOnMainThread $ 0(Sandbox.java:89)     在java.util.concurrent.FutureTask.run(FutureTask.java:266)在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案