Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: cannot find symbol Error

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default cannot find symbol Error

    Can someone help me with debugging this error?
    This is the error Im getting but I do not know why.

    SharedBufferTest.java:16: cannot find symbol
    symbol : constructor Producer(Buffer)
    location: class Producer
    Producer producer = new Producer( sharedLocation );
    ^
    SharedBufferTest.java:17: cannot find symbol
    symbol : constructor Consumer(Buffer)
    location: class Consumer
    Consumer consumer = new Consumer( sharedLocation );

    Here is the code for SharedBufferTest.java
    public class SharedBufferTest {
    	public static void main( String [] args)
    	{
     
    	Buffer sharedLocation = new UnsynchronizedBuffer();
     
     
    	Producer producer = new Producer( sharedLocation );
    	Consumer consumer = new Consumer( sharedLocation );
    	Semaphore valueProduced=new Semaphore(0);
    	Semaphore valueConsumed = new Semaphore(1);
     
    		producer.start();
    		consumer.start();
     
    	}
    }

    Here is the Producer code
    public class Producer extends Thread{
    	private Buffer sharedLocation;
    	private Semaphore valueProduced;
    	private Semaphore valueConsumed;
     
    	public Producer (Buffer shared, Semaphore valueP, Semaphore valueC) {
    		super("Producer");
    		sharedLocation = shared;
    		valueProduced = valueP;
    		valueConsumed = valueC;
    	}
     
    	public void run() {
    		for (int count = 1; count <= 4; count++){
    			//try {
    				//Thread.sleep((int) (Math.random() * 3001));
    				valueConsumed.P();
    				//check to see if the value has been consumed P( valueConsumed );
    				sharedLocation.set(count);
    				//let consumer thread know it can consume the value
    				valueProduced.V();
    			//}
    			//catch (InterruptedException exception) {
    				//exception.printStackTrace();
    			//}
    		}
    		System.err.println(getName() + " done producing.");
    	}
    }

    Here is the Consumer code
    public class Consumer extends Thread{
    	private Buffer sharedLocation;
    	private Semaphore valueProduced;
    	private Semaphore valueConsumed;
     
    	public Consumer (Buffer shared, Semaphore valueP, Semaphore valueC) {
    		super("Consumer");
    		sharedLocation = shared;
    		valueProduced = valueP;
    		valueConsumed = valueC;
     
    	}
    	public void run() {
    		int sum = 0;
    		for (int count=1; count<=4; count++) {
    			//try{
    				//how it shouldve worked:
    				//sharedLocation.get()=null; check to see if the buffer is empty
    				//if 
    				//Thread.sleep((int) (Math.random() * 3001));
    				valueProduced.P();
    				sum += sharedLocation.get();
    				valueConsumed.V();
    			//}
    			//catch (InterruptedException exception) {
    				//exception.printStackTrace();
    			//}
    		}
    		System.err.println(getName() + " done consuming. and sum= " + sum);
    	}
    }
    Last edited by bananasplitkids; March 8th, 2010 at 11:54 AM. Reason: left out code


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cannot find symbol Error

    So I recompiled the program again and now Im getting these errors:

    cannot find symbol
    symbol : class Buffer
    location: class SharedBufferTest
    Buffer sharedLocation = new UnsynchronizedBuffer();
    ^
    ./UnsynchronizedBuffer.java:9: cannot find symbol
    symbol: class Buffer
    public class UnsynchronizedBuffer implements Buffer {
    ^
    ./Producer.java:10: cannot find symbol
    symbol : class Buffer
    location: class Producer
    private Buffer sharedLocation;
    ^
    ./Producer.java:14: cannot find symbol
    symbol : class Buffer
    location: class Producer
    public Producer (Buffer shared, Semaphore valueP, Semaphore valueC) {
    ^
    SharedBufferTest.java:16: internal error; cannot instantiate Producer.<init> at Producer to ()
    Producer producer = new Producer( sharedLocation );
    ^
    ./Consumer.java:10: cannot find symbol
    symbol : class Buffer
    location: class Consumer
    private Buffer sharedLocation;
    ^
    ./Consumer.java:14: cannot find symbol
    symbol : class Buffer
    location: class Consumer
    public Consumer (Buffer shared, Semaphore valueP, Semaphore valueC) {
    ^
    SharedBufferTest.java:17: internal error; cannot instantiate Consumer.<init> at Consumer to ()
    Consumer consumer = new Consumer( sharedLocation );
    ^
    ./Consumer.java:30: inconvertible types
    found : <nulltype>
    required: int
    sum += sharedLocation.get();

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: cannot find symbol Error

    Double posted and answered on the Oracle forums.
    New To Java - cannot find symbol

    db

Similar Threads

  1. Why the compiler can not find the symbol?
    By AlicNewbie in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2010, 08:16 PM
  2. cannot find symbol - method
    By kyuss in forum Object Oriented Programming
    Replies: 2
    Last Post: December 7th, 2009, 01:01 PM
  3. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  4. cannot find symbol variable radius?
    By noobish in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 4th, 2009, 10:29 AM
  5. Replies: 5
    Last Post: September 19th, 2009, 06:48 AM