Reputation: 31
I'm trying to develop Android apps via Java,Eclipse.
I'm trying to use this example.
My activity:
package grid.View;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getVieww(int position, View convertView, ViewGroup parent) {
ImageView imageVieww;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageVieww = new ImageView(mContext);
imageVieww.setLayoutParams(new GridView.LayoutParams(85, 85));
imageVieww.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageVieww.setPadding(8, 8, 8, 8);
} else {
imageVieww = (ImageView) convertView;
}
imageVieww.setImageResource(mThumbIds[position]);
return imageVieww;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return null;
}
}
I have this error for all those "samples":
sample_2 cannot be resolved or is not a field
What I'm supposed to do? :S
Thanks!
Upvotes: 0
Views: 243
Reputation: 5183
This means that there is not such resource in your drawables folder. Either you have to add it there or don't use it anymore.
In case you actually have it, then try to clean & build again your project.
Hope this helps!
Upvotes: 1
Reputation: 5980
R.drawable.sample_2
refers to a image called "sample_2" in your drawable folder.
If it shows this error, either the image isn't available in your drawable folder(s) (missing, different name?), or you haven't imported the R.java
file.
By the looks of it, you haven't downloaded the images described in the example and put them in your drawables
folder.
Upvotes: 1
Reputation: 22822
You're supposed to have images in your drawable folder, named sample_0.png
to sample_7.png
The Android SDK will detect them and generate variables R.drawable.sample_X
(X - 0 to 7) for you to use.
Upvotes: 2