Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当startActivity(Intent)运行时,Context.getResources()返回null_Android_Nullpointerexception - Fatal编程技术网

Android 当startActivity(Intent)运行时,Context.getResources()返回null

Android 当startActivity(Intent)运行时,Context.getResources()返回null,android,nullpointerexception,Android,Nullpointerexception,最近对我的代码库进行了一些重大重构(主要是将类移动到新的包中),现在我在用户登录后尝试启动NavigationDrawer活动时出错 DistributorLogin运行一个asynctask来验证用户的凭据,并返回一个Distributor对象,该对象作为额外对象传递,目的是启动NavigationDrawer。在startActivity(Intent)运行后的某个时刻,设置活动时会调用Context.getResources()。资源对象似乎返回为null。有些设备在ContextThem

最近对我的代码库进行了一些重大重构(主要是将类移动到新的包中),现在我在用户登录后尝试启动NavigationDrawer活动时出错

DistributorLogin运行一个asynctask来验证用户的凭据,并返回一个Distributor对象,该对象作为额外对象传递,目的是启动NavigationDrawer。在startActivity(Intent)运行后的某个时刻,设置活动时会调用Context.getResources()。资源对象似乎返回为null。有些设备在ContextThemeWrapper.initializeTheme(int)中出现此错误,我也在Window.getDefaultFeatures(Context)中看到过在尝试检索布尔值时出现此错误。此问题仅在尝试启动NavDrawer活动时发生。其他活动似乎开始得不错。NavDrawer的onCreate()从未被调用

分销物流活动

@Override
public void distributorAuthenticationFinished(Distributor output) {

try {
        //Only continue if a valid Distributor object was received
        if (output != null) {

            String currentLanguage = "ENG";
            DistributorSettings distributorSettings = output.getDistributorSettings();
            if (distributorSettings != null) {
                String homeCountry = distributorSettings.getHomeCountry();
                currentLanguage = distributorSettings.getCurrentLanguage();
                Content.getInstance().setCurrentLocale(homeCountry, currentLanguage);
                writeContentDocs(homeCountry, currentLanguage, false);
                writeAllSupportedLanguageDocs();
            }

            //Clear UI element values
            etxt_name.setText("");
            etxt_password.setText("");

            //Attempt to register a new device token if one is not already saved.
            Intent tokenIntent = IntentCreator.getTokenRegistrationIntent(this, RegistrationTokenIntentService.CREATE_NEW_IF_NONE_EXISTS,
                    Distributor.distributorId, Distributor.homeCountry, currentLanguage);
            startService(tokenIntent);

            // Start the main activity
            Intent intent = new Intent(this, NavDrawer.class);
            intent.putExtra(getString(R.string.cb_parameter_distributor), output);
            startActivity(intent);

        }
    } catch (Exception e) {
        Log.e(TAG, "Error starting nav drawer activity.", e);
    }
}
Android清单

<manifest
    package="com.marketamerica.android.unfranchiseprospecting"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:name=".models.Ufp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:uiOptions="splitActionBarWhenNarrow">
        <activity
            android:name=".activities.DistributorLogin"
            android:label="@string/app_name_acronym"
            android:windowSoftInputMode="adjustPan">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.NavDrawer"
            android:label="@string/title_activity_nav_drawer"
            android:windowSoftInputMode="adjustPan"
            android:launchMode="singleTop"/>
    </application>
</manifest>
    09-07 15:48:51.644 24077-24077/com.marketamerica.android.unfranchiseprospecting E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.marketamerica.android.unfranchiseprospecting, PID: 24077
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.marketamerica.android.unfranchiseprospecting/com.marketamerica.android.unfranchiseprospecting.activities.NavDrawer}: 
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.res.Resources.newTheme()' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
    at android.app.ActivityThread.access$900(ActivityThread.java:182)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6141)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
    Caused by: java.lang.NullPointerException: 
    Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.res.Resources.newTheme()' on a null object reference
    at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:134)
    at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:85)
    at android.support.v7.app.AppCompatActivity.setTheme(AppCompatActivity.java:86)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2760)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879) 
    at android.app.ActivityThread.access$900(ActivityThread.java:182) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:145) 
    at android.app.ActivityThread.main(ActivityThread.java:6141) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
    09-07 15:48:51.644 24077-24077/com.marketamerica.android.unfranchiseprospecting E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.marketamerica.android.unfranchiseprospecting, PID: 24077
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.marketamerica.android.unfranchiseprospecting/com.marketamerica.android.unfranchiseprospecting.activities.NavDrawer}: 
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.res.Resources.newTheme()' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
    at android.app.ActivityThread.access$900(ActivityThread.java:182)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6141)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
    Caused by: java.lang.NullPointerException: 
    Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.res.Resources.newTheme()' on a null object reference
    at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:134)
    at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:85)
    at android.support.v7.app.AppCompatActivity.setTheme(AppCompatActivity.java:86)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2760)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879) 
    at android.app.ActivityThread.access$900(ActivityThread.java:182) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:145) 
    at android.app.ActivityThread.main(ActivityThread.java:6141) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)