これは私のコードからのスニペットで、ロード時に Android FragmentActivity で null_pointer を取得しますが、その理由はわかりません。最後の SharedPreferences で発生します。
public class BaseActivity extends FragmentActivity {
private static final String MY_PREFS_FILE_NAME = "check_status";
final SharedPreferences _prefs = new ObscuredSharedPreferences(this, this
.getApplication().getApplicationContext()
.getSharedPreferences(MY_PREFS_FILE_NAME, Context.MODE_PRIVATE));
public static Context _appContext;
private ListView _baseDrawerList;
private DrawerLayout _baseDrawer;
private CustomActionBarDrawerToggle _baseDrawerToggle;
private String[] _menuItemsControl;// for profile and settings.
private String[] _menuItemsControlSplit_1;
private FragmentManager _fManager;
private LoginFragment _loginFragment;
private MainDisplayFragment mf;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_fManager = getSupportFragmentManager();
mf = new MainDisplayFragment();
setContentView(R.layout.activity_base_drawer);
// enable ActionBar app icon to behave as action to toggle nav drawer
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
_baseDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
// set a custom shadow that overlays the main content when the drawer
// opens
_baseDrawer.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
initlize_menu();
必要なステータスを安全に保存しようとしているだけで、これが最善の方法だと思いました。
例外は次のとおりです。
11-05 06:37:31.532: E/AndroidRuntime(13674): FATAL EXCEPTION: main
11-05 06:37:31.532: E/AndroidRuntime(13674): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.development/com.development.BaseActivity}: java.lang.NullPointerException
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.os.Looper.loop(Looper.java:137)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-05 06:37:31.532: E/AndroidRuntime(13674): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 06:37:31.532: E/AndroidRuntime(13674): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 06:37:31.532: E/AndroidRuntime(13674): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-05 06:37:31.532: E/AndroidRuntime(13674): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-05 06:37:31.532: E/AndroidRuntime(13674): at dalvik.system.NativeStart.main(Native Method)
11-05 06:37:31.532: E/AndroidRuntime(13674): Caused by: java.lang.NullPointerException
11-05 06:37:31.532: E/AndroidRuntime(13674): at com.development.BaseActivity.<init>(BaseActivity.java:52)
11-05 06:37:31.532: E/AndroidRuntime(13674): at java.lang.Class.newInstanceImpl(Native Method)
11-05 06:37:31.532: E/AndroidRuntime(13674): at java.lang.Class.newInstance(Class.java:1319)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
11-05 06:37:31.532: E/AndroidRuntime(13674): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
11-05 06:37:31.532: E/AndroidRuntime(13674): ... 11 more