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 4 of 4

Thread: Writing a class - class not found

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Writing a class - class not found

    I am studying defining a class in Java Programming.

    I am having an issue with whenever I try to write a class, even one directly from the book, NetBeans tells me it can't find the class.

    The code looks correct but it won't run. i don't understand what I am doing wrong.

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package auto;
     
    /* Auto class, Version 2
     Anderson, Franceschi
     */
    public class Auto
    {
    	// instance variables
    	private String model;	//  model of auto
    	private int milesDriven;	//  number of miles driven
    	private double gallonsOfGas; //  number of gallons of gas
     
    	// Default constructor:
    	//  initializes model to "unknown";
    	//  milesDriven is autoinitialized to 0
    	//        and gallonsOfGas to 0.0
    	public Auto( )
    	{
            model = "unknown";
    	}
     
    	// Overloaded constructor:
    	// allows client to set beginning values for
    	//   model, milesDriven, and gallonsOfGas.
    	public Auto( String startModel,
    	int startMilesDriven,
    	double startGallonsOfGas )
    	{
            model = startModel;
     
    	// validate startMilesDriven parameter
    	if ( startMilesDriven >= 0 )
               milesDriven = startMilesDriven;
    	else
    	{
    	System.err.println( "Miles driven is negative." );
    	System.err.println( "Value set to 0." );
    	}
     
    	// validate startGallonsOfGas parameter
    	if ( startGallonsOfGas >= 0.0 )
               gallonsOfGas = startGallonsOfGas;
    	else
    	{
    	System.err.println( "Gallons of gas is negative" );
    	System.err.println( "Value set to 0.0." );
    	}
    	}
     
    	// Accessor method:
    	// returns current value of model
    	public String getModel( )
    	{
    	return model;
    	}
     
    	// Accessor method:
    	// returns current value of milesDriven
    	public int getMilesDriven( )
    	{
    	return milesDriven;
    	}
     
    	// Accessor method:
    	//  returns current value of gallonsOfGas
    	public double getGallonsOfGas( )
    	{
    	return gallonsOfGas;
    	}
    }:confused:


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Writing a class - class not found

    Post the exact error message, copied and pasted from what appears at your end. What's the name of the source file?

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Writing a class - class not found

    Quote Originally Posted by GregBrannon View Post
    Post the exact error message, copied and pasted from what appears at your end. What's the name of the source file?
    I figured out what i had to do. it has to be a file all until itself within the program. I got confused. now it works correctly

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Writing a class - class not found

    Okay. Good job figuring it out.

  5. The Following User Says Thank You to GregBrannon For This Useful Post:

    nepperso (November 23rd, 2013)

Similar Threads

  1. Replies: 4
    Last Post: October 15th, 2013, 04:33 AM
  2. File not found in class path
    By Jeff.Steinkamp in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: January 1st, 2013, 08:37 PM
  3. class not found
    By aki in forum Java Applets
    Replies: 1
    Last Post: May 23rd, 2012, 06:50 AM
  4. What is wrong with this code class not found
    By newbieJava in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 19th, 2011, 06:39 PM
  5. Main Class Not Found Problem
    By shadow in forum Java Theory & Questions
    Replies: 3
    Last Post: September 29th, 2009, 09:42 AM

Tags for this Thread