0

我正在使用类类别

package Entities;

import java.util.ArrayList;

import com.j256.ormlite.field.DatabaseField;

import utils.ImageHelper;

import android.graphics.Bitmap;
import android.util.Base64;

public class Category {


    @DatabaseField(generatedId = true)
    int id ;
    @DatabaseField
    String name ;

    String image;

    Bitmap bitmapImage;




    public Bitmap getBitmapImage() {
        return bitmapImage;
    }

    public void setBitmapImage(Bitmap bitmapImage) {
        this.bitmapImage = bitmapImage;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    ArrayList<Item> items;



    public Category (int id,String CN , String CP)
    {
        this.id=id;
        name=CN;
        image=CP;

    }

    public Category (String CN , String CP)
    {

        name=CN;
        image=CP;

    }

    public Category ()
    {


    }

    public ArrayList<Item> getItems() {
        return items;
    }
    public void setItems(ArrayList<Item> items) {
        this.items = items;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public void  convertStringImageToBitmapImage()
    {
        if(image!=null)
        {
        byte[] imgData = Base64.decode(image, Base64.DEFAULT);
        bitmapImage = ImageHelper.CreateBitmapFromByteArray(imgData);
        image="";
        }


    }


}

我从 webservice 收到我的照片作为字符串 base64 并使用 convertStringImageToBitmapImage 将其更改为位图,我想将此类用于 ormlite ,但我收到了这个问题

Exception in thread "main" java.lang.NoClassDefFoundError: Landroid/graphics/Bitmap;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2387)
    at java.lang.Class.getDeclaredFields(Class.java:1796)
    at com.j256.ormlite.android.apptools.OrmLiteConfigUtil.writeConfigForTable(OrmLiteConfigUtil.java:220)
    at com.j256.ormlite.android.apptools.OrmLiteConfigUtil.writeConfigFile(OrmLiteConfigUtil.java:144)
    at com.j256.ormlite.android.apptools.OrmLiteConfigUtil.writeConfigFile(OrmLiteConfigUtil.java:133)
    at com.j256.ormlite.android.apptools.OrmLiteConfigUtil.writeConfigFile(OrmLiteConfigUtil.java:124)
    at database.DatabaseConfigUtil.main(DatabaseConfigUtil.java:21)
Caused by: java.lang.ClassNotFoundException: android.graphics.Bitmap
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 8 more

我该如何解决?

4

1 回答 1

0

您不能使用Bitmap,但是,您可以将图像转换为Base64并保存为String.

在您可以恢复此信息之后

InfoDao = getHelper().getInfoDao();
data = InfoDao.queryForAll();
byte[] decodedString = Base64.decode(data.get(position).getImage(),Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

现在您可以使用位图

于 2015-11-21T02:33:54.097 回答