2016-03-24 20 views
0

ImageViewで画像を表示しようとしました。型はSQLiteデータベースにBLOBですが、アンドロイドスタジオでエラーが見つかりました。エラー:(43,220)エラー:互換性のない型:byte []をintに変換できません。エラー:互換性のない型:byte []をintに変換できません。 Image

はこれがあなたのに対し、タイプintのものでなければならない私のデータベースクラス内のコード

public class Database { 
public static final String DATABASE_NAME = "dic.sqlite"; 
public static final String TABLE_FIRST = "en1_word"; 
public static final String TABLE_SECOND = "en2_word"; 
public static final String COLUMN_ID = "id"; 
public static final String COLUMN_WORD = "word"; 
public static final String COLUMN_MEAN = "mean"; 
public static final String COLUMN_CATEGORY = "category"; 
public static final String COLUMN_PIC = "pic"; 
public static final String COLUMN_FAVORITE = "favorite";} 

とdatabasedaoクラス

public class DictionaryDaoImpl implements DictionaryDao { 
private SQLiteDatabase sqLiteDatabase; 
public DictionaryDaoImpl(SQLiteDatabase sqLiteDatabase){ 
    this.sqLiteDatabase = sqLiteDatabase; 

} 
@Override 
public Word getWordById(int id) { 
    Cursor cursor = sqLiteDatabase.query(Util.getCurrentTableName(),new String[]{Database.COLUMN_ID, Database.COLUMN_WORD, Database.COLUMN_MEAN, Database.COLUMN_FAVORITE,Database.COLUMN_CATEGORY ,Database.COLUMN_PIC}, 
      Database.COLUMN_ID + " = ?",new String[]{String.valueOf(id)},null,null,null,null); 

    int idColumnIndex = cursor.getColumnIndex(Database.COLUMN_ID); 
    int wordColumnIndex = cursor.getColumnIndex(Database.COLUMN_WORD); 
    int meanColumnIndex = cursor.getColumnIndex(Database.COLUMN_MEAN); 
    int favoriteColumnIndex = cursor.getColumnIndex(Database.COLUMN_FAVORITE); 
    int categoryColumnIndex = cursor.getColumnIndex(Database.COLUMN_CATEGORY); 
    byte[] picColumnIndex = cursor.getBlob(cursor.getColumnIndex(Database.COLUMN_PIC)); 

    Word word = null; 
    if (cursor.moveToNext()){ 
     word = new Word(cursor.getInt(idColumnIndex),cursor.getString(wordColumnIndex), cursor.getString(meanColumnIndex), cursor.getInt(favoriteColumnIndex)==1,cursor.getString(categoryColumnIndex), cursor.getBlob(picColumnIndex)); 
    } 
    return word; 
} 

と単語クラスこのcursor.getBlob(picColumnIndex)picColumnIndex

public class Word { 
private int id; 
private String word; 
private String mean; 
boolean isFavorite; 
private byte[] pic; 
private String category; 

public Word(int id, String word, String mean, boolean isFavorite, byte[] pic, String category) { 
    this.id = id; 
    this.word = word; 
    this.mean = mean; 
    this.isFavorite = isFavorite; 
    this.pic = pic; 
    this.category = category; 
} 
public int getId() { 
    return id; 
} 
public void setId(int id) { 
    this.id = id; 
} 
public String getWord() { 
    return word; 
} 
public void setWord(String word) { 
    this.word = word; 
} 
public String getMean() { 
    return mean; 
} 
public void setMean(String mean) { 
    this.mean = mean; 
} 
public boolean isFavorite() { 
    return isFavorite; 
} 
public void setIsFavorite(boolean isFavorite) { 
    this.isFavorite = isFavorite; 
} 
public String getCategory() { 
    return category; 
} 
public void setCategory(String category) { 
    this.category = category; 
} 
public byte[] getPic() { 
    return pic; 
} 
public void setPic(byte[] pic) { 
    this.pic = pic; 
} 
+0

をしたいと考えていますか? –

答えて

0

ですと定義しています

代わりのbyte[] picColumnIndex = cursor.getBlob(cursor.getColumnIndex(Database.COLUMN_PIC));私はあなたが、例外がスローされないint picColumnIndex = cursor.getColumnIndex(Database.COLUMN_PIC);

+0

私は約 – leonziyo

+0

OKと言っていました。私は混乱します。できます。あなたより。 – user3268375