• Post Reply Bookmark Topic Watch Topic
  • New Topic

"Could Not Find Or Load Main Class AreaTester"  RSS feed

 
Sandra Edwards-Thro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wrote the Hello World program for my computer class last week and had the same error ("could not find or load main class HelloWorld"), until I fixed it. Unfortunately, I haven't done any programming since last week (I know I should be working on this every day, but...), and now I'm getting the error again, and I've forgotten how I fixed it last time.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandra Edwards-Thro wrote:Hi,
I wrote the Hello World program for my computer class last week and had the same error ("could not find or load main class HelloWorld"), until I fixed it. Unfortunately, I haven't done any programming since last week (I know I should be working on this every day, but...), and now I'm getting the error again, and I've forgotten how I fixed it last time.



Are you running it from a command line or inside an IDE (like Eclipse or NetBeans)?

What exact command are you executing, or what steps are you taking to run it?

What's your classpath set to?

What does the directory structure look like where your .class file is and what's your current working directory?
 
Sandra Edwards-Thro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using JCreator

Here's the code:
public class AreaTester {

public static void main(String[] args) {

apartmentarea = new Rectangle(100,10);
System.out.print("Area: ");
System.out.println(apartmentarea.getWidth()*apartmentarea.getHeight());
System.out.println ("Expected: 1000");

My classpath is set to (I figured this out by typing echo %CLASSPATh% into the command prompt)
C:\Users\Sora\Documents\JCreator LE\MyProjects

I'm having trouble finding the class file (interestingly, I can find it for the programs I made last week that worked fine - they're not saved to specific folders within My Projects). There's a folder labeled "Area Tester" in "My Projects that contains a jcp, jcu, jcw file, and src_areatester file. There are two sub-folders, one labeled classes and one labeled "src". The classes file is empty and the source code file contains a JAVA file.

I'm pretty new to this and don't really understand what you mean by working directory.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with JCreator. However, if you're trying to run it from within JCreator, then your CLASSPATH environment variable probably doesn't matter. The IDE probably has its own classpath setting. As for where it puts your .class file, that will be another setting. If you can't find it, then it may be that it got cleaned up for some reason and you haven't recompiled.

This is one of the reasons most people encourage beginners to just use a text editor (or programmer's editor) and the command line for compiling and running.

By "current directory" I mean the directory you're "in" if you're using a command prompt. JCreator will also have a notion of a current directory, which you can probably also set for when you run your program.

If you start up a command prompt, you'll see something like:


My current directory here is C:\Users\jeff. The command prompt starts by default in my home directory.

Then I might do something like


If there is in fact a directory called proj inside the jeff directory, the cmd prompt will show the current directory as such


If that's where my AreaTester.java is...


...I can then compile and run it:


You can find step-by-step instructions here, I believe: http://docs.oracle.com/javase/tutorial/getStarted/cupojava/index.html
 
Sandra Edwards-Thro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help - I guess I'll have to mess around with JCreator later if I want to use it, but now at least I can get my homework done!
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used to use JCreator as a text editor, but it is an IDE. Unfortunately you had to pay for the full version, so I only used the basic version and went on to Eclipse when I wanted to use a full‑blown IDE. You are probably better off with a decent text editor (JEdit, NotePad2, NotePad++, etc) than an IDE at this stage.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!