小编Pav*_*agi的帖子

由java.lang.NullPointerException引起:尝试在空对象引用上调用虚方法'int android.graphics.Bitmap.getWidth()'

我有BitmapScalingHelper.java:

public class BitmapScalingHelper
{
    public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight)
    {
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(res, resId, options);
        options.inJustDecodeBounds = false;

        options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth,
                dstHeight);

        Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options);

        return unscaledBitmap;
    }

    public static Bitmap decodeFile(String filePath, int dstWidth, int dstHeight)
    {
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, options);

        options.inJustDecodeBounds = false;
        options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth,
                dstHeight);

        Bitmap unscaledBitmap = BitmapFactory.decodeFile(filePath, options); …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception android-activity android-bitmap

17
推荐指数
2
解决办法
2万
查看次数

java.lang.IllegalStateException:已在池中

在回收物品时,我在回收者视图上的产品上遇到这种奇怪的崩溃,而且我也无法重现此崩溃。

  Fatal Exception: java.lang.IllegalStateException: Already in the pool!
   at androidx.core.util.Pools$SimplePool.release(Pools.java:117)
   at androidx.recyclerview.widget.AdapterHelper.recycleUpdateOp(AdapterHelper.java:743)
   at androidx.recyclerview.widget.AdapterHelper.recycleUpdateOpsAndClearList(AdapterHelper.java:750)
   at androidx.recyclerview.widget.AdapterHelper.consumePostponedUpdates(AdapterHelper.java:123)
   at androidx.recyclerview.widget.AdapterHelper.consumeUpdatesInOnePass(AdapterHelper.java:557)
   at androidx.recyclerview.widget.RecyclerView.processAdapterUpdatesAndSetAnimationFlags(RecyclerView.java:3585)
   at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3829)
   at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
   at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1877)
   at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5044)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)
   at android.view.Choreographer.doCallbacks(Choreographer.java:893)
   at android.view.Choreographer.doFrame(Choreographer.java:809)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)
   at android.os.Handler.handleCallback(Handler.java:891)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:207)
   at android.app.ActivityThread.main(ActivityThread.java:7539)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Run Code Online (Sandbox Code Playgroud)

android recycler-adapter android-recyclerview

12
推荐指数
1
解决办法
647
查看次数