我正在使用 base64 解码,由于某种原因,它不断使应用程序崩溃。我在其他地方使用这个代码,它似乎在那里完美地工作。也许我在使用它的班级有问题?
这是我的课:
private class MyListAdapter extends ArrayAdapter<Users>
{
public MyListAdapter()
{
super(SearchActivity.this, R.layout.list_item, myUsers);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//Make sure we have a view to work with (may have been given null)
View itemView = convertView;
if(itemView == null)
{
itemView = getLayoutInflater().inflate(R.layout.list_item, parent, false);
}
//Find the user to work with
Users currentUser = myUsers.get(position);
//Fill the view
TextView text;
text = (TextView) itemView.findViewById(R.id.item_name);
text.setText(currentUser.getName());
text = (TextView) itemView.findViewById(R.id.item_location);
text.setText(currentUser.getLocation());
if(!currentUser.getPicture().equals("noPicture"))
{
String temp = currentUser.getPicture();
ImageView imageView = (ImageView) findViewById(R.id.item_picture);
byte[] decodedString = Base64.decode(temp, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);
}
return itemView;
}
}
它在以下行崩溃:
byte[] decodedString = Base64.decode(temp, Base64.DEFAULT);
有没有人看到它会崩溃的原因?