Error:Cannot Find Symbol

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1070 Views - Last Post: 17 March 2012 - 09:38 AM Rate Topic: -----

#1 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Error:Cannot Find Symbol

Posted 15 March 2012 - 07:55 PM

I've been trying to solve this with no success. I keep on getting this error:

error: cannot find symbol
threeDPoint myThreeDPoint=new coordX();

Mains.java
import java.util.Scanner;

class Mains {
int coordX;
	public static void main(String[] args){


		threeDPoint myThreeDPoint=new coordX();

		Scanner sc=new Scanner(System.in);
		String coordX;

		System.out.println("Input Coordinate X");
		coordX=sc.nextLine();


	}
}




threeDPoint.java
public class threeDPoint {

	double coord,coordX;

	public threeDPoint(String[] args){
		coord = 0;
	}

	public threeDPoint(double myCoord){
		coord = myCoord;
	}

	public void coordX(double myCoordX){
		coordX +=coord;
	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: Error:Cannot Find Symbol

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 07:57 PM

Your instantiation is implying that coordX is a class, which it isn't. You want to instantiate a new threeDPoint() object instead.
Was This Post Helpful? 0
  • +
  • -

#3 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 08:00 PM

I'm sorry for this noob question. but can you explain or guide me on how to instantiate a new threeDPoint() object?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 08:03 PM

You quite literally replace coordX with threeDPoint(someStringArray) in your instantiation. Remember that coordX is an instance variable, not a class name.

This post has been edited by macosxnerd101: 15 March 2012 - 08:11 PM
Reason for edit:: Edited according to the post below

Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7731
  • View blog
  • Posts: 13,057
  • Joined: 19-March 11

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 08:08 PM

View Postmacosxnerd101, on 15 March 2012 - 10:03 PM, said:

You quite literally replace coordX with threeDPoint in your instantiation. Remember that coordX is an instance variable, not a class name.


It looks like your constructor calls for a String array, but I think that's probably a mistake. As written, the compiler will object if you try to do
threeDPoint myThreeDPoint=new threeDPoint();


because you haven't defined a null-argument constructor.

I think we need to go back to your threeDPoint class and define that correctly. To do that, I'll ask you first to describe in English what it is a threeDPoint is, and what data you think it needs to know about. We'll get you to write that class correctly, and from there you can go about using it correctly. Fair enough?
Was This Post Helpful? 1
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 08:11 PM

Thanks for catching that, jon.kiparsky!
Was This Post Helpful? 0
  • +
  • -

#7 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 08:21 PM

tried that and got this

error: no suitable constructor found for threeDPoint()
threeDPoint myThreeDPoint=new threeDPoint();
^
constructor threeDPoint.threeDPoint(double) is not applicable
(actual and formal argument lists differ in length)
constructor threeDPoint.threeDPoint(String[]) is not applicable
(actual and formal argument lists differ in length)
1 error


What I'm trying to achieve here is to use the Mains.java for input of Coordinate X, And by using accessor and mutator method, using threeDPoint.java to get the input that I've typed in for Coordinate X and displaying it with the "return" variable in the end:

public double getCoordX(){
	return CoordX;
}

Was This Post Helpful? 0
  • +
  • -

#8 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 08:42 PM

View Postjon.kiparsky, on 16 March 2012 - 03:08 AM, said:

It looks like your constructor calls for a String array, but I think that's probably a mistake. As written, the compiler will object if you try to do
threeDPoint myThreeDPoint=new threeDPoint();


because you haven't defined a null-argument constructor.

I think we need to go back to your threeDPoint class and define that correctly. To do that, I'll ask you first to describe in English what it is a threeDPoint is, and what data you think it needs to know about. We'll get you to write that class correctly, and from there you can go about using it correctly. Fair enough?


Fair enough. Thanks in advance. The threeDPoint is actually going to be used to model the coordinates for X,Y and Z in a three dimensional cartesian coordinate system. it also needs a no-arg constructor that creates a default point 0.0 for all three data fields.

it doesn't have to calculate the coordinates themselves because I'll be inputting the coordinates in the Main class later on. I'll try and do that myself. :D .

Also the accessor and mutator methods for all three data fields.

I hope I explained that correctly.
Was This Post Helpful? 0
  • +
  • -

#9 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7731
  • View blog
  • Posts: 13,057
  • Joined: 19-March 11

Re: Error:Cannot Find Symbol

Posted 15 March 2012 - 09:04 PM

Okay, that's quite reasonable. As a bare-minimum, that's what I'd expect, so I'm glad we're on the same page.

Now, let's start defining the class.

For a class, you need a name, fields, and methods.

The name you've got:

public class ThreeDPoint {   // I'm going to ask that we use the standard capitalization 


}



The fields are the object's "state". They're what persists across the life of the object. For a point in three-dimensional space, you need three numbers, obviously, and as you say these are typically called X, Y, and Z. I think for now those are suffficient by way of fields. If you want the space that's defined by these points to be continuous, you should make the doubles, as you do above. If you want them to be discrete then you'd make them ints. You'll find that this sort of decision is important, and it's mostly conditioned on what it is you want to represent with these objects, and how you want to be able to play with them.

Whichever you like, you'll define three of them as fields, naming them x, y, and z. They should be private, so no other object can mess with them.


That will look like this:


public class ThreeDPoint {   // I'm going to ask that we use the standard capitalization 

  private double x, y, z;  // or int, if you prefer, but you used double above

}



Now you have the capacity to store the bare minimum information this object needs to know to do what you need it to do.

Nxt, you need to write constructors. I'll let you play with that. I'd suggest you want two of them. One will take no arguments, and set the fields to zero initially, and the other will take three doubles (again, assuming you decide to stick with doubles) and set x, y, and z to those values.

Go ahead and write those. I'll start you off:

public ThreeDPoint() {
  // your code here
}


and
public ThreeDPoint(double x, double y, double z) {
  // your code here
}


Once you've done those, you can write your accessors and mutators, and you'll be in good shape.
Was This Post Helpful? 1
  • +
  • -

#10 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Re: Error:Cannot Find Symbol

Posted 16 March 2012 - 12:56 AM

Thank You so much jon.kiparsky! I'll try again. will let you know if any other error pops up after this.
Was This Post Helpful? 0
  • +
  • -

#11 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Re: Error:Cannot Find Symbol

Posted 16 March 2012 - 01:52 AM

Ok, I've tried redoing both and tried running it again, but somewhere somehow, it still have me the same errors. I seem to get myself stuck with declaring the threeDPoint.java in my Main.java. here's the new coding:

threeDPoint.java
public class ThreeDPoint{

	private double x, y, z;

	public threeDPoint(){
		coordX=0;
		coordY=0;
		coordZ=0;
	}

	public threeDPoint(double x, double y, double z){
		coordX = x;
		coordY = y;
		coordZ = z;
	}

	public double getCoord(double x, double y, double z){
		return coordX;
		return coordY;
		return coordZ;
	}
}



And

Main.java
import java.util.Scanner;

public class Mainz{
	int coordX, coordY, coordZ;

	public static void main(String[] args){

		threeDPoint myThreeDPoint=new threeDPoint();

		Scanner sc=new Scanner(System.in);
		String coordX, coordY, coordZ;

		System.out.println("Input Coordinate X");
		myThreeDPoint.coordX(sc.nextDouble());

		System.out.println("Input Coordinate Y");
		myThreeDPoint.coordY(sc.nextDouble());

		System.out.println("Input Coordinate Z");
		myThreeDPoint.coordZ(sc.nextDouble());


	}
}



The errors I got were:
C:\Users\BurneySoo\Documents\Mainz.java:8: error: cannot find symbol
threeDPoint myThreeDPoint=new threeDPoint();
^
symbol: class threeDPoint
location: class Mainz
C:\Users\BurneySoo\Documents\Mainz.java:8: error: cannot find symbol
threeDPoint myThreeDPoint=new threeDPoint();
^
symbol: class threeDPoint
location: class Mainz
C:\Users\BurneySoo\Documents\Mainz.java:14: error: cannot find symbol
myThreeDPoint.coordX(sc.nextDouble());
^
symbol: variable myThreeDPoint
location: class Mainz
C:\Users\BurneySoo\Documents\Mainz.java:17: error: cannot find symbol
myThreeDPoint.coordY(sc.nextDouble());
^
symbol: variable myThreeDPoint
location: class Mainz
C:\Users\BurneySoo\Documents\Mainz.java:20: error: cannot find symbol
myThreeDPoint.coordZ(sc.nextDouble());
^
symbol: variable myThreeDPoint
location: class Mainz
5 errors


When I change the
System.out.println("Input Coordinate X");
      myThreeDPoint.coordX(sc.nextDouble());



to just

System.out.println("Input Coordinate X");
coordX=sc.nextLine();



I only got these errors
C:\Users\BurneySoo\Documents\Mainz.java:8: error: cannot find symbol
threeDPoint myThreeDPoint=new threeDPoint();
^
symbol: class threeDPoint
location: class Mainz
C:\Users\BurneySoo\Documents\Mainz.java:8: error: cannot find symbol
threeDPoint myThreeDPoint=new threeDPoint();
^
symbol: class threeDPoint
location: class Mainz
2 errors


So, what am I doing wrong??

This post has been edited by nielsen: 16 March 2012 - 02:00 AM

Was This Post Helpful? 0
  • +
  • -

#12 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Re: Error:Cannot Find Symbol

Posted 16 March 2012 - 02:17 AM

Corrections! My last error post can be considered NULL and VOID. I did a few typo. The last error is the latest and correct error.

And somehow, with this new coding, it doesn't come out with an output that requires me to "Input Coordinate X".

I got this error at the Output panel:

--------------------Configuration: <Default>--------------------
Error: Could not find or load main class Mainz

Process completed.

Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Error:Cannot Find Symbol

Posted 16 March 2012 - 07:09 AM


	public double getCoord(double x, double y, double z){
		return coordX;
		return coordY;
		return coordZ;
	}
}


A method can only return one thing and usually getter() do not have parameter
your (x, y, z) are useless. What are they ? You want the value of the coordN variables hold into your object.
You might need

public double getCoordX() {
   return coordX;
}
public double getCoordY() {
   return coordY;
}
...


Was This Post Helpful? 0
  • +
  • -

#14 burneyjsoo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 12

Re: Error:Cannot Find Symbol

Posted 16 March 2012 - 05:21 PM

View Postpbl, on 16 March 2012 - 07:09 AM, said:


	public double getCoord(double x, double y, double z){
		return coordX;
		return coordY;
		return coordZ;
	}
}


A method can only return one thing and usually getter() do not have parameter
your (x, y, z) are useless. What are they ? You want the value of the coordN variables hold into your object.
You might need

public double getCoordX() {
   return coordX;
}
public double getCoordY() {
   return coordY;
}
...



Thank You for the help pbl. (nielsen was my colleague's account he introduced me to DIC. this is my own account now that I've registered.)

Anyway, I tried the ammendment that you sugested, but, it gave out even more errors than the previous coding. Maybe there's something else that I'm doing wrong?

The Errors:
C:\Users\BurneySoo\Documents\Main.java:14: error: cannot find symbol
myTreeDPoint.coordX(sc.nextLine());
^
symbol: variable myTreeDPoint
location: class Main
C:\Users\BurneySoo\Documents\Main.java:17: error: cannot find symbol
myTreeDPoint.coordY(sc.nextLine());
^
symbol: variable myTreeDPoint
location: class Main
C:\Users\BurneySoo\Documents\Main.java:20: error: cannot find symbol
myTreeDPoint.coordZ(sc.nextLine());
^
symbol: variable myTreeDPoint
location: class Main

C:\Users\BurneySoo\Documents\Main.java:22: error: non-static variable coordY cannot be referenced from a static context
myThreeDPoint.setCoord(coordX, coordY, coordZ);
^
C:\Users\BurneySoo\Documents\Main.java:22: error: non-static variable coordZ cannot be referenced from a static context
myThreeDPoint.setCoord(coordX, coordY, coordZ);
^
C:\Users\BurneySoo\Documents\Main.java:22: error: cannot find symbol
myThreeDPoint.setCoord(coordX, coordY, coordZ);
^
symbol: method setCoord(String,double,double)
location: variable myThreeDPoint of type ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:6: error: cannot find symbol
coordX=0;
^
symbol: variable coordX
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:7: error: cannot find symbol
coordY=0;
^
symbol: variable coordY
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:8: error: cannot find symbol
coordZ=0;
^
symbol: variable coordZ
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:12: error: cannot find symbol
coordX = x;
^
symbol: variable coordX
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:13: error: cannot find symbol
coordY = y;
^
symbol: variable coordY
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:14: error: cannot find symbol
coordZ = z;
^
symbol: variable coordZ
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:18: error: cannot find symbol
return coordX;
^
symbol: variable coordX
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:22: error: cannot find symbol
return coordY;
^
symbol: variable coordY
location: class ThreeDPoint
C:\Users\BurneySoo\Documents\ThreeDPoint.java:26: error: cannot find symbol
return coordZ;
^
symbol: variable coordZ
location: class ThreeDPoint
15 errors


And it still doesn't prompt me to input coordinates. but gave me this error instead. Is my Scanner util broken or something? :D

Error: Could not find or load main class Main

My current Coding:
ThreeDPoint.java
public class ThreeDPoint{

	private double x, y, z;

	public ThreeDPoint(){
		coordX=0;
		coordY=0;
		coordZ=0;
	}

	public ThreeDPoint(double x, double y, double z){
		coordX = x;
		coordY = y;
		coordZ = z;
	}

	public double getCoordX(){
		return coordX;
	}

    public double getCoordY(){
    	return coordY;
    }

    public double getCoordZ(){
    	return coordZ;
    }

}


Main.java
import java.util.Scanner;

public class Main {
	double coordX, coordY, coordZ;

	public static void main(String[] args){

	ThreeDPoint myThreeDPoint=new ThreeDPoint();

	Scanner sc=new Scanner(System.in);
	String coordX;

    System.out.println("Input Coordinate X: ");
	myTreeDPoint.coordX(sc.nextLine());

	System.out.println("Input Coordinate Y: ");
	myTreeDPoint.coordY(sc.nextLine());

	System.out.println("Input Coordinate Z: ");
	myTreeDPoint.coordZ(sc.nextLine());

    myThreeDPoint.setCoord(coordX, coordY, coordZ);
}

}

Was This Post Helpful? 0
  • +
  • -

#15 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Error:Cannot Find Symbol

Posted 16 March 2012 - 07:29 PM

Let's start with your ThreeDPoint class. First, your instance fields are named x, y, and z. Yet you try and access non-existent variables coordX, coordY, and coordZ in the constructors. Second, you don't define any setter methods in ThreeDPoint class, and you try to invoke them. Those are the causes of most of your errors.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2