2017-04-25 60 views
0

我的问题是当我运行代码的应用程序跳出应用程序。我正在使用SQLite数据库使用Recycler视图我有两个视图控件1是Textview,另一个是图像view.An应用上的TextView运行,但是当我使用图片视图那么Android Studio中有错误:“显示java.lang.NullPointerException:尝试获取空数组的长度”显示错误,以获得空数组错误的图像视图

Thanx提前。 这里是我的Recycler_List_Item_Adapter2.java

@Override 
public void onBindViewHolder(MyViewHolder_item holder, int position) { 
    Recycler_List_Item_Pojo2 recycler_title_pojo=arrayList.get(position); 
    holder.outImage=recycler_title_pojo.getImg(); 
    ByteArrayInputStream imageStream = new ByteArrayInputStream(holder.outImage); 
    Bitmap theImage = BitmapFactory.decodeStream(imageStream); 
    holder.imageView.setImageBitmap(theImage); 
    holder.textView.setText(recycler_title_pojo.getBr_title()); 
} 


@Override 
public int getItemCount() { 
    return arrayList.size(); 
} 

public class MyViewHolder_item extends RecyclerView.ViewHolder { 
    TextView textView; 
    CircleImageView imageView; 
    byte[] outImage; 

这里是我的Recycler_List_Item_Pojo2.java

public class Recycler_List_Item_Pojo2 { 
byte[] img=null; 
String br_title,bt_material,br_procedure,br_notice; 

public Recycler_List_Item_Pojo2(byte[] img, String br_title) { 
    this.img = img; 
    this.br_title = br_title; 
} 

public byte[] getImg() { 
    return img; 
} 

public void setImg(byte[] img) { 
    this.img = img; 
} 

public String getBr_title() { 
    return br_title; 
} 

public void setBr_title(String br_title) { 
    this.br_title = br_title; 
} 

这里是我的SQLite数据库代码

Recycler_List_Item_Pojo2 product = null; 
    List<Recycler_List_Item_Pojo2> productList = new ArrayList<Recycler_List_Item_Pojo2>(); 
    openDatabase(); 
    Cursor cursor = mDatabase.rawQuery(" select * from a", null, null); 
    cursor.moveToFirst(); 
    while (!cursor.isAfterLast()) { 

     product = new Recycler_List_Item_Pojo2(cursor.getBlob(1),cursor.getString(2)); 
     productList.add(product); 
     cursor.moveToNext(); 
    } 
    cursor.close(); 
    closeDatabase(); 
    return productList; 

这里是我的错误

FATAL EXCEPTION: main 
                  Process: com.pp.receipe, PID: 21550 
                  java.lang.NullPointerException: Attempt to get length of null array 
                   at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:60) 
                   at com.pp.receipe.adapter.Recycler_List_Item_Adapter2.onBindViewHolder(Recycler_List_Item_Adapter2.java:50) 
                   at com.pp.receipe.adapter.Recycler_List_Item_Adapter2.onBindViewHolder(Recycler_List_Item_Adapter2.java:30) 
+0

可能重复[什么是NullPointerException,以及如何解决它?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-doi-i-fix -it) –

回答

1

@Prashant请检查您的SQLITE数据库。如果插入了任何NULL值或检查任何字段是否为空。请从数据库中删除您的空字段。

+0

谢谢......我删除了我的空字段。现在代码正在工作.... –