Results 1 to 2 of 2
  1. #1
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Class Not Found Exception when 1st two of four parameters passed Constructor

    This is a crazy one. I have a hierarchical inheritance program. Starting with Quadrilateral class which is extended by the Trapezoid class which is extended by the Parallelogram class which is extended by the Rectangle class which is extended by the Square class. All classes use the Point class which has 2 instance variables. Both are doubles that are the x, y coordinates. Everything works fine except
    the Square constructor that takes 4 parameters. Each parameter is the point of a corner. What is happening is when I am debugging the first two parameters throw a "Class Not Found" Exception. The last two parameters do not. What is really weird is that the Square constructor that takes 4 parameters is just a call to the (super)Rectangle constructor that takes 4 parameters and its fine. I have even tried to manually set the points with a mutator method that I bubbled up from the Quadrilateral class, but it makes no difference. Its like I lost access to the public methods to access the first 2 points of the Quadrilateral class?????? Thanks in advance!!!!!

    Here's my output 1st:
    Java Code:
    The coordinates of the Quadrilateral are: (1.1, 1.2), (6.6, 2.8), (6.2, 9.9), (2.2, 7.4)
    The coordinates of the Trapezoid are: (0.0, 0.0), (0.0, 0.0), (8.0, 5.0), (3.3, 5.0)
    Height is: 5.99
    Area is: 14.08
    The coordinates of the Parallelogram are: (5.0, 5.0), (11.0, 5.0), (12.0, 20.0), (6.0, 20.0)
    Width is: 6.00
    Height is: 15.03
    Area is: 90.20
    The coordinates of the Rectangle are: (17.0, 14.0), (30.0, 14.0), (30.0, 28.0), (17.0, 28.0)
    Width is: 13.0
    Height is: 14.0
    Area is: 182.0
    The coordinates of the Square is: (0.0, 0.0), (0.0, 0.0), (8.0, 4.0), 4.0, 4.0)
    Side is: 0.00
    Area is: 0.00



    Java Code:
    public class testQuad 
    {
    
    
    	public static void main(String[] args) 
    	{
    		Quadrilateral quad = new Quadrilateral(new Point(1.1, 1.2), new Point(6.6, 2.8), new Point(6.2, 9.9), new Point(2.2, 7.4));
    		Trapezoid trap = new Trapezoid(new Point(0.0, 0.0), new Point(10.0, 0.0), new Point(8.0, 5.0), new Point(3.3, 5.0));
    		Parallelogram par = new Parallelogram(new Point(5.0, 5.0), new Point(11.0, 5.0), new Point(12.0, 20.0), new Point(6.0, 20.0));
    		Rectangle rect = new Rectangle(new Point(17.0, 14.0), new Point(30.0, 14.0), new Point(30.0, 28.0), new Point(17.0, 28.0));
    		Square sq = new Square(new Point(4.0, 0.0), new Point(8.0, 0.0), new Point(8.0, 4.0), new Point(4.0, 4.0));
    		
    		sq.setA(new Point(4.0, 0.0));
    		sq.setB(new Point(8.0, 0.0));
    		
    		System.out.println(quad.toString());
    		System.out.println(trap.toString());
    		System.out.println(par.toString());
    		System.out.println(rect.toString());
    		System.out.println(sq.toString());
    		
    
    	}//end of main method
    
    }//end of testQuad class
    Java Code:
    /* represents the coordinate of a corner of a geometric shape */
    public class Point
    {
    	//instance variables, each double represents an X,Y coordinate of a point
    	private  double Xcoordinate;
    	private  double Ycoordinate;
    	
    	//default Constructor, Post condition all instance variables assigned value of 0.0
    	public Point()
    	{
    		Xcoordinate = 0.0;
    		Ycoordinate = 0.0;
    	}
    	
    	//Constructor that takes 2 arguments
    	//post condition: each argument represents X,Y coordinate of a corner
    	//Calls setPoint method
    	public Point(double x, double y)
    	{
    			//input validation (> 0) checked by setPoint method
    			setPoint(x, y);
    		
    	}
    	
    	//method to set just the X coordinate
    	//post condition: argument passed is the value of the X coordinate
    	public void setXcoordinate(double x)
    	{
    		if(x > 0)
    		{
    			Xcoordinate = x;
    		}
    		else
    		{
    			Xcoordinate = 0;
    		}
    	}
    	
    	//method to set the Y coordinate
    	//post condition: Argument passed is the value of the Y coordinate
    	public void setYcoordinate(double y)
    	{
    		if(y > 0)
    		{
    			Ycoordinate = y;
    		}
    		else
    		{
    			Ycoordinate = 0;
    		}
    	}
    	
    	//method to set both coordinates of a point
    	//post condition: 1st argument is value of X coordinate
    	//2nd argument is value of Y coordinate
    	public void setPoint(double x, double y)
    	{
    		if(x > 0 && y > 0)
    		{
    			Xcoordinate = x;
    			Ycoordinate = y;
    		}
    		else
    		{
    			Xcoordinate = 0;
    			Ycoordinate = 0;
    		}
    	}
    	
    	//method to return X coordinate
    	//post condition: X coordinate is returned to caller
    	public double getXcoordinate()
    	{
    		return Xcoordinate;
    	}
    	//method to return Y coordinate
    	//post condition: Y coordinate is returned to the caller
    	public double getYcoordinate()
    	{
    		return Ycoordinate;
    	}
    	
    	//override method to print out string version of a point
    	//post condition: String of X, Y coordinate returned to caller
    	public String toString()
    	{
    		return "(" + Xcoordinate + ", " + Ycoordinate + ")";
    	}
    }//end of Point class
    Java Code:
    /* 1st generation in Shape Hierarchy */
    public class Quadrilateral 
    {
    	//instance variables
    	//the 4 points of a Quadrilateral
    	private Point A = new Point();
    	private Point B = new Point();
    	private Point C = new Point();
    	private Point D = new Point();
    	
    	
    	//default Constructor
    	//post condition: all points initialized to (0.0, 0.0)
    	public Quadrilateral()
    	{
    		A.setPoint(0.0, 0.0);
    		B.setPoint(0.0, 0.0);
    		C.setPoint(0.0, 0.0);
    		D.setPoint(0.0, 0.0);
    	}
    	
    	//constructor that takes four Points as arguments
    	//post condition: each argument is set as the coordinate of a corner of the quadrilateral
    	public Quadrilateral(Point x, Point y, Point z, Point w)
    	{
    		A = x;
    		B = y;
    		C = z;
    		D = w;
    	}
    	
    	//method to set Point A
    	//post condition: Point A is set to the parameter that is passed
    	public void setA(Point a)
    	{
    		A = a;
    	}
    	
    	//method to set Point B
    	//post condition: Point B is set to the parameter that is passed
    	public void setB(Point b)
    	{
    		B = b;
    	}
    	
    	//method to set Point C
    	//post condition: Point C is set to the parameter that is passed
    	public void setC(Point c)
    	{
    		C = c;
    	}
    	
    	//method to set Point D
    	//post condition: Point D is set to the parameter that is passed
    	public void setD(Point d)
    	{
    		D = d;
    	}
    	
    	//method to get Point A
    	//post condition: Point A is returned to the caller
    	public Point getA()
    	{
    		return A;
    	}
    	
    	//method to get Point B
    	//post condition: Point B is returned to the caller
    	public Point getB()
    	{
    		return B;
    	}
    	
    	//method to get Point C
    	//post condition: Point C is returned to the caller
    	public Point getC()
    	{
    		return C;
    	}
    	
    	//method to get Point D
    	//post condition: Point D is returned to the caller
    	public Point getD()
    	{
    		return D;
    	}
    	
    	
    	
    	//override method to print out all four point as a string
    	//post condition: String of points is returned to the caller
    	public String toString()
    	{
    		return  "The coordinates of the Quadrilateral are: " + A.toString() + ", "  + B.toString() + ", " +
    			     C.toString() + ", "  + D.toString();
    	}
    		
    	
    }//end of Quadrilateral class
    Java Code:
    /* Trapezoid class inherits from Quadrilateral Parent
     Program prints out points of the Trapezoid, the height
     and the area.*/
    public class Trapezoid extends Quadrilateral
    {
    	//point a to point b
    	private double lengthA;
    	
    	//point b to point c
    	private double lengthB;
    	
    	//point c to point d
    	private double lengthC;
    	
    	//point d to point a
    	private double lengthD;
    	
    	private final double HALF = 0.5;
    	
    	//default constructor
    	//post condition: default super constructor called
    	//each instance variable set to 0.0
    	public Trapezoid()
    	{
    		super();
    		lengthA = 0.0;
    		lengthB = 0.0;
    		lengthC = 0.0;
    		lengthD = 0.0;
    	}
    	
    	//constructor that takes four Points as arguments
    	//post condition: 1st argument is value of Point a, 2nd argument is value of Point b
    	//3rd argument is value of Point c and 4th argument is value of Point d
    	public Trapezoid(Point a, Point b, Point c, Point d)
    	{
    		
    			super(a, b, c, d);
    			lengthA = findSideLength(a, b);
    			lengthB = findSideLength(b, c);
    			lengthC = findSideLength(c, d);
    			lengthD = findSideLength(d, a);
    		
    	}
    	
    	//method to find the length of a side of a Trapezoid
    	//post condition: length of side is returned to caller
    	public double findSideLength(Point a, Point b)
    	{
    		double length = 0.0;
    		//using formula from www.mathopenref.com
    		//lengthOfSide = sqrt (dx^2 + dy^2)
    		//dx is difference of x coordinates
    		//dy is difference of y coordinates
    		double ax = a.getXcoordinate();
    		double ay = a.getYcoordinate();
    		double bx = b.getXcoordinate();
    		double by = b.getYcoordinate();
    		
    		double differenceX = Math.abs(ax - bx);
    		double differenceY = Math.abs(ay - by);
    		
    		double sumOfDifferenceSquared = (differenceX * differenceX) + (differenceY * differenceY);
    		
    		length = Math.sqrt(sumOfDifferenceSquared);
    
    		return length;
    	}
    	
    	public double trapezoidArea()
    	{
    		double area = 0.0;
    		double height = findSideLength(trapGetA(), trapGetD());
    		//using formula from www.mathopenref.com 
    		area = (HALF * height) * (lengthA + lengthC);
    		
    		return area;
    	}
    	
    	public double trapezoidHeight()
    	{
    		double height = 0.0;
    		//using formula from www.mathopenref.com 
    		//lengthOfSide = sqrt (dx^2 + dy^2)
    		//dx is difference of x coordinates
    		//dy is difference of y coordinates
    		height = findSideLength(trapGetA(), trapGetD());
    
    		return height;
    	}
    	
    	
    	/* getters and setters bubble up for 1st generation
    	  Points */
    	public Point trapGetA()
    	{
    		return super.getA();
    	}
    	
    	public Point trapGetB()
    	{
    		return super.getB();
    	}
    	
    	public Point trapGetC()
    	{
    		return super.getC();
    	}
    	
    	public Point trapGetD()
    	{
    		return super.getD();
    	}
    	
    	public void trapSetA(Point a)
    	{
    		super.setA(a);
    	}
    	
    	public void trapSetB(Point b)
    	{
    		super.setB(b);
    	}
    	
    	public void trapSetC(Point c)
    	{
    		super.setC(c);
    	}
    	
    	public void trapSetD(Point d)
    	{
    		super.setD(d);
    	}
    	
    	//toString overridden method
    	//post conditions: returns coordinates, height, and area
    	//to caller as a string
    	public String toString()
    	{
    		return "The coordinates of the Trapezoid are: " + trapGetA().toString() + ", " + trapGetB().toString() +
    				", " + trapGetC().toString() + ", " + trapGetD().toString() + "\n" + "Height is: " + String.format("%.2f", trapezoidHeight()) + "\n" +
    				"Area is: " + String.format("%.2f", trapezoidArea());
    	}
    
    }//end of Trapezoid class
    Java Code:
    /* Parallelogram class inherits from Trapezoid Parent
     Program prints out points of the Parallelogram, the height, the width
     and the area.*/
    public class Parallelogram extends Trapezoid
    {
    	//default constructor
    	//post condition all instance variable of parent
    	//initialized to 0 calling the base class default
    	//constructor
    	public Parallelogram()
    	{
    		super();
    	}
    	
    	//constructor that takes 4 parameters
    	//post condition: base class constructor that takes 4
    	//arguments is invoked
    	public Parallelogram(Point a, Point b, Point c, Point d)
    	{
    		super(a, b, c, d );
    	}
    	
    	//method to find height of Parallelogram
    	//post condition: call to base class findSideLength method
    	//is invoked
    	public double parallelogramHeight()
    	{
    		return super.findSideLength(super.trapGetA(), super.trapGetD());
    	}
    	
    	//method to find width of Parallelogram
    	//post condition: call to base class findSideLength method
    	//is invoked
    	public double parallelogramWidth()
    	{
    		return super.findSideLength(super.trapGetA(), super.trapGetB());
    	}
    	//method to find area of a parallelogram
    	//post condition: area of parallelogram is returned
    	//to the caller
    	public double parallelogramArea()
    	{
    		double area = 0.0;
    		
    		area = parallelogramWidth() * parallelogramHeight();
    		return area;
    	}
    	
    	/* getters and setters for the four points of a 
    	 * parallelogram, bubbling up to the first generation
    	 */
    	
    	public Point parGetA()
    	{
    		return super.trapGetA();
    	}
    	
    	public Point parGetB()
    	{
    		return super.trapGetB();
    	}
    	
    	public Point parGetC()
    	{
    		return super.trapGetC();
    	}
    	
    	public Point parGetD()
    	{
    		return super.trapGetD();
    	}
    	
    	public void parSetA(Point a)
    	{
    		super.trapSetA(a);
    	}
    	
    	public void parSetB(Point b)
    	{
    		super.trapSetB(b);
    	}
    	
    	public void parSetC(Point c)
    	{
    		super.trapSetC(c);
    	}
    	
    	public void parSetD(Point d)
    	{
    		super.trapSetD(d);
    	}
    	
    	//toString overridden method
    	//post conditions: returns coordinates, height, width and area
    	//to caller as a string
    	public String toString()
    	{
    		return "The coordinates of the Parallelogram are: " + parGetA().toString() + ", " + parGetB().toString() + 
    				", " + parGetC().toString() + ", " + parGetD().toString() + "\n" + "Width is: " + String.format("%.2f", parallelogramWidth()) +
    				"\n" + "Height is: " + String.format("%.2f", parallelogramHeight()) + "\n" + "Area is: " + String.format("%.2f", parallelogramArea());
    	}
    	
    	
    }//end of Parallelogram class
    Java Code:
    /* Parallelogram class inherits from Parallelogram Parent
     Program prints out points of the Rectangle, the height, the width
     and the area.*/
    public class Rectangle extends Parallelogram
    {
    	
    	//default constructor
    	//post condition all instance variable of parent
    	//initialized to 0 calling the base class default
    	//constructor
    	public Rectangle()
    	{
    		super();
    	}
    	
    	//constructor that takes 4 parameters
    	//post condition: base class constructor that takes 4
    	//arguments is invoked
    	public Rectangle(Point a, Point b, Point c, Point d)
    	{
    		super(a, b ,c, d);
    	}
    	
    	/* getter and setters for the four points
    	 * of a Rectangle, bubble up from 1st generation*/
    	
    	public Point rectGetA()
    	{
    		return super.parGetA();
    	}
    	
    	public Point rectGetB()
    	{
    		return super.parGetB();
    	}
    	
    	public Point rectGetC()
    	{
    		return super.parGetC();
    	}
    	
    	public Point rectGetD()
    	{
    		return super.parGetD();
    	}
    	
    	public void rectSetA(Point a)
    	{
    		super.parSetA(a);
    	}
    	
    	public void rectSetB(Point b)
    	{
    		super.parSetB(b);
    	}
    	
    	public void rectSetC(Point c)
    	{
    		super.parSetC(c);
    	}
    	
    	public void rectSetD(Point d)
    	{
    		super.parSetD(d);
    	}
    	
    	//method to find height of Rectangle
    	//post condition: call to base class parallelogramHeight() method
    	//is invoked
    	public double rectangleHeight()
    	{
    		double height = 0.0;
    		height = super.parallelogramHeight();
    		return height;
    	}
    	
    	//method to find width of Rectangle
    	//post condition: call to base class parallelogramWidth() method
    	//is invoked
    	public double rectangleWidth()
    	{
    		double width = 0.0;
    		width = super.parallelogramWidth();
    		return width;
    	}
    	
    	//method to find area of a Rectangle
    	//post condition: call to base class parallelogramArea() method
    	//is invoked
    	public double rectangleArea()
    	{
    		double area = 0.0;
    		area = super.parallelogramArea();
    		return area;
    	}
    	
    	//toString overridden method
    	//post conditions: returns coordinates, height, width and area
    	//to caller as a string
    	public String toString()
    	{
    		return "The coordinates of the Rectangle are: " + rectGetA().toString() + ", " + rectGetB().toString() + ", " +
    				rectGetC().toString() + ", " + rectGetD().toString() + "\n" + "Width is: " + rectangleWidth() + "\n" +
    				"Height is: " + rectangleHeight() + "\n" + "Area is: " + rectangleArea() ;
    	}
    	
    }//end of Rectangle class
    Java Code:
    /* Square class inherits from Rectangle Parent
     Program prints out points of the Square, the height, the width
     and the area.*/
    public class Square extends Rectangle
    {
    	//default constructor
    	//post condition: all instance variable of parent
    	//initialized to 0 calling the base class default
    	//constructor
    	public Square()
    	{
    		super();
    	}
    	
    	//constructor that takes 4 parameters
    	//post condition: base class constructor that takes 4
    	//arguments is invoked
    	public Square(Point a, Point b, Point c, Point d)
    	{
    		super(a, b, c, d);
    	}
    	
    	
    	/* getter and setters for the four points
    	 * of a Square, bubble up from 1st generation*/
    	public Point squareGetA()
    	{
    		return super.rectGetA();
    	}
    	
    	public Point squareGetB()
    	{
    		return super.rectGetB();
    	}
    	
    	public Point squareGetC()
    	{
    		return super.rectGetC();
    	}
    	
    	public Point squareGetD()
    	{
    		return super.rectGetD();
    	}
    	
    	public void squareSetA(Point a)
    	{
    		super.rectSetA(a);
    	}
    	
    	public void squareSetB(Point b)
    	{
    		super.rectSetB(b);
    	}
    	
    	public void squareSetC(Point c)
    	{
    		super.rectSetC(c);
    	}
    	
    	public void squareSetD(Point d)
    	{
    		super.rectSetD(d);
    	}
    	
    	//method to find side of a Square
    	//post condition: call to base class rectangleWidth() method
    	//is invoked
    	public double squareSide()
    	{
    		double height = 0.0;
    		double x1 = 0.0;
    		double x2 = 0.0;
    		
    		
    		String pointOne;
    		String pointTwo;
    		String Xp1;
    		String Xp2;
    		
    		pointOne = squareGetA().toString();
    		pointTwo = squareGetB().toString();
    		char[] point1Array = pointOne.toCharArray();
    		char[] point2Array = pointTwo.toCharArray();
    		
    		Xp1 = Character.toString(point1Array[1]) + Character.toString(point1Array[2]) + Character.toString(point1Array[3]);
    		Xp2 = Character.toString(point2Array[1]) + Character.toString(point2Array[2]) + Character.toString(point2Array[3]);
    		
    		x1 = Double.parseDouble(Xp1);
    		x2 = Double.parseDouble(Xp2);
    		
    		height = Math.abs(x1 - x2);
    		return height;
    	}
    	
    	public double squareSideTwo()
    	{
    		double height;
    		height = super.parallelogramWidth();
    		return height;
    	}
    	
    	//method to find area of a Square
    	//post condition 
    	public double squareArea()
    	{
    		double area = 0.0;
    		area = squareSide() * squareSide();
    		return area;
    	}
    	
    	//toString overridden method
    	//post conditions: returns coordinates, side and area
    	//to caller as a string
    	public String toString()
    	{
    		return "The coordinates of the Square is: " + squareGetA().toString() + ", " + squareGetB().toString() + ", " + 
    				squareGetC().toString() + ", " + squareGetD().toString() + "\n" + "Side is: " + String.format("%.2f", squareSide()) + "\n" +
    				"Area is: " + String.format("%.2f", squareArea());
    				
    	}
    }//end of Square clas

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Class Not Found Exception when 1st two of four parameters passed Constructor

    throw a "Class Not Found" Exception.
    Please post the full text of the error message.

Similar Threads

  1. URL parameters not getting passed during javascript submit
    By fierof2 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 10-01-2011, 09:26 AM
  2. Class not found exception for the servlet class.
    By mazem in forum Java Servlet
    Replies: 2
    Last Post: 08-24-2011, 10:20 AM
  3. Replies: 6
    Last Post: 07-25-2011, 11:34 AM
  4. Class not found Exception
    By surendra in forum Java Servlet
    Replies: 8
    Last Post: 06-09-2011, 01:52 PM
  5. class not found exception while using IKVM to create exe for c#
    By manjunath k reddy in forum New To Java
    Replies: 0
    Last Post: 02-21-2009, 07:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •