This Question have no Text answers yet!

arrays.sort return null in java

Tags: java android
Question!

I am using camera api2 in android studio I implemented the recyclerview adapter, here is my adapter is it advisable to add notifychangedAdapter?which part should I add them here?:

public static class AsyncDrawable extends BitmapDrawable {
    final WeakReference<BitmapWorkerTask> taskReference;

    public AsyncDrawable(Resources resources,
                         Bitmap bitmap,
                         BitmapWorkerTask bitmapWorkerTask) {
        super(resources, bitmap);
        taskReference = new WeakReference(bitmapWorkerTask);
    }

    public BitmapWorkerTask getBitmapWorkerTask() {
        return taskReference.get();
    }
}

public ImageAdapter(File[] folderFiles, RecyclerViewClickPositionInterface positionInterface) {
    mPositionInterface = positionInterface;
    mImageFiles= folderFiles;
}


@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.gallery_images_relative_layout, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    File imageFile = mImageFiles[position];
    Bitmap bitmap = CamaraIntentActivity.getBitmapFromMemoryCache(imageFile.getName());
    if(bitmap != null) {
        holder.getImageView().setImageBitmap(bitmap);
    }
    else if(checkBitmapWorkerTask(imageFile, holder.getImageView())) {
        BitmapWorkerTask bitmapWorkerTask = new BitmapWorkerTask(holder.getImageView());
        AsyncDrawable asyncDrawable = new AsyncDrawable(holder.getImageView().getResources(),
                placeHolderBitmap,
                bitmapWorkerTask);
        holder.getImageView().setImageDrawable(asyncDrawable);
        bitmapWorkerTask.execute(imageFile);
    }
}

@Override
public int getItemCount() {
    return mImageFiles != null ? mImageFiles.length : 0;

}

public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    private ImageView imageView;

    public ViewHolder(View view) {
        super(view);

        view.setOnClickListener(this);
        imageView = (ImageView) view.findViewById(R.id.imageGalleryView);
    }

    public ImageView getImageView() {
        return imageView;
    }

    @Override
    public void onClick(View v) {
        mPositionInterface.getRecyclerViewAdapterPosition(this.getPosition());
    }
}

public static boolean checkBitmapWorkerTask(File imageFile, ImageView imageView) {
    BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
    if(bitmapWorkerTask != null) {
        final File workerFile = bitmapWorkerTask.getImageFile();
        if(workerFile != null) {
            if(workerFile != imageFile) {
                bitmapWorkerTask.cancel(true);
            } else {
                // bitmap worker task file is the same as the imageview is expecting
                // so do nothing
                return false;
            }
        }
    }
    return true;
}

public static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    if(drawable instanceof AsyncDrawable) {
        AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
        return asyncDrawable.getBitmapWorkerTask();
    }
    return null;
}

in my activity I implemented like this and calls the notifydatachanged afterwards:

 RecyclerView.Adapter imageAdapter = ImageAdapter(sortFilesToLatest(mGalleryFolder), this);
        mRecyclerView.setAdapter(imageAdapter);
        imageAdapter.notifyDataSetChanged();

this is my sortFilesToLatest which sorts the image captured once it has been using the camera

 private File[] sortFilesToLatest(File fileImagesDir) {
        File[] files = fileImagesDir.listFiles();
        Arrays.sort(files, new Comparator<File>() {
                @Override
                public int compare(File lhs, File rhs) {
                    return Long.valueOf(rhs.lastModified()).compareTo(lhs.lastModified());
                }
            });

        return files;
    }

when I run this code the sortFilesToLatest the arrays returns this

java.lang.NullPointerException: Attempt to get length of null array

How can I be able to resolve this?any help or advice guys?




Android API for detecting new media from inbuilt camera & mic

How do I find the DNS servers in Android from a Java program?

how to call a soap web service on android

Any good ORM tools for Android development? [closed]

JRE on Android


android internals and memory/processor constraints?

Android HTTP Connection

Timed popup in Android

Eclipse eye for a Visual Studio guy

What happened to android.provider.Telephony?

Android TextView Timer

Line-breaking widget layout for Android

File permissions in Android

Java - Convert String to valid URI object

Android InputStream Internet Disconnect

Video about arrays.sort return null in java