当我进入横向模式时,我的应用程序崩溃了

时间:2015-04-14 02:44:04

标签: java android xml listview android-fragments

当它处于纵向模式时,我在活动中显示一个片段。该片段包含一个ListView。单击某个项目时,它会打开另一个活动,该活动具有另一个片段,其中包含有关单击的listView项目的详细信息。现在,当它处于横向时,假设显示第一个片段(ListView)并在它旁边,第二个片段(关于从ListView中选择的项目的详细信息)。但它正在崩溃。我的logcat中的错误是nullpointerexception。任何帮助将不胜感激。

我的GradeListActivity.java:

public class GradeListActivity extends Activity
{
    public GradeCollection gc = new GradeCollection();    
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grade_list_activity);
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            //ListViewFragment LVF = new ListViewFragment();
            ft.add(R.id.ui_container, new ListViewFragment());
            //GradeDetailFragment GDF = new GradeDetailFragment();
            int currentOrientation = getResources().getConfiguration().orientation;
            if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE)
            {
                ft.add(R.id.ui_detail, new GradeDetailFragment());
            }
            ft.commit();
    }
}

我的grade_list_activity.xml(格局):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
     <FrameLayout
        android:id="@+id/ui_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="2"
    />
     <FrameLayout
        android:id="@+id/ui_detail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="2"
    />
</LinearLayout>

我的grade_list_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     <FrameLayout
        android:id="@+id/ui_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    />

</LinearLayout>

我的GradeListFragment.java:

     public class GradeDetailFragment extends Fragment {

        public GradeCollection gc = new GradeCollection();
        public int position;


        @Override
        public View onCreateView(   LayoutInflater inflater,
            ViewGroup container,
            Bundle savedInstanceState) 
        {   
            View v = inflater.inflate(R.layout.grade_detail_fargment, container, false);

            Activity a = getActivity();
            Intent i = a.getIntent();

            gc = (GradeCollection) i.getExtras().getSerializable("OriginalGradeCollectionInstance");
            position = (Integer) i.getExtras().getSerializable("position");


            EditText textCategory = (EditText) v.findViewById(R.id.editTextCategory);
            EditText textNumber = (EditText) v.findViewById(R.id.editTextNumber);
            EditText textGrade = (EditText) v.findViewById(R.id.editTextGrade);
            EditText textDescription = (EditText) v.findViewById(R.id.editTextDescription);


//This code chunk might be giving me NPE
            //if(gc != null)
            //{
                textCategory.setText(gc.GetItem(position).getCategory() + "");
                textNumber.setText(gc.GetItem(position).getNumber() + "");
                String grade = "" + gc.GetItem(position).getGrade();
                textGrade.setText(grade);
                textDescription.setText(gc.GetItem(position).getDescription() + "");
            //}
            return v;
        }
    }

我的LogCat:

 04-14 03:02:11.565: D/AndroidRuntime(3598): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
04-14 03:02:11.565: D/AndroidRuntime(3598): CheckJNI is ON
04-14 03:02:11.595: D/dalvikvm(3598): Trying to load lib libjavacore.so 0x0
04-14 03:02:11.605: D/dalvikvm(3598): Added shared lib libjavacore.so 0x0
04-14 03:02:11.635: D/dalvikvm(3598): Trying to load lib libnativehelper.so 0x0
04-14 03:02:11.635: D/dalvikvm(3598): Added shared lib libnativehelper.so 0x0
04-14 03:02:12.315: D/AndroidRuntime(3598): Calling main entry com.android.commands.pm.Pm
04-14 03:02:12.365: W/ActivityManager(2382): No content provider found for permission revoke: file:///data/local/tmp/bcs421.muhammadqumail.hwk.gradeapp.presentation.apk
04-14 03:02:12.465: W/ActivityManager(2382): No content provider found for permission revoke: file:///data/local/tmp/bcs421.muhammadqumail.hwk.gradeapp.presentation.apk
04-14 03:02:12.465: I/PackageManager(2382): Copying native libraries to /data/app-lib/vmdl-1175232448
04-14 03:02:12.665: I/PackageManager(2382): Removing non-system package:bcs421.muhammadqumail.hwk.gradeapp.presentation
04-14 03:02:12.675: I/ActivityManager(2382): Force stopping package bcs421.muhammadqumail.hwk.gradeapp.presentation appid=10048 user=-1
04-14 03:02:12.675: I/ActivityManager(2382): Killing proc 3543:bcs421.muhammadqumail.hwk.gradeapp.presentation/u0a10048: force stop bcs421.muhammadqumail.hwk.gradeapp.presentation
04-14 03:02:12.675: I/ActivityManager(2382):   Force finishing activity ActivityRecord{40ed9828 u0 bcs421.muhammadqumail.hwk.gradeapp.presentation/.MainActivity}
04-14 03:02:12.705: I/WindowState(2382): WIN DEATH: Window{4110b3d0 u0 bcs421.muhammadqumail.hwk.gradeapp.presentation/bcs421.muhammadqumail.hwk.gradeapp.presentation.MainActivity}
04-14 03:02:12.805: I/PackageManager(2382): Package bcs421.muhammadqumail.hwk.gradeapp.presentation codePath changed from /data/app/bcs421.muhammadqumail.hwk.gradeapp.presentation-1.apk to /data/app/bcs421.muhammadqumail.hwk.gradeapp.presentation-2.apk; Retaining data and using new
04-14 03:02:12.815: I/PackageManager(2382): Running dexopt on: bcs421.muhammadqumail.hwk.gradeapp.presentation
04-14 03:02:13.735: I/dalvikvm(3609): DexOpt: access denied from Landroid/support/v4/app/NotificationCompatKitKat; to field Landroid/app/Notification;.actions
04-14 03:02:14.395: D/dalvikvm(3609): DexOpt: load 252ms, verify+opt 828ms, 1242628 bytes
04-14 03:02:14.485: I/ActivityManager(2382): Force stopping package bcs421.muhammadqumail.hwk.gradeapp.presentation appid=10048 user=-1
04-14 03:02:14.485: W/PackageManager(2382): Code path for pkg : bcs421.muhammadqumail.hwk.gradeapp.presentation changing from /data/app/bcs421.muhammadqumail.hwk.gradeapp.presentation-1.apk to /data/app/bcs421.muhammadqumail.hwk.gradeapp.presentation-2.apk
04-14 03:02:14.485: W/PackageManager(2382): Resource path for pkg : bcs421.muhammadqumail.hwk.gradeapp.presentation changing from /data/app/bcs421.muhammadqumail.hwk.gradeapp.presentation-1.apk to /data/app/bcs421.muhammadqumail.hwk.gradeapp.presentation-2.apk
04-14 03:02:14.565: D/PackageManager(2382): New package installed in /data/app/bcs421.muhammadqumail.hwk.gradeapp.presentation-2.apk
04-14 03:02:14.655: I/ActivityManager(2382): Force stopping package bcs421.muhammadqumail.hwk.gradeapp.presentation appid=10048 user=0
04-14 03:02:14.785: I/InputReader(2382): Reconfiguring input devices.  changes=0x00000010
04-14 03:02:14.805: W/ContextImpl(2873): Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1352 android.content.ContextWrapper.startService:450 android.content.ContextWrapper.startService:450 com.android.keychain.KeyChainBroadcastReceiver.onReceive:12 android.app.ActivityThread.handleReceiver:2376 
04-14 03:02:15.046: I/InputReader(2382): Reconfiguring input devices.  changes=0x00000010
04-14 03:02:15.205: W/InputMethodManagerService(2382): Found no subtypes in a system IME: com.android.inputmethod.pinyin
04-14 03:02:15.545: D/dalvikvm(2382): GC_EXPLICIT freed 1115K, 24% free 7369K/9668K, paused 18ms+33ms, total 232ms
04-14 03:02:15.575: D/AndroidRuntime(3598): Shutting down VM
04-14 03:02:15.585: D/dalvikvm(3598): GC_CONCURRENT freed 94K, 18% free 467K/564K, paused 1ms+1ms, total 11ms
04-14 03:02:15.585: D/jdwp(3598): Got wake-up signal, bailing out of select
04-14 03:02:15.585: D/dalvikvm(3598): Debugger has detached; object registry had 1 entries
04-14 03:02:15.835: W/RecognitionManagerService(2382): no available voice recognition services found for user 0
04-14 03:02:16.285: D/AndroidRuntime(3617): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
04-14 03:02:16.285: D/AndroidRuntime(3617): CheckJNI is ON
04-14 03:02:16.345: D/dalvikvm(3617): Trying to load lib libjavacore.so 0x0
04-14 03:02:16.366: D/dalvikvm(3617): Added shared lib libjavacore.so 0x0
04-14 03:02:16.455: D/dalvikvm(3617): Trying to load lib libnativehelper.so 0x0
04-14 03:02:16.455: D/dalvikvm(3617): Added shared lib libnativehelper.so 0x0
04-14 03:02:17.215: D/AndroidRuntime(3617): Calling main entry com.android.commands.am.Am
04-14 03:02:17.225: D/dalvikvm(3617): Note: class Landroid/app/ActivityManagerNative; has 157 unimplemented (abstract) methods
04-14 03:02:17.245: I/ActivityManager(2382): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=bcs421.muhammadqumail.hwk.gradeapp.presentation/.MainActivity} from pid 3617
04-14 03:02:17.335: D/AndroidRuntime(3617): Shutting down VM
04-14 03:02:17.345: D/dalvikvm(3627): Not late-enabling CheckJNI (already on)
04-14 03:02:17.355: D/dalvikvm(3617): GC_CONCURRENT freed 96K, 17% free 499K/600K, paused 1ms+1ms, total 10ms
04-14 03:02:17.355: D/jdwp(3617): Got wake-up signal, bailing out of select
04-14 03:02:17.355: D/dalvikvm(3617): Debugger has detached; object registry had 1 entries
04-14 03:02:17.385: I/ActivityManager(2382): Start proc bcs421.muhammadqumail.hwk.gradeapp.presentation for activity bcs421.muhammadqumail.hwk.gradeapp.presentation/.MainActivity: pid=3627 uid=10048 gids={50048, 1028}
04-14 03:02:17.625: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-14 03:02:17.765: E/Trace(3627): error opening trace file: No such file or directory (2)
04-14 03:02:18.405: D/dalvikvm(3627): GC_CONCURRENT freed 73K, 7% free 2710K/2904K, paused 12ms+26ms, total 103ms
04-14 03:02:18.445: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-14 03:02:18.465: D/libEGL(3627): loaded /system/lib/egl/libEGL_emulation.so
04-14 03:02:18.465: D/(3627): HostConnection::get() New Host Connection established 0x2a165848, tid 3627
04-14 03:02:18.476: D/libEGL(3627): loaded /system/lib/egl/libGLESv1_CM_emulation.so
04-14 03:02:18.485: D/libEGL(3627): loaded /system/lib/egl/libGLESv2_emulation.so
04-14 03:02:18.525: W/EGL_emulation(3627): eglSurfaceAttrib not implemented
04-14 03:02:18.535: D/OpenGLRenderer(3627): Enabling debug mode 0
04-14 03:02:18.735: I/ActivityManager(2382): Displayed bcs421.muhammadqumail.hwk.gradeapp.presentation/.MainActivity: +1s411ms
04-14 03:02:21.175: I/ActivityManager(2382): START u0 {cmp=bcs421.muhammadqumail.hwk.gradeapp.presentation/.GradeListActivity (has extras)} from pid 3627
04-14 03:02:21.405: D/dalvikvm(3627): GC_FOR_ALLOC freed 88K, 7% free 2846K/3056K, paused 36ms, total 37ms
04-14 03:02:21.405: I/dalvikvm-heap(3627): Grow heap (frag case) to 3.501MB for 635812-byte allocation
04-14 03:02:21.475: D/dalvikvm(3627): GC_FOR_ALLOC freed 1K, 6% free 3466K/3680K, paused 60ms, total 60ms
04-14 03:02:21.535: D/dalvikvm(3627): GC_CONCURRENT freed 2K, 6% free 3475K/3680K, paused 6ms+23ms, total 64ms
04-14 03:02:21.705: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-14 03:02:21.725: W/EGL_emulation(3627): eglSurfaceAttrib not implemented
04-14 03:02:21.955: I/ActivityManager(2382): Displayed bcs421.muhammadqumail.hwk.gradeapp.presentation/.GradeListActivity: +737ms
04-14 03:02:24.255: I/InputReader(2382): Reconfiguring input devices.  changes=0x00000004
04-14 03:02:24.255: I/InputReader(2382): Device reconfigured: id=0, name='qwerty2', size 480x800, orientation 1, mode 1, display id 0
04-14 03:02:24.265: I/ActivityManager(2382): Config changes=1480 {1.0 310mcc260mnc en_US ldltr sw320dp w491dp h294dp 240dpi nrml land finger qwerty/v/v -nav/h s.15}
04-14 03:02:24.565: D/dalvikvm(2947): GC_FOR_ALLOC freed 8933K, 65% free 4966K/14064K, paused 100ms, total 105ms
04-14 03:02:24.585: I/dalvikvm-heap(2947): Grow heap (frag case) to 11.078MB for 6410576-byte allocation
04-14 03:02:24.695: D/dalvikvm(2947): GC_FOR_ALLOC freed 260K, 23% free 10965K/14064K, paused 109ms, total 110ms
04-14 03:02:24.922: D/dalvikvm(3627): GC_FOR_ALLOC freed 36K, 5% free 3683K/3840K, paused 152ms, total 199ms
04-14 03:02:24.945: I/dalvikvm-heap(3627): Grow heap (frag case) to 4.319MB for 635812-byte allocation
04-14 03:02:25.005: D/dalvikvm(2947): GC_CONCURRENT freed <1K, 23% free 10966K/14064K, paused 5ms+154ms, total 313ms
04-14 03:02:25.085: D/dalvikvm(3627): GC_CONCURRENT freed 8K, 4% free 4296K/4464K, paused 79ms+5ms, total 143ms
04-14 03:02:25.085: D/dalvikvm(3627): WAIT_FOR_CONCURRENT_GC blocked 64ms
04-14 03:02:25.556: D/AndroidRuntime(3627): Shutting down VM
04-14 03:02:25.556: W/dalvikvm(3627): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-14 03:02:25.606: E/AndroidRuntime(3627): FATAL EXCEPTION: main
04-14 03:02:25.606: E/AndroidRuntime(3627): java.lang.RuntimeException: Unable to start activity ComponentInfo{bcs421.muhammadqumail.hwk.gradeapp.presentation/bcs421.muhammadqumail.hwk.gradeapp.presentation.GradeListActivity}: java.lang.NullPointerException
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.ActivityThread.access$700(ActivityThread.java:141)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.os.Looper.loop(Looper.java:137)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at java.lang.reflect.Method.invokeNative(Native Method)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at java.lang.reflect.Method.invoke(Method.java:511)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at dalvik.system.NativeStart.main(Native Method)
04-14 03:02:25.606: E/AndroidRuntime(3627): Caused by: java.lang.NullPointerException
04-14 03:02:25.606: E/AndroidRuntime(3627):     at bcs421.muhammadqumail.hwk.gradeapp.presentation.GradeDetailFragment.onCreateView(GradeDetailFragment.java:30)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.Fragment.performCreateView(Fragment.java:1695)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.BackStackRecord.run(BackStackRecord.java:682)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.Activity.performStart(Activity.java:5113)
04-14 03:02:25.606: E/AndroidRuntime(3627):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
04-14 03:02:25.606: E/AndroidRuntime(3627):     ... 12 more
04-14 03:02:25.655: W/ActivityManager(2382):   Force finishing activity bcs421.muhammadqumail.hwk.gradeapp.presentation/.GradeListActivity
04-14 03:02:25.725: D/dalvikvm(2947): GC_FOR_ALLOC freed <1K, 23% free 10966K/14064K, paused 150ms, total 150ms
04-14 03:02:25.745: I/dalvikvm-heap(2947): Grow heap (frag case) to 13.309MB for 2606048-byte allocation
04-14 03:02:25.835: D/dalvikvm(2947): GC_CONCURRENT freed 0K, 4% free 13511K/14064K, paused 5ms+5ms, total 96ms
04-14 03:02:25.835: D/dalvikvm(2947): WAIT_FOR_CONCURRENT_GC blocked 89ms
04-14 03:02:25.965: D/dalvikvm(2382): GC_FOR_ALLOC freed 687K, 23% free 7523K/9668K, paused 239ms, total 250ms
04-14 03:02:25.975: I/dalvikvm-heap(2382): Grow heap (frag case) to 8.074MB for 635812-byte allocation
04-14 03:02:26.075: D/dalvikvm(2382): GC_FOR_ALLOC freed 20K, 22% free 8124K/10292K, paused 96ms, total 96ms
04-14 03:02:26.195: W/WindowManager(2382): Window freeze timeout expired.
04-14 03:02:26.195: W/WindowManager(2382): Force clearing orientation change: Window{4108cac8 u0 NavigationBar}
04-14 03:02:26.195: W/WindowManager(2382): Force clearing orientation change: Window{40ec49f0 u0 StatusBar}
04-14 03:02:26.195: W/WindowManager(2382): Force clearing orientation change: Window{412dab18 u0 com.android.systemui.ImageWallpaper}
04-14 03:02:26.475: W/ActivityManager(2382): Activity pause timeout for ActivityRecord{40f38d20 u0 bcs421.muhammadqumail.hwk.gradeapp.presentation/.GradeListActivity}
04-14 03:02:26.715: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-14 03:02:26.725: I/Choreographer(2947): Skipped 35 frames!  The application may be doing too much work on its main thread.
04-14 03:02:27.845: I/Process(3627): Sending signal. PID: 3627 SIG: 9
04-14 03:02:27.865: I/WindowState(2382): WIN DEATH: Window{40f5adc8 u0 bcs421.muhammadqumail.hwk.gradeapp.presentation/bcs421.muhammadqumail.hwk.gradeapp.presentation.MainActivity}
04-14 03:02:27.865: I/ActivityManager(2382): Process bcs421.muhammadqumail.hwk.gradeapp.presentation (pid 3627) has died.
04-14 03:02:27.905: D/dalvikvm(3643): Not late-enabling CheckJNI (already on)
04-14 03:02:27.935: I/ActivityManager(2382): Start proc bcs421.muhammadqumail.hwk.gradeapp.presentation for activity bcs421.muhammadqumail.hwk.gradeapp.presentation/.MainActivity: pid=3643 uid=10048 gids={50048, 1028}
04-14 03:02:28.246: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-14 03:02:28.285: E/Trace(3643): error opening trace file: No such file or directory (2)
04-14 03:02:28.945: D/dalvikvm(3643): GC_CONCURRENT freed 78K, 7% free 2710K/2908K, paused 6ms+4ms, total 83ms
04-14 03:02:28.995: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-14 03:02:29.015: D/libEGL(3643): loaded /system/lib/egl/libEGL_emulation.so
04-14 03:02:29.015: D/(3643): HostConnection::get() New Host Connection established 0x2a154410, tid 3643
04-14 03:02:29.025: D/libEGL(3643): loaded /system/lib/egl/libGLESv1_CM_emulation.so
04-14 03:02:29.035: D/libEGL(3643): loaded /system/lib/egl/libGLESv2_emulation.so
04-14 03:02:29.075: W/EGL_emulation(3643): eglSurfaceAttrib not implemented
04-14 03:02:29.085: D/OpenGLRenderer(3643): Enabling debug mode 0
04-14 03:02:29.115: W/InputMethodManagerService(2382): Got RemoteException sending setActive(false) notification to pid 3627 uid 10048
04-14 03:02:29.305: I/ActivityManager(2382): Displayed bcs421.muhammadqumail.hwk.gradeapp.presentation/.MainActivity: +1s422ms
04-14 03:02:30.685: D/dalvikvm(2382): GC_EXPLICIT freed 256K, 21% free 8172K/10292K, paused 13ms+12ms, total 135ms
04-14 03:02:38.185: D/ExchangeService(2762): Received deviceId from Email app: null
04-14 03:02:38.185: D/ExchangeService(2762): !!! deviceId unknown; stopping self and retrying
04-14 03:02:43.235: D/ExchangeService(2762): !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false
04-14 03:02:43.255: W/ActivityManager(2382): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
04-14 03:02:43.255: D/ExchangeService(2762): !!! Email application not found; stopping self
04-14 03:02:43.265: W/ActivityManager(2382): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
04-14 03:02:43.285: E/ActivityThread(2762): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d41668 that was originally bound here
04-14 03:02:43.285: E/ActivityThread(2762): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d41668 that was originally bound here
04-14 03:02:43.285: E/ActivityThread(2762):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-14 03:02:43.285: E/ActivityThread(2762):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-14 03:02:43.285: E/ActivityThread(2762):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-14 03:02:43.285: E/ActivityThread(2762):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-14 03:02:43.285: E/ActivityThread(2762):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-14 03:02:43.285: E/ActivityThread(2762):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-14 03:02:43.285: E/ActivityThread(2762):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-14 03:02:43.285: E/ActivityThread(2762):     at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-14 03:02:43.285: E/ActivityThread(2762):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-14 03:02:43.285: E/ActivityThread(2762):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-14 03:02:43.285: E/ActivityThread(2762):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-14 03:02:43.285: E/ActivityThread(2762):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-14 03:02:43.285: E/ActivityThread(2762):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-14 03:02:43.285: E/ActivityThread(2762):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-14 03:02:43.285: E/ActivityThread(2762):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-14 03:02:43.285: E/ActivityThread(2762):     at java.lang.Thread.run(Thread.java:856)
04-14 03:02:43.285: E/StrictMode(2762): null
04-14 03:02:43.285: E/StrictMode(2762): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d41668 that was originally bound here
04-14 03:02:43.285: E/StrictMode(2762):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-14 03:02:43.285: E/StrictMode(2762):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-14 03:02:43.285: E/StrictMode(2762):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-14 03:02:43.285: E/StrictMode(2762):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-14 03:02:43.285: E/StrictMode(2762):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-14 03:02:43.285: E/StrictMode(2762):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-14 03:02:43.285: E/StrictMode(2762):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-14 03:02:43.285: E/StrictMode(2762):     at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-14 03:02:43.285: E/StrictMode(2762):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-14 03:02:43.285: E/StrictMode(2762):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-14 03:02:43.285: E/StrictMode(2762):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-14 03:02:43.285: E/StrictMode(2762):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-14 03:02:43.285: E/StrictMode(2762):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-14 03:02:43.285: E/StrictMode(2762):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-14 03:02:43.285: E/StrictMode(2762):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-14 03:02:43.285: E/StrictMode(2762):     at java.lang.Thread.run(Thread.java:856)
04-14 03:02:43.295: W/ActivityManager(2382): Unbind failed: could not find connection for android.os.BinderProxy@41165ea0
04-14 03:02:43.315: E/ActivityThread(2762): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce7880 that was originally bound here
04-14 03:02:43.315: E/ActivityThread(2762): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce7880 that was originally bound here
04-14 03:02:43.315: E/ActivityThread(2762):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-14 03:02:43.315: E/ActivityThread(2762):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-14 03:02:43.315: E/ActivityThread(2762):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-14 03:02:43.315: E/ActivityThread(2762):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-14 03:02:43.315: E/ActivityThread(2762):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-14 03:02:43.315: E/ActivityThread(2762):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-14 03:02:43.315: E/ActivityThread(2762):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-14 03:02:43.315: E/ActivityThread(2762):     at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
04-14 03:02:43.315: E/ActivityThread(2762):     at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
04-14 03:02:43.315: E/ActivityThread(2762):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
04-14 03:02:43.315: E/ActivityThread(2762):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-14 03:02:43.315: E/ActivityThread(2762):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-14 03:02:43.315: E/ActivityThread(2762):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-14 03:02:43.315: E/ActivityThread(2762):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-14 03:02:43.315: E/ActivityThread(2762):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)

2 个答案:

答案 0 :(得分:1)

在方向更改后,Android会重新创建活动,但它不会再次传递最初启动该活动的 intent 。因此,当您旋转屏幕时,getIntent()会返回null,然后代码会引发NullPointerException

因此,为了解决您的问题,您需要在重新创建 intent 数据时初始化您的片段,您可以通过检查savedInstanceState是否{{ {1}}。

null

但是,这意味着旋转后的片段无法使用之前收到的 intent 数据正确初始化。因此,为了实现这一点,您需要在Android销毁片段之前将if (savedInstanceState == null) { Activity a = getActivity(); Intent i = a.getIntent(); gc = (GradeCollection) i.getExtras() .getSerializable("OriginalGradeCollectionInstance"); position = (Integer) i.getExtras().getSerializable("position"); } GradeCollection保存到实例状态

position

然后只需将@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("position", position); outState.putSerializable("grades", gc); } 中的片段状态恢复为

onCreateView()

请注意,您需要让if (savedInstanceState == null) { Activity a = getActivity(); Intent i = a.getIntent(); gc = (GradeCollection) i.getExtras() .getSerializable("OriginalGradeCollectionInstance"); position = (Integer) i.getExtras().getSerializable("position"); } else { position = savedInstanceState.getInt("position"); gc = (GradeCollection) savedInstanceState.getSerializable("grades"); } (以及任何非包装自定义成员&#39;类)实施GradeCollection

答案 1 :(得分:0)

onCreateView()中的片段通常无法使用活动。尝试一些移动:

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        Intent i = activity.getIntent();

        gc = (GradeCollection) i.getExtras().getSerializable("OriginalGradeCollectionInstance");
        position = (Integer) i.getExtras().getSerializable("position");

        textCategory.setText(gc.GetItem(position).getCategory() + "");
        textNumber.setText(gc.GetItem(position).getNumber() + "");
        String grade = "" + gc.GetItem(position).getGrade();
        textGrade.setText(grade);
        textDescription.setText(gc.GetItem(position).getDescription() + "");
    }

删除onCreateView()中的相应行,并将所有EditText s - 片段的字段删除。