Home > Mobile >  Some problems about Recyclerview
Some problems about Recyclerview

Time:09-26

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

CodePudding user response:

reference 1/f, travel snail reply:
recyclerview. SetAdapter () null pointer - & gt; Recyclerview is empty, take a look at where the initialization of

I this is in the activity's oncreate Butterknife binding View, then the empty problems constantly

CodePudding user response:

Generally do not encounter this problem, when see you ButterKnife call binding, is before or after the initAdapter, it is possible that you are in the debugger to a wrong uploaded to the server

CodePudding user response:

reference travel snail reply: 3/f
generally do not encounter this problem, when see you ButterKnife call binding, is before or after the initAdapter, it is possible that you are in debugging process of the wrong uploaded to the server

I am bound in onCreate, network request is after binding request, the request is successful after initadapter will call
 
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO: add the setContentView (... ) invocation
ButterKnife. Bind (this);
}
@ Override
Protected void onResume () {
Super. OnResume ();
MineOrderFormPresenter. GetMineOrderFromList (user_id);
}

@ Override
Protected int the setContentView () {
Return R.l ayout. Activity_mine_order_form;
}

@ Override
Public void getMineOrderFromList (MineOrderListBean data) {
If (data!=null) {
If (data. GetData ()!=null & amp; & Data. GetData (). The size () & gt; 0 {
List DataBeanList=data. GetData ();
List. The clear ();
List. The addAll (dataBeanList);

InitAdapter ();
If (loadinglayout!=null) {
Loadinglayout. ShowContent ();
}
} else {
If (loadinglayout!=null) {
Loadinglayout. ShowEmpty ();
}
}
} else {
If (loadinglayout!=null) {
Loadinglayout. ShowEmpty ();
}
}
}

This is a very normal network operation, who knows can appear sometimes recyclerview is empty

CodePudding user response:

I feel is butterknife appear problem, butterknife8.8.1 version

CodePudding user response:

Your super. The oncreate () there should be a problem! If the init method before the setContentView call will surely null pointer

CodePudding user response:

reference 4 floor situation is very good response:
Quote: reference travel snail reply: 3/f

Generally do not encounter this problem, when see you ButterKnife call binding, is before or after the initAdapter, it is possible that you are in debugging process of the wrong uploaded to the server

I am bound in onCreate, network request is after binding request, the request is successful after initadapter will call
 
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO: add the setContentView (... ) invocation
ButterKnife. Bind (this);
}
@ Override
Protected void onResume () {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related