I am new on android and i am self learner i got the error during full screen activity i.e.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.project.sumit.diems_onlinenoticeboard, PID: 25646
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.sumit.diems_onlinenoticeboard/com.project.sumit.diems_onlinenoticeboard.FullImageActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2326)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5264)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at com.project.sumit.diems_onlinenoticeboard.NoticeListAdapter.getItem(NoticeListAdapter.java:38)
at com.project.sumit.diems_onlinenoticeboard.FullImageActivity.onCreate(FullImageActivity.java:36)
at android.app.Activity.performCreate(Activity.java:5975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5264)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
My NoticeListAdpater code is
public class NoticeListAdapter extends BaseAdapter
{
private Context context;
private int layout;
private ArrayList foodsList;
public NoticeListAdapter(Context context, int layout, ArrayList foodsList) {
this.context = context;
this.layout = layout;
this.foodsList = foodsList;
}
@Override
public int getCount() {
return foodsList.size();
}
@Override
public Object getItem(int position) {
return foodsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder{
ImageView imageView;
TextView txtName, txtPrice,notice_id;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
View row = view;
NoticeListAdapter.ViewHolder holder = new NoticeListAdapter.ViewHolder();
if(row == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layout, null);
holder.notice_id = (TextView) row.findViewById(R.id.notice_id);
holder.txtName = (TextView) row.findViewById(R.id.txtName);
holder.txtPrice = (TextView) row.findViewById(R.id.txtPrice);
holder.imageView = (ImageView) row.findViewById(R.id.imgFood);
row.setTag(holder);
}
else {
holder = (NoticeListAdapter.ViewHolder) row.getTag();
}
Notice food = foodsList.get(position);
holder.notice_id.setText(food.getNoticeId());
holder.txtName.setText(food.getName());
holder.txtPrice.setText(food.getPrice());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(food.getImageUrl(), options);
holder.imageView.setImageBitmap(bitmap);
return row;
}
}
and full image activity code is
public class FullImageActivity extends Activity {
ArrayList list;
private ArrayList foodsList;
public Object getItem(int position) {
return foodsList.get(position);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
list = new ArrayList<>();
NoticeListAdapter imageAdapter = new NoticeListAdapter(this, R.layout.food_items, list);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource((Integer) imageAdapter.getItem(position));
}
}
and i used on set item click listener on the main page to show the image on full screen, my set item click listener code is on main page
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
but i got error that is pasted above plz help mee. Thank you.
