为什么变量应用程序返回null,抛出空指针异常?我正在尝试修改KP Android应用程序,并且无法通过登录屏幕,因为它会抛出此错误。
08-07 23:55:51.229: E/AndroidRuntime(14870): FATAL EXCEPTION: main
08-07 23:55:51.229: E/AndroidRuntime(14870): Process: com.bernard.beaconportal.activities, PID: 14870
08-07 23:55:51.229: E/AndroidRuntime(14870): java.lang.NullPointerException: No application instance given
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.bernard.beaconportal.activities.mail.store.StorageManager.<init>(StorageManager.java:525)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.bernard.beaconportal.activities.mail.store.StorageManager.getInstance(StorageManager.java:497)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.bernard.beaconportal.activities.Account.<init>(Account.java:272)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.bernard.beaconportal.activities.Preferences.newAccount(Preferences.java:113)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.bernard.beaconportal.activities.activity.setup.AccountSetupBasics.onManualSetup(AccountSetupBasics.java:309)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.bernard.beaconportal.activities.activity.setup.AccountSetupBasics.onNext(AccountSetupBasics.java:272)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.bernard.beaconportal.activities.activity.setup.AccountSetupBasics.onClick(AccountSetupBasics.java:349)
08-07 23:55:51.229: E/AndroidRuntime(14870): at android.view.View.performClick(View.java:4466)
08-07 23:55:51.229: E/AndroidRuntime(14870): at android.view.View$PerformClick.run(View.java:18827)
08-07 23:55:51.229: E/AndroidRuntime(14870): at android.os.Handler.handleCallback(Handler.java:808)
08-07 23:55:51.229: E/AndroidRuntime(14870): at android.os.Handler.dispatchMessage(Handler.java:103)
08-07 23:55:51.229: E/AndroidRuntime(14870): at android.os.Looper.loop(Looper.java:193)
08-07 23:55:51.229: E/AndroidRuntime(14870): at android.app.ActivityThread.main(ActivityThread.java:5299)
08-07 23:55:51.229: E/AndroidRuntime(14870): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 23:55:51.229: E/AndroidRuntime(14870): at java.lang.reflect.Method.invoke(Method.java:515)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
08-07 23:55:51.229: E/AndroidRuntime(14870): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
08-07 23:55:51.229: E/AndroidRuntime(14870): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
08-07 23:55:51.229: E/AndroidRuntime(14870): at dalvik.system.NativeStart.main(Native Method)
现在这里是logcat中引用的行:
K9.app初始化的地方,抱歉没有在
之前发布/**
* Register a component to be notified when the {@link K9} instance is ready.
*
* @param component
* Never <code>null</code>.
*/
public static void registerApplicationAware(final ApplicationAware component) {
synchronized (observers) {
if (sInitialized) {
component.initializeComponent(K9.app);
} else if (!observers.contains(component)) {
observers.add(component);
}
}
}
Storage Manager中的第517-526行
/**
* @param application
* Never <code>null</code>.
* @throws NullPointerException
* If <tt>application</tt> is <code>null</code>.
*/
protected StorageManager(final Application application) throws NullPointerException {
if (application == null) {
throw new NullPointerException("No application instance given");
}
Storage Manager中的第495-500行
public static synchronized StorageManager getInstance(final Application application) {
if (instance == null) {
instance = new StorageManager(application);
}
return instance;
}
帐户中的第272行
mLocalStorageProviderId = StorageManager.getInstance(K9.app).getDefaultProviderId();
首选项中的第112-118行
public synchronized Account newAccount() {
newAccount = new Account(K9.app);
accounts.put(newAccount.getUuid(), newAccount);
accountsInOrder.add(newAccount);
return newAccount;
}
AccountSetupBasics中的第308-310行
if (mAccount == null) {
mAccount = Preferences.getPreferences(this).newAccount();
}
AccountSetupBasics中的第262-274行
protected void onNext() {
String email = mEmailView.getText().toString();
String[] emailParts = splitEmail(email);
String domain = emailParts[1];
mProvider = findProviderForDomain(domain);
if (mProvider == null) {
/*
* We don't have default settings for this account, start the manual
* setup process.
*/
onManualSetup();
return;
}
AccountSetupBasics中的第346-355行
public void onClick(View v) {
switch (v.getId()) {
case R.id.next:
onNext();
break;
case R.id.manual_setup:
onManualSetup();
break;
}
}
这是Android清单,因为我很确定这是我的问题的根源,因为它似乎是应用程序无法获取名称或包,或者正在运行的当前活动......这样的事情
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bernard.beaconportal.activities"
android:versionCode="1"
android:versionName="1.0"
>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<!-- Needed to mark a contact as contacted -->
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" />
<permission android:name="com.bernard.beaconportal.activities.permission.READ_ATTACHMENT"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="dangerous"
android:label="@string/read_attachment_label"
android:description="@string/read_attachment_desc"/>
<uses-permission android:name="com.bernard.beaconportal.activities.permission.READ_ATTACHMENT"/>
<permission android:name="com.bernard.beaconportal.activities.permission.REMOTE_CONTROL"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="dangerous"
android:label="@string/remote_control_label"
android:description="@string/remote_control_desc"/>
<uses-permission android:name="com.bernard.beaconportal.activities.permission.REMOTE_CONTROL"/>
<permission android:name="com.bernard.beaconportal.activities.permission.READ_MESSAGES"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="dangerous"
android:label="@string/read_messages_label"
android:description="@string/read_messages_desc"/>
<uses-permission android:name="com.bernard.beaconportal.activities.permission.READ_MESSAGES"/>
<permission android:name="com.bernard.beaconportal.activities.permission.DELETE_MESSAGES"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="dangerous"
android:label="@string/delete_messages_label"
android:description="@string/delete_messages_desc"/>
<uses-permission android:name="com.bernard.beaconportal.activities.permission.DELETE_MESSAGES"/>
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"
/>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
android:allowTaskReparenting="false"
>
<meta-data android:name="android.app.default_searchable"
android:value=".activity.Search" />
<activity android:name=".MainActivity"
android:theme="@style/CustomActionBarTheme"
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=".FragmentsLinked"
android:theme="@style/CustomActionBarTheme"
android:windowSoftInputMode="adjustResize"
>
</activity>
<activity
android:name=".FragmentsEdit"
android:theme="@style/CustomActionBarTheme"
android:windowSoftInputMode="adjustResize" >
</activity>
<activity
android:name=".homeworkdueDetailsActivity"
android:theme="@style/CustomActionBarTheme"
android:parentActivityName="com.bernard.beaconportal.activities.MainActivity"
>
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.bernard.beaconportal.activities.MainActivity" />
</activity>
<activity
android:name=".activity.Accounts"
android:configChanges="locale"
android:launchMode="singleTop"
android:uiOptions="splitActionBarWhenNarrow"
android:label="@string/app_name">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="application/x-k9settings" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".activity.setup.Prefs"
android:label="@string/prefs_title"
android:configChanges="locale"
android:taskAffinity="com.bernard.beaconportal.activities.activity.setup.Prefs"
android:excludeFromRecents="true"
>
</activity>
<activity
android:name=".activity.setup.WelcomeMessage"
android:label="@string/welcome_message_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.FontSizeSettings"
android:label="@string/font_size_settings_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSetupBasics"
android:label="@string/account_setup_basics_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSetupAccountType"
android:label="@string/account_setup_account_type_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSetupIncoming"
android:label="@string/account_setup_incoming_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSetupComposition"
android:label="@string/account_settings_composition_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSetupOutgoing"
android:label="@string/account_setup_outgoing_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSetupOptions"
android:label="@string/account_setup_options_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSetupNames"
android:label="@string/account_setup_names_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.ChooseFolder"
android:theme="@style/Theme.K9Dialog"
android:label="@string/choose_folder_title"
android:configChanges="locale"
android:noHistory="true"
>
</activity>
<activity
android:name=".activity.ChooseIdentity"
android:theme="@style/Theme.K9Dialog"
android:label="@string/choose_identity_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.ManageIdentities"
android:label="@string/manage_identities_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.EditIdentity"
android:label="@string/edit_identity_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.NotificationDeleteConfirmation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:launchMode="singleTop"
android:taskAffinity=""
android:excludeFromRecents="true"
>
</activity>
<!-- XXX Note: this activity is hacked to ignore config changes,
since it doesn't currently handle them correctly in code. -->
<activity
android:name=".activity.setup.AccountSetupCheckSettings"
android:label="@string/account_setup_check_settings_title"
android:configChanges="keyboardHidden|orientation|locale"
>
</activity>
<activity
android:name=".activity.setup.AccountSettings"
android:label="@string/account_settings_title_fmt"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.setup.FolderSettings"
android:theme="@android:style/Theme.Dialog"
android:label="@string/folder_settings_title"
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.FolderList"
android:configChanges="locale"
android:uiOptions="splitActionBarWhenNarrow"
>
<intent-filter>
<!-- This action is only to allow an entry point for launcher shortcuts -->
</intent-filter>
</activity>
<activity
android:name=".activity.MessageList"
android:configChanges="locale"
android:launchMode="singleTop"
android:uiOptions="splitActionBarWhenNarrow"
>
<intent-filter>
<!-- This action is only to allow an entry point for launcher shortcuts -->
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
android:scheme="email"
android:host="messages"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activity.MessageCompose"
android:label="@string/app_name"
android:enabled="false"
android:configChanges="locale"
>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<!-- Search Activity - searchable -->
<activity android:name=".activity.Search"
android:label="@string/search_action"
android:configChanges="locale"
android:uiOptions="splitActionBarWhenNarrow"
>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".activity.LauncherShortcuts"
android:label="@string/shortcuts_title"
android:configChanges="locale"
>
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activity.AccessibleEmailContentActivity"
>
</activity>
<activity android:name=".activity.EmailAddressList"
android:configChanges="locale"
>
</activity>
<receiver android:name=".service.BootReceiver"
android:enabled="true"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DEVICE_STORAGE_LOW" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DEVICE_STORAGE_OK" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="com.android.sync.SYNC_CONN_STATUS_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="com.bernard.beaconportal.activities.service.BroadcastReceiver.scheduleIntent"/>
</intent-filter>
</receiver>
<receiver android:name=".service.RemoteControlReceiver"
android:enabled="true"
android:permission="com.bernard.beaconportal.activities.permission.REMOTE_CONTROL"
>
<intent-filter>
<action android:name="com.bernard.beaconportal.activities.K9RemoteControl.set"/>
</intent-filter>
<intent-filter>
<action android:name="com.bernard.beaconportal.activities.K9RemoteControl.requestAccounts"/>
</intent-filter>
</receiver>
<receiver android:name=".service.CoreReceiver"
android:enabled="true"
>
<intent-filter>
<action android:name="com.bernard.beaconportal.activities.service.CoreReceiver.wakeLockRelease"/>
</intent-filter>
</receiver>
<receiver android:name=".service.StorageReceiver"
android:enabled="true"
>
<intent-filter>
<!--
android.intent.action.MEDIA_MOUNTED
* Broadcast Action: External media is present and mounted at its mount point.
* The path to the mount point for the removed media is contained in the Intent.mData field.
* The Intent contains an extra with name "read-only" and Boolean value to indicate if the
* media was mounted read only.
-->
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<!--
MEDIA_EJECT and MEDIA_UNMOUNTED are not defined here: they have to be dynamically registered
otherwise it would make K-9 start at the wrong time
-->
<data android:scheme="file"/>
</intent-filter>
</receiver>
<service
android:name=".service.MailService"
android:enabled="true"
>
</service>
<service
android:name=".service.NotificationActionService"
android:enabled="true"
>
</service>
<service
android:name=".service.PushService"
android:enabled="true"
>
</service>
<service
android:name=".service.PollService"
android:enabled="true"
>
</service>
<service
android:name=".service.RemoteControlService"
android:enabled="true"
android:permission="com.bernard.beaconportal.activities.permission.REMOTE_CONTROL"
>
</service>
<service
android:name=".service.SleepService"
android:enabled="true"
>
</service>
<provider
android:name=".provider.AttachmentProvider"
android:authorities="com.bernard.beaconportal.activities.attachmentprovider"
android:multiprocess="true"
android:grantUriPermissions="true"
android:readPermission="com.bernard.beaconportal.activities.permission.READ_ATTACHMENT"
android:exported="true"
/>
<provider
android:name=".provider.MessageProvider"
android:authorities="com.bernard.beaconportal.activities.messageprovider"
android:multiprocess="true"
android:grantUriPermissions="true"
android:readPermission="com.bernard.beaconportal.activities.permission.READ_MESSAGES"
android:writePermission="com.bernard.beaconportal.activities.permission.DELETE_MESSAGES"
android:exported="true"
/>
<provider
android:name=".provider.EmailProvider"
android:authorities="com.bernard.beaconportal.activities.provider.email"
android:exported="false"
/>
<receiver
android:name=".provider.UnreadWidgetProvider"
android:label="@string/unread_widget_label"
android:icon="@drawable/icon">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/unread_widget_info" />
</receiver>
<activity android:name=".activity.UnreadWidgetConfiguration">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity
android:name=".activity.UpgradeDatabases"
android:label="@string/upgrade_databases_title">
</activity>
<service
android:name=".service.DatabaseUpgradeService"
android:exported="false">
</service>
</application>
</manifest>
如果您需要更多代码,或者需要询问有关此代码的问题,请询问。
答案 0 :(得分:1)
K9.app似乎可以访问单身人士。这似乎仅在您进行身份验证时设置。您需要更多地了解K9.app是如何实现的。
答案 1 :(得分:0)
原来我早先的怀疑是正确的,而AndroidManifest确实存在一个让我搞砸的问题。所以我添加了#34;机器人:名称=&#34; com.bernard.beaconportal.activities.K9&#34; &#34;到清单,修复它。我将它添加到清单的应用程序部分,所以它现在看起来像这样。感谢前一个答案提供的所有帮助,这些帮助指出了我正确的方向。并且Jeremy Miller最初确实发现了错误,但我想我不知道你必须在清单中添加扩展Application的类。
<application
android:icon="@drawable/ic_launcher"
android:name="com.bernard.beaconportal.activities.K9"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
android:allowTaskReparenting="false"
>
<meta-data android:name="android.app.default_searchable"
android:value=".activity.Search" />