Monday, 15 July 2013

android - app crashes after exiting? -


I am creating an application that has multiple horizontal visibility, overall the app runs well, but when the user is out If the exit boom app crashes, logs I think that there are several markers in onPostExecute:

  rootview = inflater.inflate (R.Layout.three_framement, container, incorrect); L1 = (linear timer) rootview.findvibid (rid. Leaner layout 1); L3 = (TextView) rootView.findViewById (R.id.CheckTest); Contract = (progress bar) rootview.findvibid (RID progressive); BooksList = New Arrestist & lt; Books & gt; (); New JSONAsyncTask () Execute ("http://192.168.30.3/actors/book_tab2.php"); CenterLockHorizontalScrollview = (CentreLockHorizontalScrollView) rootView.findViewById (R.id.HMscrollView); Adapter = new cardhome adapter (getActivity), R. timber out.ro_home_card, book list); CenterLockHorizontalScrollview.SsetAdapter (TabThreeFragment.this, adapter); RootView.setLayoutParams (New Frame Layout. LayoutParams (Frame Layout. LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); }}  

onPostExecute:

  protected void onPostExecute (Boolean result) {adapter.notifyDataSetChanged (); If (result == incorrect) toast. MakeActivity (), "unable to get data from server", Toast.LNGTH_LONG). Show (); If (list of books! = Null) {adapter = new cardhome adapter (getActivity). GetApplicationContext (), R.Liloot.ro_heemcard, Book List); CenterLockHorizontalScrollview.SsetAdapter (TabThreeFragment.this, adapter); }  

Error:

  03-07 11: 49: 21.478: E / Android time (9703): fatal exception: main 03-07 11:49 : 21.478: e / AndroidRuntime (9703): java.lang.NullPointerException 03-07 11: 49: 21.478: e / AndroidRuntime (9703): $ JSONAsyncTask.onPostExecute on br.liveo.fragments.TabThreeFragment (TabThreeFragment.java:344) 03-07 11: 49: 21.478: e / AndroidRuntime (9703): br.liveo.fragments.TabThreeFragment 03-07 11 to $ JSONAsyncTask.onPostExecute (TabThreeFragment.java:1): 49: 21.478: e / AndroidRuntime (9703) : 03-07 on android.os.AsyncTask.finish (AsyncTask.java:631) 11: 49: 21.478: e / AndroidRuntime (9703): on android.os.AsyncTask.access $ 600 (AsyncTask.java:177) 03 - 07 11: 49: 21.478: e / AndroidRuntime (9703): 49 :: 21.478: e / AndroidRuntime (9703): on Android android.os.AsyncTask $ InternalHandler.handleMessage (AsyncTask.java:644) 03-07 At 11 OSHANDLER DISVEPECH MESSAGE (Handler. Java: 99) 03-07 11: 49: 21.478: E / Android Random (9 703): Android.OS Lopper. On Loop (Looper.java:137) 03-07 11: 49: 21.478: E / AndroidRuntime (9703): android.app.ActivityThread.main (ActivityThread.java:4961) on 03-07 11: 49: 21.478: E / AndroidRuntime (9703): java.lang.reflect.Method.invokeNative at (native methode) 03-07 11: 49: 21.478: E / Android Retentmann (9 703): at java.lang.reflect.Method.invoke (method Kjawatr 11) 03-07 11: 49: 21.478: e / AndroidRuntime (9703): on com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1004) 03-07 11: 49: 21.478: e / AndroidRuntime (9703): com.android.internal.os.ZygoteInit.main (ZygoteInit.java:771) 03-07 11: 49: 21.478: e / Androidrentaim (9703): on Dalvik.system.NativeStart.main (Basic method)  

When you exit the application They are, and are still executed to execute the post, then attempts to open the activity to display a toast or to create a new adapter, but because your application has been killed, the functionality is no longer present. , So you get a null pointer exception. If you want to show a toast or a new adapter, or after hitting your work in the ondstory function of your activity, check if (getActivity ()! = Null)

  PostExecute (Boolean result) on protected void {if (getActivity ()! = Null) {adapter.notifyDataSetChanged (); If (result == incorrect) toast. MakeActivity (), "unable to get data from server", Toast.LNGTH_LONG). Show (); If (list of books! = Null) {adapter = new cardhome adapter (getActivity). GetApplicationContext (), R.Liloot.ro_heemcard, Book List); CenterLockHorizontalScrollview.SsetAdapter (TabThreeFragment.this, adapter); }}  

No comments:

Post a Comment