如何解决我的应用程序中的图像适配器错误?
您好,我正在尝试将数组列表值放入我的图像适配器类中,但现在出现错误。我正在尝试解决,但我不知道。
错误行:
Bitmap bitmap = BitmapFactory.decodeFile(path_List.get(position));
错误:Bundle 类型中的方法 get(String) 不适用于参数 (int)
我的代码: parxmlActivity.java 类,
public class ParxmlActivity extends Activity {
private String array_spinner[];
private Cursor cursor;
private int columnIndex;
ParsedExampleDataSet parsedExampleDataSet= null;
ArrayList<String> hltag_List=new ArrayList<String>();
ArrayList<Subchild>sltag_List=new ArrayList<Subchild>();
ArrayList<String> name_List =new ArrayList<String>();
ArrayList<String> path_List =new ArrayList<String>();
ArrayList<String> mmimage_List = new ArrayList<String>();
ArrayList<String> mname_List = new ArrayList<String>();
ArrayList<String> mmimage = new ArrayList<String>();
ArrayList<String> mvideo_List = new ArrayList<String>();
ArrayList<schild> model_List =new ArrayList<schild>();
ArrayList<String> mspec_List = new ArrayList<String>();
Spinner spinner_hltag,spinner_sltag, spinner_path;
ArrayAdapter<String> adapter_hltag;
ArrayAdapter<String> adapter_sltag;
ArrayAdapter<String> adapter_path;
int hltagPos=0;
int sltagPos=0;
Object sdcard;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
spinner_hltag= (Spinner) findViewById(R.id.spinner1);
spinner_sltag = (Spinner) findViewById(R.id.spinner2);
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Intent intent = new Intent(ParxmlActivity.this, tabview.class);
//intent.putStringArrayListExtra("numbers", mspec_List);
intent.putExtra("name",model_List.get(position).name);
//intent.putExtra("name",model_List.get(position).name);
startActivity(intent);
}
});
sdcardImages.setAdapter(new ImageAdapter(this));
String[] proj = {MediaStore.Images.Thumbnails._ID};
cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
try {
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader */
ExampleHandler myExampleHandler = new ExampleHandler();
xr.setContentHandler(myExampleHandler);
/* Parse the xml-data from our file. */
xr.parse(new InputSource(getAssets().open("mafile.xml")));
/* Parsing has finished. */
parsedExampleDataSet =myExampleHandler. myParsedExampleDataSet;
for (int i = 0; i < parsedExampleDataSet.gethltag().size(); i++) {
Log.v("gethltag SIZE ", ""+parsedExampleDataSet.gethltag().size());
hltag_List.add(parsedExampleDataSet.getHLTag().get(i));
}
sltag_List = parsedExampleDataSet.getSLTag(hltag_List.get(hltagPos));
for(int i = 0; i < sltag_List.size(); i++) {
name_List.add(sltag_List.get(i).name);
path_List.add(sltag_List.get(i).path);
}
model_List.clear();
model_List = sltag_List.get(sltagPos).model;
for(int j = 0; j<model_List.size(); j++){
mmimage_List.addAll(model_List.get(j).imageList);
mname_List.add(model_List.get(j).name);
mvideo_List.addAll(model_List.get(j).videoList);
mmimage.add(model_List.get(j).mimage);
mspec_List.add(model_List.get(j).spec);
}
spinner_hltag.setAdapter(new MyAdapter(ParxmlActivity.this, R.layout.row, hltag_List));
spinner_sltag.setAdapter(new MyAdapter1(ParxmlActivity.this, R.layout.row1,name_List));
} catch (Exception e) {
}
}
}
这是我的 ImageAdapter.class 我在下面的代码中遇到错误:
public class ImageAdapter extends BaseAdapter {
Bundle path_List;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return path_List.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
//Bitmap bitmap = BitmapFactory.decodeFile(path_List);
Bitmap bitmap = BitmapFactory.decodeFile(path_List.get(position));
imageView.setImageBitmap(bitmap);
return imageView;
}
}
hi I am trying to get my arraylist value into my image adapter class but i got error now. i am trying to solve but i don't know.
error line:
Bitmap bitmap = BitmapFactory.decodeFile(path_List.get(position));
error : The method get(String) in the type Bundle is not applicable for the arguments (int)
my code:
parxmlActivity.java class
public class ParxmlActivity extends Activity {
private String array_spinner[];
private Cursor cursor;
private int columnIndex;
ParsedExampleDataSet parsedExampleDataSet= null;
ArrayList<String> hltag_List=new ArrayList<String>();
ArrayList<Subchild>sltag_List=new ArrayList<Subchild>();
ArrayList<String> name_List =new ArrayList<String>();
ArrayList<String> path_List =new ArrayList<String>();
ArrayList<String> mmimage_List = new ArrayList<String>();
ArrayList<String> mname_List = new ArrayList<String>();
ArrayList<String> mmimage = new ArrayList<String>();
ArrayList<String> mvideo_List = new ArrayList<String>();
ArrayList<schild> model_List =new ArrayList<schild>();
ArrayList<String> mspec_List = new ArrayList<String>();
Spinner spinner_hltag,spinner_sltag, spinner_path;
ArrayAdapter<String> adapter_hltag;
ArrayAdapter<String> adapter_sltag;
ArrayAdapter<String> adapter_path;
int hltagPos=0;
int sltagPos=0;
Object sdcard;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
spinner_hltag= (Spinner) findViewById(R.id.spinner1);
spinner_sltag = (Spinner) findViewById(R.id.spinner2);
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Intent intent = new Intent(ParxmlActivity.this, tabview.class);
//intent.putStringArrayListExtra("numbers", mspec_List);
intent.putExtra("name",model_List.get(position).name);
//intent.putExtra("name",model_List.get(position).name);
startActivity(intent);
}
});
sdcardImages.setAdapter(new ImageAdapter(this));
String[] proj = {MediaStore.Images.Thumbnails._ID};
cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
try {
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader */
ExampleHandler myExampleHandler = new ExampleHandler();
xr.setContentHandler(myExampleHandler);
/* Parse the xml-data from our file. */
xr.parse(new InputSource(getAssets().open("mafile.xml")));
/* Parsing has finished. */
parsedExampleDataSet =myExampleHandler. myParsedExampleDataSet;
for (int i = 0; i < parsedExampleDataSet.gethltag().size(); i++) {
Log.v("gethltag SIZE ", ""+parsedExampleDataSet.gethltag().size());
hltag_List.add(parsedExampleDataSet.getHLTag().get(i));
}
sltag_List = parsedExampleDataSet.getSLTag(hltag_List.get(hltagPos));
for(int i = 0; i < sltag_List.size(); i++) {
name_List.add(sltag_List.get(i).name);
path_List.add(sltag_List.get(i).path);
}
model_List.clear();
model_List = sltag_List.get(sltagPos).model;
for(int j = 0; j<model_List.size(); j++){
mmimage_List.addAll(model_List.get(j).imageList);
mname_List.add(model_List.get(j).name);
mvideo_List.addAll(model_List.get(j).videoList);
mmimage.add(model_List.get(j).mimage);
mspec_List.add(model_List.get(j).spec);
}
spinner_hltag.setAdapter(new MyAdapter(ParxmlActivity.this, R.layout.row, hltag_List));
spinner_sltag.setAdapter(new MyAdapter1(ParxmlActivity.this, R.layout.row1,name_List));
} catch (Exception e) {
}
}
}
this is my ImageAdapter.class i got error in below code:
public class ImageAdapter extends BaseAdapter {
Bundle path_List;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return path_List.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
//Bitmap bitmap = BitmapFactory.decodeFile(path_List);
Bitmap bitmap = BitmapFactory.decodeFile(path_List.get(position));
imageView.setImageBitmap(bitmap);
return imageView;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在尝试从
Bundle path_List
而不是ArrayList获取字符串值 path_List
这就是为什么您收到此错误。从
public class ImageAdapter extends BaseAdapter
中删除此行Bundle path_List;
并引用
ArrayList<字符串> path_List
不要Bundle path_List
并尝试再次运行..
更新: 另外我假设您的 ImageAdapter 类位于 ParxmlActivity 中..
代码: 另外,如果可能的话,请在您的 ImageAdapter 类中进行更改..类似,
并且在您的活动中这一行应该是,
You are trying to get string values from
Bundle path_List
instead ofArrayList<String> path_List
that's why you got this error..Remove this line
Bundle path_List;
frompublic class ImageAdapter extends BaseAdapter
Make a reference to
ArrayList<String> path_List
not toBundle path_List
And try to run again..
UPDATE: Also I am assuming your ImageAdapter class in ParxmlActivity..
Code: Also if possible make changes in your ImageAdapter class.. something like,
And in your activity this line should be,
public Object get (String key)
不会将 int 作为参数。因此将 path_List.get(position) 替换为 path_List.get(String.valueOf(position)) 。
我想补充的一件事是bundle在这里为空,所以首先在其中插入路径。
可能是您忘记将其从活动传递到适配器。
更新 :
位图 bitmap = BitmapFactory.decodeFile((String)path_List.getString.valueOf(position));
public Object get (String key)
will not take int as argument .so
replace path_List.get(position
) bypath_List.get(String.valueOf(position))
.one more thing i want to add is bundle is null here , so first insert path inside it .
might be you forgot to pass it from activity to adapter .
Update :
Bitmap bitmap = BitmapFactory.decodeFile((String)path_List.getString.valueOf(position));