4 Replies - 351 Views - Last Post: 03 May 2013 - 07:13 PM Rate Topic: -----

#1 ashley.h  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-May 13

Error Cannot find symbol and driver class is not linking with others

Posted 03 May 2013 - 01:59 PM

You will need to check that the four parameters entered by the user are blank, so you will do the same as you did before but four times.

To Identify if the User Presses <enter>

You have written a JAVA program that creates a CD object with four instance variables, along with a CDException.java class that helps you validate this input. So far you have been using these classes with my driver classes. Now it is time for you to create a real driver class that will implement an ArrayList of CD objects.
Here is a list of requirements for your LAST program

Read the artist name from the user
Read the album name from the user
Read the number of items in stock
Read the price of the album
Your program should continue to read the CD information from the user until all the entries from
the user for all the fields are blank.
Your program will then print the list all the "valid" CDs entered by the user.

I keep getting errors like this

CDStore.java:12: error: cannot find symbol
	 Disk d;
	 ^
  symbol:   class Disk
  location: class CDStore

CDStore.java:61: error: cannot find symbol
		catch(CDException cde){
		      ^
  symbol:   class CDException
  location: class CDStore

CDStore.java:67: error: cannot find symbol
	for(int i = 0; i < CDShelf.length( ); i++){
	                          ^
  symbol:   method length()
  location: variable CDShelf of type ArrayList

CDStore.java:68: error: cannot find symbol
		d = (Disk)(CD.get(i));
		     ^
  symbol:   class Disk
  location: class CDStore

CDStore.java:68: error: cannot find symbol
		d = (Disk)(CD.get(i));
		             ^
  symbol:   method get(int)
  location: class CD
5 errors


And it looks like that my driver class here is not linking with my exception class. Any help would be much appreciated on how to get rid of these errors!

import java.util.*;
import java.text.*;

public class CDStore{
   public static void main (String[ ] arg)throws Exception{
	 
	 String sArtist = "";
	 String sAlbum = "";
	 int inStock = 0;
	 double dPrice = 0;
	 String C = "";
	 Disk d;
	 int count = 0;
	 boolean exit = false;
	 
	 
	 Scanner reader = new Scanner (System.in);
	 ArrayList CDShelf = new ArrayList( );
	 
       do{
		try{
		   System.out.print("What is the Artist name: ");
		   sArtist = reader.nextLine( );
		   reader = new Scanner(System.in);
			
		   if(sArtist.length( ) < 1){
                     exit = true;
                   }
			
		   System.out.print("What is the album name: ");
		   sAlbum = reader.nextLine( );
		   reader = new Scanner(System.in);
			
		   if(sAlbum.length( ) < 1){
                       exit = true;
                   }
		   System.out.print("What is the price: ");
		   dPrice = reader.nextDouble( );
		   reader = new Scanner(System.in);
			
		   if(dPrice < 1){
                      exit = true;
                   }
		   System.out.print("How many are in stock: ");
		   inStock = reader.nextInt( );
		   reader = new Scanner(System.in);
		   d = new CD(sArtist, sAlbum, dPrice, inStock);
			
		   if(inStock < 1){
                      exit = true;
                   }
			
		      CD.add(d);
		      count++;
		      System.out.println(C.toString( ));
		      System.out.println("=============================");
		  }
		  catch(InputMismatchException ime){
		     System.out.println("You didnt do it");
		  }
		catch(CDException cde){
			System.out.println(cde.getMessage( ));
		}
	}while(count < 3);
	
	System.out.println("This is what you entered");
	for(int i = 0; i < CDShelf.length( ); i++){
		d = (Disk)(CD.get(i));
		System.out.println(d.toString( ));
	}
	}
}

This post has been edited by GregBrannon: 03 May 2013 - 03:09 PM
Reason for edit:: Put stack trace in code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Error Cannot find symbol and driver class is not linking with others

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2194
  • View blog
  • Posts: 5,222
  • Joined: 10-September 10

Re: Error Cannot find symbol and driver class is not linking with others

Posted 03 May 2013 - 03:17 PM

I put the stack trace (error messages) in code tags so that spacing would be preserved, and we can see where the carets, '^' are pointing.

"cannot find symbol" errors mean the compiler has encountered a name (variable, method, class (object), etc.) that it doesn't recognize, because it hasn't been declared at all or not within the scope of its current usage. In this case, the compiler doesn't know what Disk, CDException, and methods length() and get() are, plus any others I missed.

Think about what I've said the error means, and try to fix them all yourself.

In order for this class to see your CDException class, the class needs to be "visible." It can be a non-public, top-level class in the same file, a nested class, a public class in another file in the same directory, or a public class in another file in the same project. There are many ways to do it right.
Was This Post Helpful? 1
  • +
  • -

#3 ashley.h  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-May 13

Re: Error Cannot find symbol and driver class is not linking with others

Posted 03 May 2013 - 03:39 PM

Ohhhkay. I just re-saved my files in another file, I suppose I had other file names with the same name which explains why they were not linking all three classes together. So that fixed the CDException part! Thank YOUU!

And now to fix the cannot find symbols...
Was This Post Helpful? 0
  • +
  • -

#4 ashley.h  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-May 13

Re: Error Cannot find symbol and driver class is not linking with others

Posted 03 May 2013 - 04:46 PM

Ok. Now I have one error left. So far with my code I have this

import java.util.*;
import java.text.*;
public class CDStore{
   public static void main (String[ ] args)throws Exception{
	 
	 	String sArtist = "";
	 	String sAlbum = "";
		int inStock = 0;
		double dPrice = 0;
	 	String C = "";
		String Disk;
		String d = "";
		int count = 0;
	 	boolean exit = false;
	 
	 	Scanner reader = new Scanner (System.in);
	 	ArrayList CDShelf = new ArrayList( );
		 
   	do{
	   	try{
		   	System.out.print("What is the Artist name: ");
				sArtist = reader.nextLine( );
				reader = new Scanner(System.in);
				if(sArtist.length( ) < 1){
               exit = true;
         	}
				CDShelf.add(sArtist);
				
				System.out.print("What is the album name: ");
				sAlbum = reader.nextLine( );
				reader = new Scanner(System.in);
				if(sAlbum.length( ) < 1){
               exit = true;
        		}
				CDShelf.add(sAlbum);
				
				System.out.print("What is the price: ");
				dPrice = reader.nextDouble( );
				reader = new Scanner(System.in);
				
				if(dPrice < 1){
               exit = true;
         	}
				Double dPrices = new Double(dPrice);
				CDShelf.add(dPrices);
				
				System.out.print("How many are in stock: ");
				inStock = reader.nextInt( );
				reader = new Scanner(System.in);
				
				if(inStock < 1){
               exit = true;
         	}
				Integer iStock = new Integer(inStock);
				CDShelf.add(iStock);
				CD cd1 = new CD(sArtist, sAlbum, dPrices, iStock);

			}
			catch(InputMismatchException ime){
				System.out.println("You didnt do it");
			}
			catch(CDException cde){
				System.out.println(cde.getMessage( ));
			}
			
		}while(count < 4);
			System.out.println("This is what you entered");
			for(int i = 0; i < CDShelf.size( ); i++){
				d = (CD)(CDShelf.get(i));
				System.out.println(d.toString( ));
			}
			
			
			
	}
}


and my only error being

CDStore.java:69: error: incompatible types
d = (CD)(CDShelf.get(i));
^
required: String
found: CD

What do you suggest I do to fix it?
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

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

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Error Cannot find symbol and driver class is not linking with others

Posted 03 May 2013 - 07:13 PM

First, since JRE 5 (and we are at 7) ArrayList are generic so

ArrayList CDShelf = new ArrayList( );
should be
ArrayList<Object> CDShelf = new ArrayList<Object>( );

but you are adding to this ArrayList of different king ... I really wonder how you keep track of them

CDShelf.add(sArtist); // which is a String
CDShelf.add(sAlbum); // which is a String
CDShelf.add(dPrices); // which is a Double
CDShelf.add(iStock); // which is an Integer

for the last error

String d = "";
d = (CD)(CDShelf.get(i));

d is a String, you can't put a CD into it

But really really not a bad idea to put Object of different tpe in the same ArayList
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1