Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to invoke interface method on a null object reference #22

Closed
ziadkiwan opened this issue Dec 3, 2016 · 10 comments
Closed

Attempt to invoke interface method on a null object reference #22

ziadkiwan opened this issue Dec 3, 2016 · 10 comments

Comments

@ziadkiwan
Copy link

Hello LawLoretienne,
Thank you for this great image gallery ! while i was implement the gallery i face a null object reference exception
My Code:

Intent intent = new Intent(MainActivity.this, ImageGalleryActivity.class);
         String path = Environment.getExternalStorageDirectory().toString() + "/req_images/photos";
         Log.d("Files", "Path: " + path);
         File directory = new File(path);
         File[] files = directory.listFiles();
         Log.d("Files", "Size: "+ files.length);
         String[] images = new String[files.length];
         for (int i = 0; i < files.length; i++)
         {
             images[i] = path+"/"+files[i].getName();
             Log.d("Files", "FileName:" + path+"/"+files[i].getName());
         }
         Log.d("Files",images.length+"~~");
         Bundle bundle = new Bundle();
         bundle.putStringArrayList(ImageGalleryActivity.KEY_IMAGES, new ArrayList<>(Arrays.asList(images)));
         bundle.putString(ImageGalleryActivity.KEY_TITLE, "Gallery");
         intent.putExtras(bundle);

         startActivity(intent);

The Error i'm getting:

java.lang.NullPointerException: Attempt to invoke interface method 'void com.etiennelawlor.imagegallery.library.adapters.ImageGalleryAdapter$ImageThumbnailLoader.loadImageThumbnail(android.widget.ImageView, java.lang.String, int)' on a null object reference
at com.etiennelawlor.imagegallery.library.activities.ImageGalleryActivity.loadImageThumbnail(ImageGalleryActivity.java:101)
at com.etiennelawlor.imagegallery.library.adapters.ImageGalleryAdapter.onBindViewHolder(ImageGalleryAdapter.java:58)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5471)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5504)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4741)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:528)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
at android.view.View.layout(View.java:16653)
at android.view.ViewGroup.layout(ViewGroup.java:5438)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16653)
at android.view.ViewGroup.layout(ViewGroup.java:5438)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16653)
at android.view.ViewGroup.layout(ViewGroup.java:5438)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16653)
at android.view.ViewGroup.layout(ViewGroup.java:5438)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16653)
at android.view.ViewGroup.layout(ViewGroup.java:5438)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16653)
at android.view.ViewGroup.layout(ViewGroup.java:5438)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
at android.view.View.layout(View.java:16653)
at android.view.ViewGroup.layout(ViewGroup.java:5438)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2198)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1958)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1134)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6050)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
at android.view.Choreographer.doCallbacks(Choreographer.java:672)
at android.view.Choreographer.doFrame(Choreographer.java:608)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.jav

if you can point me at the error i would be grateful i added the activity you requested to the manifest file, and i'm attempting to launch the intent from a actionbar button click, thank you!

@ziadkiwan
Copy link
Author

Never mind! didn't read the readme well ❌ thank you!

@lawloretienne
Copy link
Owner

oh it works now? ya I tried to be a thorough as possible about the usage in the README.

@ziadkiwan
Copy link
Author

Yeah but please put the important note after the implementation directly i got a question:
the gallery got no controls like delete picture get path etc ?

@ziadkiwan
Copy link
Author

one more thing if you want i can help you rewrite the readme 👍 so it's easier to be used by everyone!

@lawloretienne
Copy link
Owner

sure, what do you think needs to change?

@ziadkiwan
Copy link
Author

First you gotta Explain that Android Graphics Pallete is required and how to import it, then explain how to implement the methods and show the code that needs to be put in the methods (i copy pasted them from them source code of your application) then explain that the application works on URI not main file path and to make the application works on Path you can make a small work around in the two methods which is :
Picasso.with(iv.getContext()) .load(Uri.fromFile(new File(imageUrl))) .resize(width, 0) .into(iv, new Callback() {

@ziadkiwan
Copy link
Author

i got a small question if you can help me where i can reach the callback of the imageview(smallones not fullscreen) so i make it on long press display a menu to delete the image

@lawloretienne
Copy link
Owner

ImageGalleryAdapter has an OnImageClickListener interface. The class that calls setOnImageClickListener() on this adapter can set up the click listener. You can similarly add an additional interface to this adapter.

public interface OnImageLongClickListener {
    void onImageLongClick(int position);
}

@ziadkiwan
Copy link
Author

Oh Okay! thank you! i will looking through it :)

@ghost
Copy link

ghost commented Apr 2, 2018

@lawloretienne Hi,

I got the same issue as ziadkiwan got. I am not sure how to use Pallete in this case. Kindly, help me execute the code. Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants