Can somebody point out the error in my recyclerview?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Can somebody point out the error in my recyclerview?



This is my code fragment.



Actually I am getting error of null pointer exception pointing in the adapter's first line.


null pointer exception



Same thing I have done in other project and that is working fine.
I don't know what's wrong with it is? Please help me.


public class Tab1 extends Fragment

RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
Tab1RecyclerViewAdapter adapter;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.tab1,container,false);
recyclerView = (RecyclerView) view.findViewById(R.id.tab1RecyclerView);
adapter = new Tab1RecyclerViewAdapter(this.getActivity());
layoutManager = new LinearLayoutManager(this.getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
return view;




My adapter


public class Tab1RecyclerViewAdapter extends RecyclerView.Adapter<Tab1RecyclerViewAdapter.RecyclerViewHolder>
Context context;
Tab1RecyclerViewAdapter(Context ctx)
context = ctx;


@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType)

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab1_item,parent,true);
RecyclerViewHolder recyclerViewHolder = new RecyclerViewHolder(view);
//soundNamePref = context.getSharedPreferences("My_Prefs", Context.MODE_PRIVATE);
//soundPositionPref = context.getSharedPreferences("My_Prefs",Context.MODE_PRIVATE);
return recyclerViewHolder;



@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position)



@Override
public int getItemCount()
return 2;


public class RecyclerViewHolder extends RecyclerView.ViewHolder
TextView textView;
// CheckBox checkBox;

public RecyclerViewHolder(View itemView)

super(itemView);
textView = (TextView) itemView.findViewById(R.id.textView);






My tab1_item.xml
where probably the error is because else where everything looks fine .... so plz see this also


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">


<TextView
android:textAlignment="center"
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World"
android:textSize="24dp"
android:textColor="#000"
/>
<view
android:background="#000"
android:layout_below="@+id/textView"
android:layout_width="match_parent"
android:layout_height="2dp"

/>

</RelativeLayout>



This is the error I am getting.



errr





You could try inflating your ViewHolder layout without passing the parent like this: View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab1_item, null);
– privoid
Aug 12 at 12:24


ViewHolder


View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab1_item, null);





there seems to be something wrong in your xml. Please post tab1_item.xml code
– Max
Aug 12 at 14:20


xml


tab1_item.xml




1 Answer
1



the problem is the view the first letter of View has to be capital. it should look like this


view


View


<View
android:background="#000"
android:layout_below="@+id/textView"
android:layout_width="match_parent"
android:layout_height="2dp"

/>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard