Java wierd error when trying to load image -


this question has answer here:

i trying load image using

static image terrain = null; 

followed by

public static void main(string[] args) {     arcanus arc = new arcanus();       try {         terrain = imageio.read(getclass().getresource("arcanus terrain tileset.png"));                     font customfont = font.createfont(font.truetype_font, new file("golden-sun.ttf")).derivefont(12f);         graphicsenvironment ge = graphicsenvironment.getlocalgraphicsenvironment();         ge.registerfont(font.createfont(font.truetype_font, new file("golden-sun.ttf")));         arc.setfont(customfont);     } catch (ioexception e) {         e.printstacktrace();     } catch (fontformatexception e) {         e.printstacktrace();     } } 

but following error

uncompilable source code - non-static method getclass() cannot referenced static context 

i have no idea why doing apreciated

you calling

terrain = imageio.read(getclass().getresource("arcanus terrain tileset.png")); 

inside static method. cannot call getclass() inside static method since getclass() refers instance of class. in context should call:

terrain = imageio.read(myclass.class.getresource("arcanus terrain tileset.png"));  

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -