Don't know if you have met some problems, is the problem about recyclerview set adapter After recent projects online, go to the background the log statistics, found that most of them are about recyclerview set adapter to get empty
# main (1)
Java. Lang. NullPointerException
Attempt to invoke virtual method 'void android. Support. V7. Widget. RecyclerView. SetAdapter (android. Support. V7. Widget. RecyclerView $Adapter)' on a null object reference The error stack
1 com. Ucfo. Youcaiwx. Module. User. Activity. MineOrderFormActivity. New (169) MineOrderFormActivity. Java: 2 com. Ucfo. Youcaiwx. Module. User. Activity. MineOrderFormActivity. GetMineOrderFromList (MineOrderFormActivity. Java: 146) 3 com. Ucfo. Youcaiwx. For. Do. Long. The new $1. For (66) MineOrderFormPresenter. Java: 4 com. Lzy. Do.. If the do. Int $1. Run (42) FirstCacheRequestPolicy. Java: 5. Android OS. Handler. HandleCallback (Handler. Java: 808) 6. Android OS. Handler. DispatchMessage (Handler. Java: 101) 7. Android OS. Stars. Loop (166). Which Java: 8 android. App. ActivityThread. Main (ActivityThread. Java: 7529) 9 Java. Lang. Reflect. Method. Invoke (Native Method) 10 com. Android. Internal. OS. Zygote $MethodAndArgsCaller. Run (Zygote. Java: 245) 11 com. Android. Internal. OS. ZygoteInit. Main (ZygoteInit. Java: 921)
Then I set up the adapter code
Private void initAdapter () { If (mineOrderFormListAdapter==null) { MineOrderFormListAdapter=new mineOrderFormListAdapter (this, a list); } If (mineOrderFormListAdapter!=null) { MineOrderFormListAdapter. NotifyDataSetChanged (); Recyclerview. SetAdapter (mineOrderFormListAdapter); } MineOrderFormListAdapter. SetOnItemClick (new ItemClickHelper. OnItemClickListener () { @ Override Public void onItemClick (View View, int position) { String payStatus=list. Get (position). GetPay_status (); Boolean equals=TextUtils. Equals (payStatus, String. The valueOf (" 3 ")); if (! Equals) { Bundle Bundle=new Bundle (); Bundle. PutString (Constant. ORDER_NUM, list the get (position). GetOrder_num ()); Bundle. PutInt (Constant STATUS, Integer. The parseInt (payStatus)); StartActivity (MineOrderFormDetailActivity. Class, bundle); } } }); }
Every time this method is the network request is successful will call later, I understand the range is right, but a lot of similar background or statistics such mistakes Hey hey, the younger brother in the Android, average bosses solution, how to write will avoid this problem
CodePudding user response:
Null pointer recyclerview. SetAdapter () - & gt; Recyclerview is empty, see where the initialization