Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java.lang.ClassNotFoundException (main class not found)

Posted on 2009-03-30
5
Medium Priority
?
977 Views
Last Modified: 2013-12-15
Hi,

I was working with a 2D graphing example (actually got the example from here) and I was trying to plot some additional points .

After writing code to do so I noticed when running the program the code was stepping through the old code (ie not running sequentially, making bizarre jumps, etc)

So after some googling I decided to clean my project (Project --> Clean)

Now I'm getting an error that says the main class cannot be found, which is quite odd since it was working fine until I "cleaned" it.

I am using java 1.6 and the latest version of eclipse.  Below is my code.

Thanks !!

Bryan


import javax.swing.*;
import java.awt.*;
import java.util.*;
 
public class DrawGraphExam extends JFrame
{
 
 
    public DrawGraphExam()
    {
        super("Glove Data Representation");
 
        setSize(300,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
 
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        Graph gloveGraph = new Graph(getPoints());
        //c.add(new Graph(getPoints()));
        c.add(gloveGraph);
        gloveGraph.setPoint(10);
        //gloveGraph.drawPoint(g)
    }
 
    private HashMap getPoints()
    {
        HashMap points = new HashMap();
        points.put(new Integer(6), new Integer(5));
        points.put(new Integer(3), new Integer(3));
        points.put(new Integer(7), new Integer(4));
        points.put(new Integer(1), new Integer(7));
        points.put(new Integer(4), new Integer(2));
        return points;
    }
 
    public static void main(String[] args)
    {
    
        new DrawGraphExam().show();
    	System.out.println("test");
    	//DrawGraphExam gloveGraph  = new DrawGraphExam();
    	//gloveGraph.show();
    	System.out.println("test");
    }
    //public void plotPoint()
 
}
 
class Graph extends Canvas
{
    private HashMap points;
    private int x0;
    private int y0;
    private int b = 25;
    private int gap = 20;
    private int tw = 5;
    //begin berg's code
    private int xOld = 0;
    private int yOld = 0;
    private int xCurrent;
    private int yCurrent;
    //end berg
 
    public Graph(HashMap points)
    {
        this.points = points;
        setBackground(Color.white);
    }
 
    public void paint(Graphics g)
    {
        super.paint(g);
        drawLine(g);
        drawPoints(g);
        drawPoint(g);
    }
 
    public void drawLine(Graphics g)
    {
        Dimension d = getSize();
        x0 = b;
        y0 = d.height - b;
 
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(Color.blue);
        g2.setStroke(new BasicStroke(1.5f));
 
        g2.drawLine(x0, y0, d.width-x0, y0); // horizontal line
        g2.drawLine(x0, y0, x0, b); // vertical line
        
        int ticksY = (int) (y0 - b)/gap;
        int ticksX = (int) (d.width-2*x0)/gap;
 
        int yx = y0;
        for(int i=0; i<ticksY; i++) // draw vertical ticks
        {
            yx -= gap;
            g2.drawLine(x0, yx, x0-tw, yx);
            g2.drawString(String.valueOf(i*10), x0, yx);
        }
 
        int xx = x0;
        for(int i=0; i<ticksX; i++) // draw horizontal ticks
        {
            xx += gap;
            g2.drawLine(xx, y0, xx, y0+tw);
            g2.drawString(String.valueOf(i*10), xx, y0);
        }
    }
 
    public void drawPoint(Graphics g){
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(Color.RED);
        g2.setStroke(new BasicStroke(1f));
        g2.drawLine(xOld, yOld, xCurrent, yCurrent);
        System.out.println("drawing point at " + xOld);
       
    }
    public void setPoint(int y){
    	xCurrent = xOld + 10; // for now making increments of 5
    	yCurrent = y;
    }
    private void drawPoints(Graphics g)
    {
        if(points != null)
        {
            Graphics2D g2 = (Graphics2D)g;
            g2.setStroke(new BasicStroke(1f));
            ArrayList list = new ArrayList(points.keySet());
            Collections.sort(list); // sorts list of x-set
            Iterator xset = list.iterator();
            int x,y;
            int cX = -1, cY = -1;
            int r = 3;
            while(xset.hasNext())
            {
                Integer key = (Integer)xset.next();
                x = x0 + (key.intValue() * gap);
                y = y0 - (((Integer)points.get(key)).intValue() * gap);
                g.fillRect(x,y,r,r);
                if(cX > 0 && cY > 0)
                {
                    g.drawLine(cX, cY, x, y);
                }
                cX = x;
                cY = y;
            }
        }
    }
}

Open in new window

0
Comment
Question by:bryanberg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24024654
check your java file is inside a source folder in your project
and make sure you are running the right class

0
 
LVL 15

Expert Comment

by:fsze88
ID: 24025704
what's your classpath? missed classpath=.\;    ?
0
 
LVL 1

Expert Comment

by:Tavic
ID: 24031888
It's a problem with your project or file names, not your code.  I can compile and run the code you provided just fine.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 24032449
>>
Now I'm getting an error that says the main class cannot be found, which is quite odd since it was working fine until I "cleaned" it.
>>

Just try rebuilding the project and running again
0
 

Author Closing Comment

by:bryanberg
ID: 31564605
I had to remove the the source folder and than readd it in order to prompt the rebuild.  For some reason my code was not rebuilding on its own, eventhough I had the option selected to build automatically. Anyone had issues like this ?

Thanks !!
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question