Android volley singleton and custom gridview adapter
I am using a custom gridview
adapter to show images with volley singleton. But when I run it it returns the onErrorResponse. It looks like the adapter is not even set properly, is it something with where i set the adapter? I have tried setting it in onCreate
but same error.
The adapter class looked fine so I think the problem is in MainActivity
.
MainActivity.java:
public class MainActivity extends AppCompatActivity
private final int THUMBNAIL_SIZE = 250;
private final String KEY = "IMAGE";
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
private static final String URLS =
"http://10.0.2.2/Android%20A4_1/germany.png",
"http://10.0.2.2/Android%20A4_1/indonesia.png",
"http://10.0.2.2/Android%20A4_1/japan.png",
"http://10.0.2.2/Android%20A4_1/sarawak.png",
"http://10.0.2.2/Android%20A4_1/singapore.png",
"http://10.0.2.2/Android%20A4_1/switzerland.png",
;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0; i<URLS.length; i++)
LoadingImages(URLS[i]);
private void LoadingImages(String url)
ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap image = response.getBitmap();
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(image, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
bitmaps.add(thumbnail);
GridView gridView = (GridView)findViewById(R.id.grid_layout);
final ImageAdapter imageAdapter = new ImageAdapter(MainActivity.this, bitmaps);
gridView.setAdapter(imageAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra(KEY, URLS[i]);
startActivity(intent);
);
@Override
public void onErrorResponse(VolleyError error)
Log.e("error", error.getMessage());
);
The Adapter class:
public class ImageAdapter extends BaseAdapter
private Context mContext;
private ArrayList<Bitmap> bitmaps;
public ImageAdapter(Context context, ArrayList<Bitmap> bitmaps)
this.mContext = context;
this.bitmaps = bitmaps;
@Override
public int getCount()
return 0;
@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)
if (view == null)
final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
view = layoutInflater.inflate(R.layout.griditems, null);
MyViewHolder myViewHolder = new MyViewHolder(view);
view.setTag(myViewHolder);
MyViewHolder myViewHolder = (MyViewHolder)view.getTag();
myViewHolder.img.setImageBitmap(bitmaps.get(i));
return view;
public class MyViewHolder
public ImageView img;
public MyViewHolder(View view)
img = view.findViewById(R.id.image1);
My Singleton:
public class MySingleton
private static MySingleton instance;
private RequestQueue requestQueue;
private ImageLoader imageLoader;
private static Context context;
private MySingleton(Context context)
this.context = context;
requestQueue = Volley.newRequestQueue(context);
imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache()
private final LruCache<String, Bitmap> cache = new LruCache<>(6);
@Override
public Bitmap getBitmap(String url)
Bitmap bmp = cache.get(url);
if (bmp == null)
System.out.println("Not in cache");
else
System.out.println("In cache");
return bmp;
@Override
public void putBitmap(String url, Bitmap bitmap)
System.out.println("Put in cache");
cache.put(url, bitmap);
);
public static synchronized MySingleton getInstance(Context context)
if (instance == null)
instance = new MySingleton(context);
return instance;
public ImageLoader getImageLoader()
return imageLoader;
Main2Activity:
public class Main2Activity extends AppCompatActivity
private ImageView imageView;
private final String KEY = "IMAGE";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
imageView = (ImageView)findViewById(R.id.imageView);
Bundle bundle = getIntent().getExtras();
String url = bundle.getString(KEY);
LoadingImages(url);
private void LoadingImages(String url)
final ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap bitmap = response.getBitmap();
imageView.setImageBitmap(bitmap);
@Override
public void onErrorResponse(VolleyError error)
Log.e("Error", error.getMessage());
);
java android singleton android-volley android-gridview
add a comment |
I am using a custom gridview
adapter to show images with volley singleton. But when I run it it returns the onErrorResponse. It looks like the adapter is not even set properly, is it something with where i set the adapter? I have tried setting it in onCreate
but same error.
The adapter class looked fine so I think the problem is in MainActivity
.
MainActivity.java:
public class MainActivity extends AppCompatActivity
private final int THUMBNAIL_SIZE = 250;
private final String KEY = "IMAGE";
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
private static final String URLS =
"http://10.0.2.2/Android%20A4_1/germany.png",
"http://10.0.2.2/Android%20A4_1/indonesia.png",
"http://10.0.2.2/Android%20A4_1/japan.png",
"http://10.0.2.2/Android%20A4_1/sarawak.png",
"http://10.0.2.2/Android%20A4_1/singapore.png",
"http://10.0.2.2/Android%20A4_1/switzerland.png",
;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0; i<URLS.length; i++)
LoadingImages(URLS[i]);
private void LoadingImages(String url)
ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap image = response.getBitmap();
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(image, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
bitmaps.add(thumbnail);
GridView gridView = (GridView)findViewById(R.id.grid_layout);
final ImageAdapter imageAdapter = new ImageAdapter(MainActivity.this, bitmaps);
gridView.setAdapter(imageAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra(KEY, URLS[i]);
startActivity(intent);
);
@Override
public void onErrorResponse(VolleyError error)
Log.e("error", error.getMessage());
);
The Adapter class:
public class ImageAdapter extends BaseAdapter
private Context mContext;
private ArrayList<Bitmap> bitmaps;
public ImageAdapter(Context context, ArrayList<Bitmap> bitmaps)
this.mContext = context;
this.bitmaps = bitmaps;
@Override
public int getCount()
return 0;
@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)
if (view == null)
final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
view = layoutInflater.inflate(R.layout.griditems, null);
MyViewHolder myViewHolder = new MyViewHolder(view);
view.setTag(myViewHolder);
MyViewHolder myViewHolder = (MyViewHolder)view.getTag();
myViewHolder.img.setImageBitmap(bitmaps.get(i));
return view;
public class MyViewHolder
public ImageView img;
public MyViewHolder(View view)
img = view.findViewById(R.id.image1);
My Singleton:
public class MySingleton
private static MySingleton instance;
private RequestQueue requestQueue;
private ImageLoader imageLoader;
private static Context context;
private MySingleton(Context context)
this.context = context;
requestQueue = Volley.newRequestQueue(context);
imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache()
private final LruCache<String, Bitmap> cache = new LruCache<>(6);
@Override
public Bitmap getBitmap(String url)
Bitmap bmp = cache.get(url);
if (bmp == null)
System.out.println("Not in cache");
else
System.out.println("In cache");
return bmp;
@Override
public void putBitmap(String url, Bitmap bitmap)
System.out.println("Put in cache");
cache.put(url, bitmap);
);
public static synchronized MySingleton getInstance(Context context)
if (instance == null)
instance = new MySingleton(context);
return instance;
public ImageLoader getImageLoader()
return imageLoader;
Main2Activity:
public class Main2Activity extends AppCompatActivity
private ImageView imageView;
private final String KEY = "IMAGE";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
imageView = (ImageView)findViewById(R.id.imageView);
Bundle bundle = getIntent().getExtras();
String url = bundle.getString(KEY);
LoadingImages(url);
private void LoadingImages(String url)
final ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap bitmap = response.getBitmap();
imageView.setImageBitmap(bitmap);
@Override
public void onErrorResponse(VolleyError error)
Log.e("Error", error.getMessage());
);
java android singleton android-volley android-gridview
add a comment |
I am using a custom gridview
adapter to show images with volley singleton. But when I run it it returns the onErrorResponse. It looks like the adapter is not even set properly, is it something with where i set the adapter? I have tried setting it in onCreate
but same error.
The adapter class looked fine so I think the problem is in MainActivity
.
MainActivity.java:
public class MainActivity extends AppCompatActivity
private final int THUMBNAIL_SIZE = 250;
private final String KEY = "IMAGE";
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
private static final String URLS =
"http://10.0.2.2/Android%20A4_1/germany.png",
"http://10.0.2.2/Android%20A4_1/indonesia.png",
"http://10.0.2.2/Android%20A4_1/japan.png",
"http://10.0.2.2/Android%20A4_1/sarawak.png",
"http://10.0.2.2/Android%20A4_1/singapore.png",
"http://10.0.2.2/Android%20A4_1/switzerland.png",
;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0; i<URLS.length; i++)
LoadingImages(URLS[i]);
private void LoadingImages(String url)
ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap image = response.getBitmap();
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(image, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
bitmaps.add(thumbnail);
GridView gridView = (GridView)findViewById(R.id.grid_layout);
final ImageAdapter imageAdapter = new ImageAdapter(MainActivity.this, bitmaps);
gridView.setAdapter(imageAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra(KEY, URLS[i]);
startActivity(intent);
);
@Override
public void onErrorResponse(VolleyError error)
Log.e("error", error.getMessage());
);
The Adapter class:
public class ImageAdapter extends BaseAdapter
private Context mContext;
private ArrayList<Bitmap> bitmaps;
public ImageAdapter(Context context, ArrayList<Bitmap> bitmaps)
this.mContext = context;
this.bitmaps = bitmaps;
@Override
public int getCount()
return 0;
@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)
if (view == null)
final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
view = layoutInflater.inflate(R.layout.griditems, null);
MyViewHolder myViewHolder = new MyViewHolder(view);
view.setTag(myViewHolder);
MyViewHolder myViewHolder = (MyViewHolder)view.getTag();
myViewHolder.img.setImageBitmap(bitmaps.get(i));
return view;
public class MyViewHolder
public ImageView img;
public MyViewHolder(View view)
img = view.findViewById(R.id.image1);
My Singleton:
public class MySingleton
private static MySingleton instance;
private RequestQueue requestQueue;
private ImageLoader imageLoader;
private static Context context;
private MySingleton(Context context)
this.context = context;
requestQueue = Volley.newRequestQueue(context);
imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache()
private final LruCache<String, Bitmap> cache = new LruCache<>(6);
@Override
public Bitmap getBitmap(String url)
Bitmap bmp = cache.get(url);
if (bmp == null)
System.out.println("Not in cache");
else
System.out.println("In cache");
return bmp;
@Override
public void putBitmap(String url, Bitmap bitmap)
System.out.println("Put in cache");
cache.put(url, bitmap);
);
public static synchronized MySingleton getInstance(Context context)
if (instance == null)
instance = new MySingleton(context);
return instance;
public ImageLoader getImageLoader()
return imageLoader;
Main2Activity:
public class Main2Activity extends AppCompatActivity
private ImageView imageView;
private final String KEY = "IMAGE";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
imageView = (ImageView)findViewById(R.id.imageView);
Bundle bundle = getIntent().getExtras();
String url = bundle.getString(KEY);
LoadingImages(url);
private void LoadingImages(String url)
final ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap bitmap = response.getBitmap();
imageView.setImageBitmap(bitmap);
@Override
public void onErrorResponse(VolleyError error)
Log.e("Error", error.getMessage());
);
java android singleton android-volley android-gridview
I am using a custom gridview
adapter to show images with volley singleton. But when I run it it returns the onErrorResponse. It looks like the adapter is not even set properly, is it something with where i set the adapter? I have tried setting it in onCreate
but same error.
The adapter class looked fine so I think the problem is in MainActivity
.
MainActivity.java:
public class MainActivity extends AppCompatActivity
private final int THUMBNAIL_SIZE = 250;
private final String KEY = "IMAGE";
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
private static final String URLS =
"http://10.0.2.2/Android%20A4_1/germany.png",
"http://10.0.2.2/Android%20A4_1/indonesia.png",
"http://10.0.2.2/Android%20A4_1/japan.png",
"http://10.0.2.2/Android%20A4_1/sarawak.png",
"http://10.0.2.2/Android%20A4_1/singapore.png",
"http://10.0.2.2/Android%20A4_1/switzerland.png",
;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0; i<URLS.length; i++)
LoadingImages(URLS[i]);
private void LoadingImages(String url)
ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap image = response.getBitmap();
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(image, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
bitmaps.add(thumbnail);
GridView gridView = (GridView)findViewById(R.id.grid_layout);
final ImageAdapter imageAdapter = new ImageAdapter(MainActivity.this, bitmaps);
gridView.setAdapter(imageAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra(KEY, URLS[i]);
startActivity(intent);
);
@Override
public void onErrorResponse(VolleyError error)
Log.e("error", error.getMessage());
);
The Adapter class:
public class ImageAdapter extends BaseAdapter
private Context mContext;
private ArrayList<Bitmap> bitmaps;
public ImageAdapter(Context context, ArrayList<Bitmap> bitmaps)
this.mContext = context;
this.bitmaps = bitmaps;
@Override
public int getCount()
return 0;
@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)
if (view == null)
final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
view = layoutInflater.inflate(R.layout.griditems, null);
MyViewHolder myViewHolder = new MyViewHolder(view);
view.setTag(myViewHolder);
MyViewHolder myViewHolder = (MyViewHolder)view.getTag();
myViewHolder.img.setImageBitmap(bitmaps.get(i));
return view;
public class MyViewHolder
public ImageView img;
public MyViewHolder(View view)
img = view.findViewById(R.id.image1);
My Singleton:
public class MySingleton
private static MySingleton instance;
private RequestQueue requestQueue;
private ImageLoader imageLoader;
private static Context context;
private MySingleton(Context context)
this.context = context;
requestQueue = Volley.newRequestQueue(context);
imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache()
private final LruCache<String, Bitmap> cache = new LruCache<>(6);
@Override
public Bitmap getBitmap(String url)
Bitmap bmp = cache.get(url);
if (bmp == null)
System.out.println("Not in cache");
else
System.out.println("In cache");
return bmp;
@Override
public void putBitmap(String url, Bitmap bitmap)
System.out.println("Put in cache");
cache.put(url, bitmap);
);
public static synchronized MySingleton getInstance(Context context)
if (instance == null)
instance = new MySingleton(context);
return instance;
public ImageLoader getImageLoader()
return imageLoader;
Main2Activity:
public class Main2Activity extends AppCompatActivity
private ImageView imageView;
private final String KEY = "IMAGE";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
imageView = (ImageView)findViewById(R.id.imageView);
Bundle bundle = getIntent().getExtras();
String url = bundle.getString(KEY);
LoadingImages(url);
private void LoadingImages(String url)
final ImageLoader imageLoader = MySingleton.getInstance(getApplicationContext()).getImageLoader();
imageLoader.get(url, new ImageLoader.ImageListener()
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
Bitmap bitmap = response.getBitmap();
imageView.setImageBitmap(bitmap);
@Override
public void onErrorResponse(VolleyError error)
Log.e("Error", error.getMessage());
);
java android singleton android-volley android-gridview
java android singleton android-volley android-gridview
edited Nov 14 '18 at 7:15
Brandon Bong
asked Nov 14 '18 at 3:27
Brandon BongBrandon Bong
267
267
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
change This methods
@Override
public int getCount()
return 0;
@Override
public Object getItem(int i)
return null;
@Override
public long getItemId(int i)
return 0;
To
@Override
public int getCount()
return bitmaps.size;
@Override
public Object getItem(int i)
return bitmaps.get(i);
@Override
public long getItemId(int i)
return i;
Thanks that makes the gridview showing. However when i click on the first image it gives me an error outOfBoundException : length =6; index = 6... Why is the image index starts with 6 instead of 0?
– Brandon Bong
Nov 14 '18 at 4:43
intent.putExtra(KEY, URLS[i]);
this line is causing the error
– Brandon Bong
Nov 14 '18 at 4:44
To: intent.putExtra(KEY, URLS[i]); change intent.putExtra("KEY", URLS[i]);
– suresh madaparthi
Nov 14 '18 at 4:46
That doesnt change the index, the KEY is set to "IMAGE" as a name.
– Brandon Bong
Nov 14 '18 at 4:51
ok its working now or not
– suresh madaparthi
Nov 14 '18 at 4:58
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292766%2fandroid-volley-singleton-and-custom-gridview-adapter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
change This methods
@Override
public int getCount()
return 0;
@Override
public Object getItem(int i)
return null;
@Override
public long getItemId(int i)
return 0;
To
@Override
public int getCount()
return bitmaps.size;
@Override
public Object getItem(int i)
return bitmaps.get(i);
@Override
public long getItemId(int i)
return i;
Thanks that makes the gridview showing. However when i click on the first image it gives me an error outOfBoundException : length =6; index = 6... Why is the image index starts with 6 instead of 0?
– Brandon Bong
Nov 14 '18 at 4:43
intent.putExtra(KEY, URLS[i]);
this line is causing the error
– Brandon Bong
Nov 14 '18 at 4:44
To: intent.putExtra(KEY, URLS[i]); change intent.putExtra("KEY", URLS[i]);
– suresh madaparthi
Nov 14 '18 at 4:46
That doesnt change the index, the KEY is set to "IMAGE" as a name.
– Brandon Bong
Nov 14 '18 at 4:51
ok its working now or not
– suresh madaparthi
Nov 14 '18 at 4:58
|
show 7 more comments
change This methods
@Override
public int getCount()
return 0;
@Override
public Object getItem(int i)
return null;
@Override
public long getItemId(int i)
return 0;
To
@Override
public int getCount()
return bitmaps.size;
@Override
public Object getItem(int i)
return bitmaps.get(i);
@Override
public long getItemId(int i)
return i;
Thanks that makes the gridview showing. However when i click on the first image it gives me an error outOfBoundException : length =6; index = 6... Why is the image index starts with 6 instead of 0?
– Brandon Bong
Nov 14 '18 at 4:43
intent.putExtra(KEY, URLS[i]);
this line is causing the error
– Brandon Bong
Nov 14 '18 at 4:44
To: intent.putExtra(KEY, URLS[i]); change intent.putExtra("KEY", URLS[i]);
– suresh madaparthi
Nov 14 '18 at 4:46
That doesnt change the index, the KEY is set to "IMAGE" as a name.
– Brandon Bong
Nov 14 '18 at 4:51
ok its working now or not
– suresh madaparthi
Nov 14 '18 at 4:58
|
show 7 more comments
change This methods
@Override
public int getCount()
return 0;
@Override
public Object getItem(int i)
return null;
@Override
public long getItemId(int i)
return 0;
To
@Override
public int getCount()
return bitmaps.size;
@Override
public Object getItem(int i)
return bitmaps.get(i);
@Override
public long getItemId(int i)
return i;
change This methods
@Override
public int getCount()
return 0;
@Override
public Object getItem(int i)
return null;
@Override
public long getItemId(int i)
return 0;
To
@Override
public int getCount()
return bitmaps.size;
@Override
public Object getItem(int i)
return bitmaps.get(i);
@Override
public long getItemId(int i)
return i;
answered Nov 14 '18 at 3:56
suresh madaparthisuresh madaparthi
25219
25219
Thanks that makes the gridview showing. However when i click on the first image it gives me an error outOfBoundException : length =6; index = 6... Why is the image index starts with 6 instead of 0?
– Brandon Bong
Nov 14 '18 at 4:43
intent.putExtra(KEY, URLS[i]);
this line is causing the error
– Brandon Bong
Nov 14 '18 at 4:44
To: intent.putExtra(KEY, URLS[i]); change intent.putExtra("KEY", URLS[i]);
– suresh madaparthi
Nov 14 '18 at 4:46
That doesnt change the index, the KEY is set to "IMAGE" as a name.
– Brandon Bong
Nov 14 '18 at 4:51
ok its working now or not
– suresh madaparthi
Nov 14 '18 at 4:58
|
show 7 more comments
Thanks that makes the gridview showing. However when i click on the first image it gives me an error outOfBoundException : length =6; index = 6... Why is the image index starts with 6 instead of 0?
– Brandon Bong
Nov 14 '18 at 4:43
intent.putExtra(KEY, URLS[i]);
this line is causing the error
– Brandon Bong
Nov 14 '18 at 4:44
To: intent.putExtra(KEY, URLS[i]); change intent.putExtra("KEY", URLS[i]);
– suresh madaparthi
Nov 14 '18 at 4:46
That doesnt change the index, the KEY is set to "IMAGE" as a name.
– Brandon Bong
Nov 14 '18 at 4:51
ok its working now or not
– suresh madaparthi
Nov 14 '18 at 4:58
Thanks that makes the gridview showing. However when i click on the first image it gives me an error outOfBoundException : length =6; index = 6... Why is the image index starts with 6 instead of 0?
– Brandon Bong
Nov 14 '18 at 4:43
Thanks that makes the gridview showing. However when i click on the first image it gives me an error outOfBoundException : length =6; index = 6... Why is the image index starts with 6 instead of 0?
– Brandon Bong
Nov 14 '18 at 4:43
intent.putExtra(KEY, URLS[i]);
this line is causing the error– Brandon Bong
Nov 14 '18 at 4:44
intent.putExtra(KEY, URLS[i]);
this line is causing the error– Brandon Bong
Nov 14 '18 at 4:44
To: intent.putExtra(KEY, URLS[i]); change intent.putExtra("KEY", URLS[i]);
– suresh madaparthi
Nov 14 '18 at 4:46
To: intent.putExtra(KEY, URLS[i]); change intent.putExtra("KEY", URLS[i]);
– suresh madaparthi
Nov 14 '18 at 4:46
That doesnt change the index, the KEY is set to "IMAGE" as a name.
– Brandon Bong
Nov 14 '18 at 4:51
That doesnt change the index, the KEY is set to "IMAGE" as a name.
– Brandon Bong
Nov 14 '18 at 4:51
ok its working now or not
– suresh madaparthi
Nov 14 '18 at 4:58
ok its working now or not
– suresh madaparthi
Nov 14 '18 at 4:58
|
show 7 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292766%2fandroid-volley-singleton-and-custom-gridview-adapter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown