I'm starting to learn Android Studio so please bypass my ignorance.
I'm getting this error code:
2020-05-12 19:32:35.398 13918-13918/com.fdev.Exploding_Tomatoes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.fdev.Exploding_Tomatoes, PID: 13918
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
at android.view.LayoutInflater.from(LayoutInflater.java:282)
at com.fdev.Exploding_Tomatoes.Adapter.onCreateViewHolder(Adapter.java:25)
at com.fdev.Exploding_Tomatoes.Adapter.onCreateViewHolder(Adapter.java:12)
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
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.layout
2020-05-12 19:32:35.398 13918-13918/com.fdev.Exploding_Tomatoes E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:956)
This is my Adapter-script to get a (hopefully) working Recyclerview. The error is, or at least I think so, at "View view = LayoutInflater.from(context).inflate(R.layout.row, null);" I tried searching but couldn't find anything working. I substituted "null" with "this", removed it. But nothing.
package com.fdev.Exploding_Tomatoes;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class Adapter extends RecyclerView.Adapter<MyHolder> {
private Context context;
Context c;
ArrayList<Model> models;
public Adapter(Context c, ArrayList<Model> models) {
this.c = c;
this.models = models;
}
@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.row, null);
return new MyHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyHolder myholder, int position) {
myholder.mTitle.setText(models.get(1).getTitle());
myholder.mNumber.setText(models.get(1).getNumber());
}
@Override
public int getItemCount() {
return models.size();
}
}
Any help is appreciated!!! Thanks