java - NullPointerException at createBitmap(). Using an Adapter to inflate a Bitmap into a ListView's rows -
i'm getting nullpointerexception @ createbitmap. on research, i've come across people suggesting it's because of low memory. i'd find out if there's in code changed make work. reference, i'll post xml file of row give idea of how should fit in.
here's function gives error (i'm trying make image circular, function):
public bitmap getcroppedbitmap(bitmap bitmap, view view) { bitmap output; try { view.builddrawingcache(true); output = bitmap.createbitmap(bitmap.getwidth(), bitmap.getheight(), //error here bitmap.config.argb_8888); }finally { view.setdrawingcacheenabled(false); } final rect rect = new rect(0, 0, bitmap.getwidth(), bitmap.getheight()); canvas canvas = new canvas(output); final paint paint = new paint(); paint.setantialias(true); int halfwidth = bitmap.getwidth()/2; int halfheight = bitmap.getheight()/2; canvas.drawcircle(halfwidth, halfheight, math.max(halfwidth, halfheight), paint); paint.setxfermode(new porterduffxfermode(porterduff.mode.src_in)); canvas.drawbitmap(bitmap, rect, rect, paint); return output; }
here's xml code row:
<android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cardview="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:clickable="true" android:orientation="horizontal" android:statelistanimator="@anim/anim" cardview:cardbackgroundcolor="@color/material_black_900" cardview:cardelevation="5dp" cardview:cardcornerradius="10dp"> <relativelayout android:id="@+id/item_linear_layout" android:layout_width="match_parent" android:layout_height="wrap_content"> <imageview android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:gravity="center_vertical" android:layout_alignparentright="true" android:scaletype="center"/> <textview android:id="@+id/name_view" android:paddingtop="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/whitesmoke" android:layout_centerhorizontal="true" android:textsize="15dp" android:singleline="false" android:text="test1" android:paddingbottom="10dp" android:textstyle="bold"/> <textview android:id="@+id/number_view" android:layout_centerhorizontal="true" android:layout_width="wrap_content" android:paddingbottom="5dp" android:singleline="false" android:layout_height="wrap_content" android:layout_below="@+id/name_view" android:text="test2" android:textcolor="@color/whitesmoke" android:textsize="15dp" android:textstyle="bold"/> </relativelayout>
here's logcat:
12-06 07:51:51.199: e/androidruntime(21433): fatal exception: main 12-06 07:51:51.199: e/androidruntime(21433): java.lang.nullpointerexception 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.abslistview.obtainview(abslistview.java:2040) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.listview.makeandaddview(listview.java:1772) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.listview.filldown(listview.java:672) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.listview.fillfromtop(listview.java:732) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.listview.layoutchildren(listview.java:1625) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.abslistview.onlayout(abslistview.java:1870) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.setchildframe(linearlayout.java:1652) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.layoutvertical(linearlayout.java:1510) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.onlayout(linearlayout.java:1415) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.framelayout.onlayout(framelayout.java:443) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.support.v4.view.viewpager.onlayout(viewpager.java:1594) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.setchildframe(linearlayout.java:1652) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.layoutvertical(linearlayout.java:1510) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.onlayout(linearlayout.java:1415) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.framelayout.onlayout(framelayout.java:443) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.setchildframe(linearlayout.java:1652) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.layoutvertical(linearlayout.java:1510) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.onlayout(linearlayout.java:1415) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.framelayout.onlayout(framelayout.java:443) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.setchildframe(linearlayout.java:1652) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.layoutvertical(linearlayout.java:1510) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.linearlayout.onlayout(linearlayout.java:1415) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.widget.framelayout.onlayout(framelayout.java:443) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.view.layout(view.java:11418) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewgroup.layout(viewgroup.java:4328) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1489) 12-06 07:51:51.199: e/androidruntime(21433): @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2442) 12-06 07:51:51.199: e/androidruntime(21433): @ android.os.handler.dispatchmessage(handler.java:99) 12-06 07:51:51.199: e/androidruntime(21433): @ android.os.looper.loop(looper.java:137) 12-06 07:51:51.199: e/androidruntime(21433): @ android.app.activitythread.main(activitythread.java:4441) 12-06 07:51:51.199: e/androidruntime(21433): @ java.lang.reflect.method.invokenative(native method) 12-06 07:51:51.199: e/androidruntime(21433): @ java.lang.reflect.method.invoke(method.java:511) 12-06 07:51:51.199: e/androidruntime(21433): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784)
Comments
Post a Comment