Results 1 to 4 of 4
Thread: Help with Static Conscructors
- 04-22-2011, 07:00 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Help with Static Conscructors
I have a problem in a program I'm working on were I'm getting a error that states that my constructor is static
Any help is appreciated. Thank you :)Java Code:public class JavaForumsName extends JPanel implements ActionListener { class CreateGrid { private boolean drawImage; CreateGrid (File file) throws IOException { BufferedImage img = null; img = ImageIO.read(file); drawImage = Graphics.drawImage(img, 0, 0, null); } } }Last edited by RyanSL; 04-22-2011 at 01:48 PM. Reason: Correcting class names to Java standards
- 04-22-2011, 08:10 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Why are you creating createGrid (CreateGrid would be a better name) as an inner class of JavaForumsName?
I'm getting a error that states that my constructor is static
What are the exact compiler messages?
- 04-22-2011, 01:46 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Error Message
Error Code:
Error non-static method drawImage(java.awt.Image,int,int,java.awt.image.Im ageObserver) cannot be referenced from a static context JavaForumsName.java 129 .../src/components
I changed createGrid to CreateGrid (I forget about coding standards from time to time).
I created "CreateGrid" to access a static function.Last edited by RyanSL; 04-22-2011 at 01:51 PM. Reason: Adding more text
- 04-22-2011, 02:57 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
The error doesn't state your constructor is static, but a method you use in your constructor is NOT static, and you are trying to use it in a static way. drawImage is not static, so don't use it as such. If you want to load images, see Lesson: Working with Images (The Java™ Tutorials > 2D Graphics)
Similar Threads
-
Can't make static reference to non-static method -> huh?! Simple car prgm
By enerj in forum New To JavaReplies: 7Last Post: 09-24-2010, 05:09 AM -
non-static method getType cannot be referenced from a static contex
By Dekkon0 in forum New To JavaReplies: 4Last Post: 05-12-2010, 11:05 AM -
non-static variable grade cannot be referenced from a static context
By pictianpravin in forum New To JavaReplies: 3Last Post: 02-11-2010, 09:59 AM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks