Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34903 > unrolled thread
| Started by | Steve Graham <solitary.wanderer52@gmail.com> |
|---|---|
| First post | 2016-07-15 11:54 -0700 |
| Last post | 2016-07-15 15:15 -0400 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
Error in build Steve Graham <solitary.wanderer52@gmail.com> - 2016-07-15 11:54 -0700
Re: Error in build Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-15 15:15 -0400
| From | Steve Graham <solitary.wanderer52@gmail.com> |
|---|---|
| Date | 2016-07-15 11:54 -0700 |
| Subject | Error in build |
| Message-ID | <746d328e-d360-4268-ace5-07a9931955ae@googlegroups.com> |
While trying to build, I got the following error. I have tried changing a few things. The classes are adapted from Oracle's Java tutorial. I would think that the Bicycle class would be "pulled in" via the common package statement.
Any help would be appreciated.
Steve
---
Error while trying to build Bicycle Demo:
C:\Users\TheUser \Documents\NetBeansProjects\Bicycle Demo\src\bicycle\demo\BicycleDemo.java:19: error: cannot find symbol
Bicycle bike1 = new Bicycle();
symbol: class Bicycle
location: class BicycleDemo
---
Bicycle:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Bicycle;
/**
*
* @author User-LibertyITS
*/
class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;
void changeCadence(int newValue) {
cadence = newValue;
}
void changeGear(int newValue) {
gear = newValue;
}
void speedUp(int increment) {
speed = speed + increment;
}
void applyBrakes(int decrement) {
speed = speed - decrement;
}
void printStates() {
System.out.println("cadence:" +
cadence + " speed:" +
speed + " gear:" + gear);
}
}
Bicycle Demo:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Bicycle;
/**
*
* @author User-LibertyITS
*/
class BicycleDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Create two different
// Bicycle objects
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();
// Invoke methods on
// those objects
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();
bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
}
}
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-07-15 15:15 -0400 |
| Message-ID | <nmbcp1$v55$1@dont-email.me> |
| In reply to | #34903 |
On 7/15/2016 2:54 PM, Steve Graham wrote:
> While trying to build, I got the following error. I have tried changing a few things. The classes are adapted from Oracle's Java tutorial. I would think that the Bicycle class would be "pulled in" via the common package statement.
> [... see up-thread for code ...]
>
> Error while trying to build Bicycle Demo:
>
> C:\Users\TheUser \Documents\NetBeansProjects\Bicycle Demo\src\bicycle\demo\BicycleDemo.java:19: error: cannot find symbol
> Bicycle bike1 = new Bicycle();
> symbol: class Bicycle
> location: class BicycleDemo
The way the source files are arranged in directories must mimic the
package structure. Because both files are in a package named "Bicycle"
(aside: not a good name for a package), both should be in a directory
named "Bicycle" as well. As it is, they appear to be in a directory
named "demo" (aside: beneath the very strange looking "TheUserBLANK").
When asked to compile ...\demo\BicycleDemo.java, Java has no trouble
finding the file -- you've given the location on the javac command line.
But when it then tries to find the "Bicycle" class, it looks for
"...\demo\Bicycle\Bicycle.class" or "...\demo\Bicycle\Bicycle.java",
and (of course) fails to find either.
You appear to be using NetBeans. When you tell NetBeans to create
a new package named "Bicycle", it will create "...\src\Bicycle", and
that directory is where "Bicycle.java" and "BicycleDemo.java" should
live.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web