Я делаю приложение в android студии. Когда я нажимаю кнопку, мое приложение падает. В журнале я вижу ошибку NullPoniterException, без номеров строк, которые я написал. Это мой Logcat: (Это внутренние коды приложений, написанные не мной. Мне нужен номер строки, который я написал, который вызывает ошибку.)
2020-01-20 14:06:02.790 16599-16599/com.tanvirgeek.sync E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tanvirgeek.sync, PID: 16599
java.lang.NullPointerException: Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$ViewHolder.itemView' on a null object reference
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7079)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3540)
at android.view.View.measure(View.java:20361)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:825)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:511)
at android.view.View.measure(View.java:20361)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6355)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:214)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:20361)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6355)
at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401)
at android.view.View.measure(View.java:20361)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6355)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:214)
at android.view.View.measure(View.java:20361)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6355)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1705)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:797)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:657)
at android.view.View.measure(View.java:20361)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6355)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:214)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:750)
at android.view.View.measure(View.java:20361)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2896)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1778)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2051)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1663)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7546)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:916)
at android.view.Choreographer.doCallbacks(Choreographer.java:718)
at android.view.Choreographer.doFrame(Choreographer.java:650)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:902)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:232)
at android.app.ActivityThread.main(ActivityThread.java:6802)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Как я могу получить строку, которую я написал, вызывая ошибку? Эти номера строк выше являются внутренними кодами приложения, не написанными мной.
КОД RecyclerAdapter:
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyviewHolder> {
private ArrayList<Contact> contactArrayList = new ArrayList<>();
public RecyclerAdapter(ArrayList<Contact> arrayList){
this.contactArrayList = arrayList;
}
@NonNull
@Override
public MyviewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view,parent,false);
return null;
}
@Override
public void onBindViewHolder(@NonNull MyviewHolder holder, int position) {
holder.name.setText(contactArrayList.get(position).getName());
int msyncStatus = contactArrayList.get(position).getSyncstatus();
if(msyncStatus == DBContact.SYNC_STATUS_OK){
holder.msyncStatus.setImageResource(R.drawable.tick);
}else{
holder.msyncStatus.setImageResource(R.drawable.sync);
}
}
@Override
public int getItemCount() {
return contactArrayList.size();
}
public static class MyviewHolder extends RecyclerView.ViewHolder{
ImageView msyncStatus;
TextView name;
public MyviewHolder(@NonNull View itemView) {
super(itemView);
msyncStatus = (ImageView) itemView.findViewById(R.id.imgSynch);
name = (TextView) itemView.findViewById(R.id.txtName);
}
}
}
Спасибо.