Eclipse does not recognize any methods of BitmapFactory.Options variable

324 Views Asked by At

So I'm trying to create a swippable menu by using a viewpager with different sections of menu as each view. Each of these sections have different dimensions as well as needing to be scaled appropriately, hence my use of BitmapFactory.

The strange thing is, I can create a BitmapFactory.Options variable

But when I try to do anything with that variable, specifically set inJustDecodeBounds to true, Eclipse assumes I'm creating another variable or asks me if I want to create a method within options instead of recognizing it to begin with. In addition, if I erase inJustDecodeBounds and use auto complete, it gives an empty box of No Default Proposals, so it doesn't seem to recognize that options is a BitmapFactory.Options variable at all.

Both android.graphics.Bitmap and android.graphics.BitmapFactory are imported

Here is the relevant code:

package com.Santacruz.sleepingmoonapp;

import com.Santacruz.sleepingmoonapp.R;
import android.support.v4.view.ViewPager;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;




public class ImageAdapter extends PagerAdapter {
Context context;
private int[] GalImages = new int[] {
R.drawable.sleepingmoonmenulogo,
R.drawable.menucoffee,
R.drawable.menusmoothies,
R.drawable.menumilkshakes,
R.drawable.menuappetizers,
R.drawable.menugoodmorning1,
R.drawable.menugoodmorning2,
R.drawable.menupaninis_1,
R.drawable.menupaninis_2,
R.drawable.menuwraps,
R.drawable.menuextras,
R.drawable.menusalad_1,
R.drawable.menubowls,
R.drawable.menufruits
};


BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

ImageAdapter(Context context){
this.context=context;
}



@Override
public int getCount() {
return GalImages.length;
}



@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {

Bitmap image = BitmapFactory.decodeResource(
    context.getResources(), 
    GalImages[position]);

imageView.setScaleType(ImageView.ScaleType.FIT_START);
imageView.setImageBitmap(image);
((ViewPager) container).addView(imageView, 0);
return imageView;
}



@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}

}

EDIT: The problem is easily repeatable in multiple projects, which makes me think its a problem with my copy of Eclipse, not the code itself. I've already redownloaded and updated my packages and restarted Eclipse, but that hasn't helped. Are there any specific packages I might be missing? Maybe some default project settings that are getting in the way? I'm kind of desperate and will try anything you can think of.

1

There are 1 best solutions below

1
On BEST ANSWER

Move your:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

inside your instantiateItem class:

@Override
public Object instantiateItem(ViewGroup container, int position) {

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;

Bitmap image = BitmapFactory.decodeResource(
    context.getResources(), 
    GalImages[position]);

imageView.setScaleType(ImageView.ScaleType.FIT_START);
imageView.setImageBitmap(image);
((ViewPager) container).addView(imageView, 0);
return imageView;
}

it should not give you that annoying error. :)