0

我的應用程序工作正常,但是當它的背景,然後恢復後,在logcat的這些錯誤的工作停止:無法啓動應用恢復活動ComponentInfo NullPointerException異常錯誤

09-26 15:46:49.278: D/SqliteDatabaseCpp(5847): Registering sqlite logging func: /data/data/com.friends.roleon/databases/roleonDB 
09-26 15:46:49.288: D/SqliteDatabaseCpp(5847): DB info: open db, path = /data/data/com.friends.roleon/databases , key = DvkadTace, flag = 6, file size = 34816 
09-26 15:46:49.288: D/SqliteDatabaseCpp(5847): DB info: path = /data/data/com.friends.roleon/databases , key = DvkadTace, handle: 0x1f29030, type: w, r/w: (0,1), mode: truncate, disk free size: 213 M 
09-26 15:46:49.318: D/SqliteDatabaseCpp(5847): DB info: close db, path = /data/data/com.friends.roleon/databases , key = DvkadTace, handle = 0x1f29030, type = w, r/w = (0, 0) 
09-26 15:46:49.318: D/check(5847): create fragmentnull 
09-26 15:46:49.559: D/SqliteDatabaseCpp(5847): DB info: open db, path = /data/data/com.friends.roleon/databases , key = DvkadTace, flag = 6, file size = 34816 
09-26 15:46:49.599: D/SqliteDatabaseCpp(5847): DB info: path = /data/data/com.friends.roleon/databases , key = DvkadTace, handle: 0x1f4a208, type: w, r/w: (0,1), mode: truncate, disk free size: 213 M 
09-26 15:46:49.649: D/SqliteDatabaseCpp(5847): DB info: open db, path = /data/data/com.friends.roleon/databases , key = DvkadTace, flag = 6, file size = 34816 
09-26 15:46:49.649: D/AndroidRuntime(5847): Shutting down VM 
09-26 15:46:49.649: W/dalvikvm(5847): threadid=1: thread exiting with uncaught exception (group=0x40aab228) 
09-26 15:46:49.659: E/AndroidRuntime(5847): FATAL EXCEPTION: main 
09-26 15:46:49.659: E/AndroidRuntime(5847): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.friends.roleon/com.friends.roleon.roleonMain}: java.lang.IllegalArgumentException: No view found for id 0x7f060038 for fragment RecordListFragment{40dd3b10 #2 id=0x7f060038} 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.ActivityThread.access$600(ActivityThread.java:139) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.os.Handler.dispatchMessage(Handler.java:99) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.os.Looper.loop(Looper.java:156) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.ActivityThread.main(ActivityThread.java:4987) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at java.lang.reflect.Method.invoke(Method.java:511) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at dalvik.system.NativeStart.main(Native Method) 
09-26 15:46:49.659: E/AndroidRuntime(5847): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f060038 for fragment RecordListFragment{40dd3b10 #2 id=0x7f060038} 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:864) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1195) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.Activity.performStart(Activity.java:4548) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) 
09-26 15:46:49.659: E/AndroidRuntime(5847):  ... 11 more 
09-26 15:46:49.679: D/SqliteDatabaseCpp(5847): DB info: path = /data/data/com.friends.roleon/databases , key = DvkadTace, handle: 0x1f5d218, type: w, r/w: (0,2), mode: truncate, disk free size: 213 M 
09-26 15:46:49.829: W/System.err(5847): java.lang.NullPointerException 
09-26 15:46:49.829: W/System.err(5847):  at com.friends.roleon.utility.DataBase.<init>(DataBase.java:27) 
09-26 15:46:49.839: W/System.err(5847):  at com.friends.roleon.list.ListViewGenerator.RecordViewGenerator(ListViewGenerator.java:25) 
09-26 15:46:49.839: W/System.err(5847):  at com.friends.roleon.list.record.RecordList$RecordListFragment$BackgroundTask.doInBackground(RecordList.java:97) 
09-26 15:46:49.839: W/System.err(5847):  at com.friends.roleon.list.record.RecordList$RecordListFragment$BackgroundTask.doInBackground(RecordList.java:1) 
09-26 15:46:49.849: W/System.err(5847):  at android.os.AsyncTask$2.call(AsyncTask.java:264) 
09-26 15:46:49.849: W/System.err(5847):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
09-26 15:46:49.849: W/System.err(5847):  at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
09-26 15:46:49.849: W/System.err(5847):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208) 
09-26 15:46:49.859: W/System.err(5847):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
09-26 15:46:49.859: W/System.err(5847):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
09-26 15:46:49.859: W/System.err(5847):  at java.lang.Thread.run(Thread.java:864) 
09-26 15:46:49.869: D/error(5847): this is the exception :java.lang.NullPointerException 
09-26 15:46:49.879: W/DBVersion(5847): 3 
09-26 15:46:49.879: D/SqliteDatabaseCpp(5847): DB info: open db, path = /data/data/com.friends.roleon/databases , key = DvkadTace, flag = 6, file size = 34816 
09-26 15:46:49.879: W/dalvikvm(5847): threadid=11: thread exiting with uncaught exception (group=0x40aab228) 
09-26 15:46:49.879: D/SqliteDatabaseCpp(5847): DB info: path = /data/data/com.friends.roleon/databases , key = DvkadTace, handle: 0x1f77c90, type: w, r/w: (0,3), mode: truncate, disk free size: 213 M 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847): crash in the same process: AsyncTask #1 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847): java.lang.RuntimeException: An error occured while executing doInBackground() 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at android.os.AsyncTask$3.done(AsyncTask.java:278) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.lang.Thread.run(Thread.java:864) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847): Caused by: java.lang.NullPointerException 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at com.friends.roleon.list.record.RecordList$RecordListFragment$BackgroundTask.doInBackground(RecordList.java:132) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at com.friends.roleon.list.record.RecordList$RecordListFragment$BackgroundTask.doInBackground(RecordList.java:1) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at android.os.AsyncTask$2.call(AsyncTask.java:264) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
09-26 15:46:49.889: E/AndroidRuntime_2_crash(5847):  ... 5 more 
09-26 15:46:49.909: D/SqliteDatabaseCpp(5847): DB info: close db, path = /data/data/com.friends.roleon/databases , key = DvkadTace, handle = 0x1f77c90, type = w, r/w = (0, 2) 

這是我的主類:

public class roleon extends SherlockFragmentActivity implements 
     ActionBar.TabListener { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
     getSupportActionBar().setDisplayShowHomeEnabled(false); 
     getSupportActionBar().setDisplayShowTitleEnabled(false); 

     AddTab(getString(R.string.tab_home)); 
     AddTab(getString(R.string.tab_activities)); 
     AddTab(getString(R.string.tab_settings)); 
    } 

    private void AddTab(String tabName) { 
     ActionBar.Tab tab = getSupportActionBar().newTab(); 
     tab.setText(tabName); 
     tab.setTabListener(this); 
     getSupportActionBar().addTab(tab); 
    } 

    @Override 
    public void onTabSelected(Tab tab, FragmentTransaction ft) { 
     Fragment fragment = null; 
     if (tab.getText().equals(getText(R.string.tab_home))) { 
      fragment = new ModuleList.ModuleListFragment(); 
     } else if (tab.getText().equals(getText(R.string.tab_activities))) { 
      fragment = new ActivityStatePager.FragmentDisplay(); 
     } else if (tab.getText().equals(getText(R.string.tab_settings))) { 
      fragment = new PreferenceScreen.PreferenceScreenFragment(); 
     } 
     getSupportFragmentManager().beginTransaction() 
       .replace(R.id.fragment_container, fragment).commit(); 
    } 

    @Override 
    public void onTabUnselected(Tab tab, FragmentTransaction ft) { 
     // Do nothing 
    } 

    @Override 
    public void onTabReselected(Tab tab, FragmentTransaction ft) { 

    } 
} 

這是從片段類,其中在恢復應用程序崩潰:

public class ActivityStatePager extends SherlockFragmentActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     setTheme(R.style.Theme_Sherlock_NoActionBar); 
     super.onCreate(savedInstanceState); 

     if (savedInstanceState == null) { 
      FragmentDisplay fragment = new FragmentDisplay(); 
      getSupportFragmentManager().beginTransaction() 
        .add(android.R.id.content, fragment).commit(); 
     } 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     ActivityStatePager.this.finish(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     startActivity(new Intent(ActivityStatePager.this, 
       roleon.class)); 
    } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     ActivityStatePager.this.finish(); 
    } 

    public static class FragmentDisplay extends SherlockFragment { 
     // Static Declarations 
     static final int NUM_ITEMS = 3; 

     private View mLayout; 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      View v = inflater 
        .inflate(R.layout.fragment_pager, container, false); 
      mLayout = v.findViewById(R.id.container); 
      SetSpinner(v); 
      return v; 
     } 

     @Override 
     public void onActivityCreated(Bundle savedInstanceState) { 
      super.onActivityCreated(savedInstanceState); 
     } 

     private void SetSpinner(View v) { 
      Spinner eventspinner = (Spinner) v.findViewById(R.id.eventspinner); 

      ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
        getActivity(), android.R.layout.simple_spinner_item); 
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

      DataBase db = new DataBase(getActivity(), "EventStatus"); 
      ArrayList<Record> eventsArray = db.SelectStatusList(); 
      db.close(); 

      for (Iterator<Record> iterator = eventsArray.iterator(); iterator 
        .hasNext();) { 
       Record record = (Record) iterator.next(); 
       adapter.add(record.getEventStatus()); 
      } 

      eventspinner.setAdapter(adapter); 

      eventspinner 
        .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
         public void onItemSelected(AdapterView<?> parent, 
           View view, int pos, long id) { 
          CreateFragment(parent.getItemAtPosition(pos) 
            .toString()); 
         } 

         public void onNothingSelected(AdapterView<?> parent) { 
          // do nothing 
         } 
        }); 
     } 

     public void CreateFragment(String fragLabel) { 
      FragmentTransaction ft = getSherlockActivity() 
        .getSupportFragmentManager().beginTransaction(); 
      Fragment fragment = new ActivityListFragment(fragLabel);//fragLabel 
      ft.add(((LinearLayout) mLayout).getId(), fragment).commit(); 
     } 

     @Override 
     public void onDestroyView() { 
      super.onDestroyView(); 
     } 

     public static class ActivityListFragment extends SherlockFragment { 
      private String mFragTag; 
      private View mFrameLayout; 
      private View mView; 

      public ActivityListFragment(String fragName) { 
       mFragTag = fragName; 
      } 

      public ActivityListFragment(){ 
       // empty constructor 
      } 

      @Override 
      public View onCreateView(LayoutInflater inflater, 
        ViewGroup container, Bundle savedInstanceState) { 
       mView = inflater.inflate(R.layout.fragment_pager_list, 
         container, false); 
       mFrameLayout = mView.findViewById(R.id.frame_layout); 

       return mView; 
      } 

      public void onActivityCreated(Bundle savedInstanceState) { 
       super.onActivityCreated(savedInstanceState); 
       SetFragment(); 
      }; 

      public void SetFragment() { 
       FragmentTransaction ft = getSherlockActivity() 
         .getSupportFragmentManager().beginTransaction(); 

       Fragment fragment = new RecordList.RecordListFragment(); 
       Bundle extras = new Bundle(); 
       extras.putString("eventstatus", mFragTag); 
       fragment.setArguments(extras); 

       ft.replace(((FrameLayout) mFrameLayout).getId(), fragment) 
         .commit(); 
      } 

      @Override 
      public void onDestroyView() { 
       super.onDestroyView(); 
      } 
     } 
    } 
} 

R.id.frame_layout有ID:0x7f060038在R.java文件

這是我的RecordList.RecordListFragment()做的事:

@Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      v = inflater.inflate(R.layout.record_list, container, false); 
      mSP = PreferenceManager.getDefaultSharedPreferences(getActivity()); 
      GetIntent(); 
      getActivity().setTitle(label); 
      new BackgroundTask().execute(); 
      return v; 
     } 


     private class BackgroundTask extends AsyncTask<Void, Void, Void> { 
      ProgressDialog mDialog; 

      protected void onPreExecute() { 
       mDialog = ProgressDialog.show(getActivity(), "", 
         getString(R.string.progress_bar_loading), true); 
      }; 

      @Override 
      protected Void doInBackground(Void... params) { 
       try { 
        mModule = new CRMModule(name, getActivity(), 
          getActivity().getIntent()); 
        mEnableOptions = true; 
        rarray = ListViewGenerator.RecordViewGenerator(mSP, 
          getActivity(), name); 
        Log.d("values","in doinbackground"+mModule+","+rarray); 
        getActivity().runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          // Amazing List View 
          View composer = v.findViewById(R.id.lsComposer); 
          mLsComposer = ((DynamicListView) composer); 
          try { 
           mLsComposer 
             .setAdapter(mAdapter = new PaginationComposerAdapter(
               mSP, getActivity(), 
               rarray, name, 
               label, mEventStatus)); 
           Options(men); 
          } catch (Exception e) { 
           Log.d("exception", "this is here at composer"+e); 
           e.printStackTrace(); 
          } 
          if (mAdapter.getCount() > 10) { 
           mLsComposer 
             .setLoadingView(getActivity() 
               .getLayoutInflater() 
               .inflate(
                 R.layout.lscomposer_loadingview, 
                 null)); 
          } 
          Log.d("complete","at the end"); 

         } 

        }); 
       } catch (final Exception e) { 
        Log.d("error", "this is the exception :"+e); 
        getActivity().runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          mEnableOptions = false; 
          // getActivity().supportInvalidateOptionsMenu(); 
          MethodActivity.CheckLogin(mSP, getActivity() 
            .getIntent(), getActivity(), e); 
         } 
        }); 
       } 
       return null; 
      } 

      protected void onPostExecute(Void result) { 
       mDialog.dismiss(); 
      }; 
     }; 

幫助理清我們的這個問題。 在此先感謝。

回答

0

因爲onDestroy()被觸發時,已經有人叫finish()the android documentation你不應該在onDestroy()打電話finish()。與上onPause()事件調用finish(),如果你要實現的目標是分離從ActivityStatePager您FragmentDisplay你應該將

if (savedInstanceState == null) { 
     FragmentDisplay fragment = new FragmentDisplay(); 
     getSupportFragmentManager().beginTransaction() 
       .add(android.R.id.content, fragment).commit(); 
    } 

onResume()事件和分離的onPause()事件這個片段同樣的事情。使用你的代碼,你每次活動被暫停時都會強制調用onCreate(),這是一個非常有效的操作。

我認爲例外java.lang.IllegalArgumentException: No view found for id 0x7f060038來自您的活動執行的方式爲onResume()

你還可以顯示什麼RecordList.RecordListFragment.BackgroundTask呢? NullPointerException從那裏開始。

編輯後加入RecordList.RecordListFragment.BackgroundTask代碼:

好吧,我想我得到這個。避免在doInBackground()上執行時訪問UIThread。使用AsyncTask.publishProgress()並覆蓋AsyncTask.onProgressUpdate()以在後臺線程上仍有工作要做時更改UI(請參閱AsynTask上的文檔)。在你的情況,你應該把

     View composer = v.findViewById(R.id.lsComposer); 
         mLsComposer = ((DynamicListView) composer); 
         try { 
          mLsComposer 
            .setAdapter(mAdapter = new PaginationComposerAdapter(
              mSP, getActivity(), 
              rarray, name, 
              label, mEventStatus)); 
          Options(men); 
         } catch (Exception e) { 
          Log.d("exception", "this is here at composer"+e); 
          e.printStackTrace(); 
         } 
         if (mAdapter.getCount() > 10) { 
          mLsComposer 
            .setLoadingView(getActivity() 
              .getLayoutInflater() 
              .inflate(
                R.layout.lscomposer_loadingview, 
                null)); 
         } 
         Log.d("complete","at the end"); 

onPostExecute()因爲你想改變你的UI長時間工作完成之後。

+0

我補充說,RecordList.RecordListFragment.BackgroundTask PLZ告訴我現在應該做什麼。 – Jpm

相關問題