I was following AbhiAndroid tutorial, I want my first, MainActivity to start a new, SecondActivity, and my app is basically for displaying a grid of different Android logos and enlarging them to original size when clicked on; However, I get
FATAL EXCEPTION: main
Process: fuckoff.com.gridviewexample, PID: 3127
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference at fuckoff.com.gridviewexample.CustomAdapter.getView(CustomAdapter.java:30)
And yes, I've read all the existing thread, starting from this java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference, this findViewByID returns null
and some other, still didn't find how that could be applied to my case
the class that's the reason of the trouble is:
package fuckoff.com.gridviewexample;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
public class CustomAdapter extends BaseAdapter{
Context context;
int logos[];
LayoutInflater inflter;
public CustomAdapter(Context applicationContext, int[] logos){
this.context = applicationContext;
this.logos = logos;
inflter = (LayoutInflater.from(applicationContext));}
@Override
public int getCount(){return logos.length;}
@Override
public Object getItem(int i){return null;}
@Override
public long getItemId(int i){return 0;}
@Override
public View getView(int i,View view,ViewGroup viewGroup){
view = inflter.inflate(R.layout.activity_gridview,null);
ImageView icon = (ImageView)view.findViewById(R.id.icon);
icon.setImageResource(logos[i]);
return view;}
}