1

I know this is a simple question, but either nobody is explaining it right, or my eclipse/JDK is broke. I am following a tutorial at: http://zetcode.com/tutorials/javagamestutorial/animation/

In it, I place a star png on the screen and animate it. When I use:

ImageIcon ii = new ImageIcon(this.getClass().getResource("star.png"));

It gives me a null pointer exception. currently I have the star.png file in the same folder as the class that is calling for it (I know that is not best practice in general, but I'm just doing what this tutorial says just to follow it.

I know this question is an exact dublicate (same tutorial even), but there is no answer, and it is not working for me no matter where I put this file. getResource() -> Source not found

I am using eclipse as my idea on here as well, do I have to do something else to make the idea realize that this is a resource for the project or something?

Community
  • 1
  • 1
Xantham
  • 1,829
  • 7
  • 24
  • 42

1 Answers1

2

Try refresh whole package in eclipse after u place there your image.

IProblemFactory
  • 9,551
  • 8
  • 50
  • 66
  • That worked.... why? To include originally, I dragged the file into the file explorer on the left side of eclipse. I would assume it would not need a refresh to recognize something eclipse itself did, since refresh (nearest I can tell from reading about it), is to refresh any filesystem changes made outside of eclipse. – Xantham Jun 17 '12 at 05:16
  • Well, file explorer and project explorer seems not be the same :) – IProblemFactory Jun 17 '12 at 05:19
  • To refresh your project view in the Eclipse Package Explorer, you can either press the F5 key, or right-click the project and select the Refresh menu option. – shareef Jun 17 '12 at 05:28
  • 1
    @ProblemFactory I was going to accept it, it just was making me wait a while before I could. BTW, nice avatar icon. – Xantham Jun 17 '12 at 05:44