Java error: non-static method cannot be referenced from a static context

April 16, 2015

Recently, while writing a java program, I got the classic Java error:
non-static method cannot be referenced from a static context.

No doubt, other young java practitioners have had this error.

Here, I’ve laid out a simple program, with explanations, so that you can avoid the problem.


public class StaticIssues 
    // At top of the class, only declare the global object 	
    // to be seen in the entire class
    objCount theCount = new objCount();

    // do not run any code here, such as:
    // System.out.println ( "top of class" );
    // or 
    // theCount.returnCount();

    // constructor of the class StaticIssues
    public StaticIssues () 
    {   // In Constructor, initialize the objects
        // including the other objects, such as 
        // instances of sub Object objCount

        theCount.initCount ();

        System.out.println ("StaticIssues () Constructor"  );
        // note that this code will run without this constructor
    }  // end constructor

    // code for sub-object objCount 
    // no brackets at the end of this declaration. ie. objCount ()
    public class objCount 
        // declare integer within class
        // not globally

        private int theCount = 0;

        public void initCount ()
            {	theCount = 0;

        public void incrementCount ()
            {	theCount ++;

        public int returnCount()
        {   return theCount;
        }  // end returnCount()

    }  // end class objCount 

    // other methods can use the object
    public void someMethod ()
        // In other methods, use the instance of the object
        // and call the methods of the object

        theCount.incrementCount ();
        System.out.print ( "In someMethod ()." );
        System.out.println ( "  theCount.returnCount() is now: " +
                theCount.returnCount()  );

        // However, do not reference the object itself. ie.
        // objCount.incrementCount ()  ;
        // otherwise, you get the famous:
        // line number of the error, followed by

        // error: non-static method incrementCount() cannot be 
        // referenced from a static context
        // objCount.incrementCount ()  ; 
        // 1 error

    }  // end someMethod ()

    public static void main(String []args) 
        // within main, create object
        StaticIssues objInstance = new StaticIssues ();

        // reference the object.
        System.out.println ( "objInstance.theCount.returnCount () is: " 
                + objInstance.theCount.returnCount () );


        // Note that from the main class 
        // you have to prefix the references by the 
        // object declared in the main class, 
        // here, objInstance
        System.out.println ( "objInstance.theCount.returnCount () is: " 
                + objInstance.theCount.returnCount () );

    }  // end main

}  // end class StaticIssues


StaticIssues () Constructor
objInstance.theCount.returnCount () is: 0
In someMethod ().  theCount.returnCount() is now: 1
objInstance.theCount.returnCount () is: 1

I’m sure that these guidelines will not solve EVERY occurrence of this error. And that there can be improvements to the program. But as I’ve written before, there is nothing a like good design and coding correctly in the first place.

Feel free to use this as a start.

Review – Nikon CoolScan 5000 ED

December 7, 2014

For over a decade, while I went to university, and for a few years after, I owned and operated a photography business. At that time, cameras were film cameras, not digital. After a few years, I had a big collection of negatives.

In 2007, I bought a film scanner to scan some family pictures, the Nikon CoolScan 5000. It’s been fabulous to use.

Nikon Coolscan 5000 ED

Nikon Coolscan 5000 ED

Recently, I’ve been using it again to scan some more 35mm negatives and transparencies. The software is so intuitive, the results so good, and it’s such a pleasure to use, that I’m inspired to write about it.


Traditional Darkroom Techniques:

For those of you who have never worked in the darkroom, it’s a very laborious process. Read the rest of this entry »

Installing NEO4J on Windows 7

November 7, 2014

Installing and running NEO4J on Windows is a little different from installing it on Linux.

NEO4J has provided two options to install NEO4J on Windows. One version of NEO4J is a dumbed down version that includes the necessary Java, that comes bundled in an .EXE file. The other Windows version comes in a .ZIP file that more closely resembles a Linux installation.

With NEO4J on Linux, a correct version of the Java JDK/SDK is assumed to be installed, but not so on Windows. Java JDK/SDK installations do have a certain learning curve, and required reading, not suitable for some users.

And then there is Java licensing. Apparently, it’s ok to bundle to Java with an executable file. But it’s not ok for Neo4j to redistribute the correct Java JDK/SDK on NEO4J’s download page, and allow users to download it.

If you are serious about NEO4J, you’ll probably want to use the full blown Windows .ZIP version. For one thing, it follows the standard paradigm and navigation. You’ll get the full functionality. And, it’s not that difficult to use. Read the rest of this entry »

Some Great Software To Capture Analog Audio

October 30, 2014


Audacity Recording

Audacity Recording

I have a nice cassette deck that you would use with a stereo system and there are some old cassette tapes that I have never thrown out. Finally I’ve got around to copying some of these cassettes to files on my hard drive.

Here is a review of some software that I test drove on an old underpowered Windows XP machine: Exact Audio Copy, Wave Repair, and Audacity.        Read the rest of this entry »

MYSQL – Create CSV File With Fieldnames For Headers

October 19, 2014

Recently, I went to dump a MYSQL table into a CSV file, with the fieldnames in the first line of the file.




This simple enough in Oracle’s SQLPLUS, so I did some internet searches to determine the syntax.

Instead of the simple MYSQL syntax, I found a number of relatively complex solutions. Some involved MYSQL scripts, and others utilized Unix string parsing commands.

However, I came up with a much simpler solution using one simple MYSQL command:

Read the rest of this entry »

Installing Gimp on Redhat 6.4

October 4, 2014

Gimp is the GNU Image Manipulation Program. It is a freely distributed piece of software for tasks like photo retouching. I wanted to use it to crop photos, like Irfanview does so easily on Windows.

Unfortunately, like so many other software installations on Redhat Linux, the install was not straightforward and required overcoming errors. :(  Here’s how to install gimp on Redhat 6.4.

gimp - GNU Image Manipulation Program

gimp – GNU Image Manipulation Program

Read the rest of this entry »

Installing Talend Open Studio For Big Data 5.5.1 on Redhat 6.4

September 20, 2014

Recently, Talend Open Studio For Big Data was recommended for me, so I thought I’d try it out.

But as I’ve so often encountered with Java on Linux, the install was a long process, full of java error stacks, google searches, research, trial and error, debugging, forum posts, and so on. Sigh, not again!

Here’s what I did to get Talend Big Data to install and work.  Big errors I encountered are detailed at the bottom.


Talend Open Studio 5.5.1

Talend Open Studio 5.5.1


Download Talend Big Data Software:

Read the rest of this entry »

%d bloggers like this: