重新打开时Android App崩溃

时间:2014-08-07 23:16:59

标签: android android-intent android-activity android-fragments fragment

当我重新打开应用时,我的Android应用崩溃了。

示例:

  1. 将应用程序打开到主要活动。
  2. 导航到其他活动(MyEventsActivity)。
  3. 在Activity(MyEventsCreator)中打开一个新片段。
  4. 当新片段处于活动状态时,我会通过点击手机的主屏幕退出应用程序。
  5. 然后让App在后台运行几个小时。
  6. 最后,当我重新打开应用程序时,它将以白色屏幕开始然后崩溃。
  7. 我试图解决这个问题好几个星期。阅读每个论坛以找到解决方案。任何有关这方面的帮助将不胜感激。

    这是错误日志,

    07-28 07:11:50.432: E/AndroidRuntime(1038): java.lang.RuntimeException: Unable to destroy activity {com.events/com.events.MyEventsActivity}: java.lang.NullPointerException
    7-28 07:11:50.432: E/AndroidRuntime(1038):  at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3337)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3355)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.app.ActivityThread.access$1300(ActivityThread.java:143)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.os.Handler.dispatchMessage(Handler.java:99)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.os.Looper.loop(Looper.java:137)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.app.ActivityThread.main(ActivityThread.java:4950)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at java.lang.reflect.Method.invoke(Method.java:511)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at dalvik.system.NativeStart.main(Native Method)
    07-28 07:11:50.432: E/AndroidRuntime(1038): Caused by: java.lang.NullPointerException
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at com.events.ui.MyEventsCreator.onCreateView(MyEventsCreator.java:60)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop(FragmentManager.java:1911)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.FragmentActivity.onReallyStop(FragmentActivity.java:809)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.FragmentActivity.doReallyStop(FragmentActivity.java:786)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:333)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.app.Activity.performDestroy(Activity.java:5343)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1124)
    07-28 07:11:50.432: E/AndroidRuntime(1038):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3324)
    

    非常感谢你。

    这是MyEventsCreator.java。但是每当重新打开应用程序时,应用程序都会在每个片段上崩溃。 我将发布另一个错误日志。那个案子在不同的地方崩溃了。

    public class MyEventsCreator扩展了CustomFragment {

    private Player currentPlayer;
    private List<MyEvent> creatorEvents = new ArrayList<MyEvent>(); 
    private ListView eventListView;
    
    private ProgressDialog progressDialog;
    
    private SharedDataSet sharedData;   
    private EventFunctions eventFunctions = new EventFunctions();
    
    /* (non-Javadoc)
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState)
    {
        View v = inflater.inflate(R.layout.myevents, null);
    
        eventListView = (ListView) v.findViewById(R.id.lv_MyEvents);            
    
        setHasOptionsMenu(true);
    
        sharedData = (SharedDataSet) getActivity().getApplicationContext();
        currentPlayer = sharedData.getLoggedInPlayer(); // get the currently logged in player   
    
        if (currentPlayer != null)
        {               
            creatorEvents = eventFunctions.getEventsListFromUId(currentPlayer.getID(), EventFunctions.ParticipantTypes.Creator);
    
            eventListView.setAdapter(new EventsAdapter());
            eventListView.setOnItemClickListener(new OnItemClickListener() {
    
                @Override
                public void onItemClick(AdapterView<?> listView, View convertView, int position,
                        long arg3)
                {
    
                    transferSync trasnferTask = new transferSync();
                    trasnferTask.execute(position + "");    
    
                }       
            });
    
        } else 
        {
            Intent intent = new Intent(getActivity(), AccountActivity.class);
            startActivity(intent);      
            getActivity().finish();
        }       
    
    
        return v;
    }  
    

    }

0 个答案:

没有答案