Android base64解码崩溃应用程序

时间:2013-09-08 10:37:13

标签: android crash base64 decoding

我使用的是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);

有没有人看到它会崩溃的原因?

0 个答案:

没有答案