Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2005, 05:05 AM
Authorized User
 
Join Date: Feb 2005
Location: chch, n/a, New Zealand.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Package problem

Help,

as per sample programs i have altered Point.java & Line.java.

Have got Point.java to compile okay but for whatever reason i cannot get Line.java to compile !!!

here are 3 of 11 errors (they appear to refer to a simlar fault)

Line.java:7: cannot resolve symbol
symbol : class Point
location: class geometry.Line
   public Line(final Point start, final Point end)
                     ^
Line.java:7: cannot resolve symbol
symbol : class Point
location: class geometry.Line
   public Line(final Point start, final Point end)
                                        ^
Line.java:15: cannot resolve symbol
symbol : class Point
location: class geometry.Line
    public Point intersects(final Line line1)

below is the 1st few lines of Point & Line

package geometry;
public class Point
{
   // create a point from coOrdinates
   public Point(double xVal, double yVal)
   {
     x = xVal;
     y = yVal;
   }


package geometry;

public class Line
{

 // create a line from 2 points
   public Line(final Point start, final Point end)
   {
     this.start = new Point(start);
     this.end = new Point(end);

any help on this would be great as I have hit a brick wall on these errors.
 
Old April 4th, 2005, 10:42 AM
Authorized User
 
Join Date: Apr 2005
Location: Arequipa, Arequipa, Peru.
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

compile in this way

javac -d . *.java
and i dont see the import package (in your .java)
with "package" your create the package but with "import" u make the reference to the other class

try it

 
Old April 5th, 2005, 02:46 AM
Authorized User
 
Join Date: Feb 2005
Location: chch, n/a, New Zealand.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will try your suggestion out tonite.

On pages 204 - 206 i am reading about packages and it said to alter 2 previous programs (Point.java & Line.java) to have the header pacakge Geometry etc etc.

At no point that i have readed seen anything about having an import for Geometry in the 2nd program (Line.java).

But in the test program (called TryPackage.java I DO ahve to import the package as

import Geometry.*
 
Old April 5th, 2005, 03:21 AM
Authorized User
 
Join Date: Feb 2005
Location: chch, n/a, New Zealand.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by DR POMPEII
 compile in this way

javac -d . *.java
and i dont see the import package (in your .java)
with "package" your create the package but with "import" u make the reference to the other class

try it

i tried your suggestion and i got another directory under geometry called geometry _but i did get the class files compiled.

Now if i moved them up into the original directory would it be okay ? (actually i will try it out).

Just re-reading page 204 it talks about the Classpath.

does this mean that in the trypackage.java if i have the following

2 source files in a sub directory called geometry and compile the test program with javac -CLASSPATH trypackage.java it will look into the geometry directory see that the class files are not there and so creates them (with no errors) and then proceed to comiple the trypackage.java code ???

well i tried it and it failed with the following errors.

javac -classpath geometry trypackage.java
trypackage.java:7: ';' expected
     double[] [] coords = { {1.0, 0.0}, {6.0, 0.0}, {6.0, 10.0}, {10.0, 10.0}, {10.0, -14.0}, {8.0, -14.0 } };
     ^
trypackage.java:11: illegal start of type
    for(int i = 0; i < coords.length; i++)
    ^
trypackage.java:12: <identifier> expected
        points[i] = new Point(coords[i] [0], coords[i] [1]);
                                                           ^
trypackage.java:19: illegal start of type
   for(int i=0; i< points.length; i++)
   ^
trypackage.java:21: <identifier> expected
       lines[i] = new line(points[i],points[i+1}); //create a line
                                                 ^
trypackage.java:22: <identifier> expected
       totallength += lines[i].length; // adds it's length
                                     ^
trypackage.java:23: <identifier> expected
       System.out.println("Line "+ (i+1)+' '+ lines[1] + " Length is " + lines[i].length());
                         ^
trypackage.java:27: 'class' or 'interface' expected
   System.out.println("/nTotal line length = " + totallength);
   ^
trypackage.java:28: 'class' or 'interface' expected
}
^
trypackage.java:29: 'class' or 'interface' expected
^
10 errors
 
Old April 5th, 2005, 04:10 AM
Authorized User
 
Join Date: Feb 2005
Location: chch, n/a, New Zealand.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well I have success!!!!

Via website http://www.kevinboone.com/classpath.html
(credit must goto another user by the name of bonnevillessei who had a simailar problem as i have)

using the command javac -classpath "" *.java it worked (ie no compile errors for Line.java).

Now with the trypackage.java i get the following errors.

javac trypackage.java
trypackage.java:7: ';' expected
     double[] [] coords = { {1.0, 0.0}, {6.0, 0.0}, {6.0, 10.0}, {10.0, 10.0}, {10.0, -14.0}, {8.0, -14.0 } };
     ^
trypackage.java:11: illegal start of type
    for(int i = 0; i < coords.length; i++)
    ^
trypackage.java:12: <identifier> expected
        points[i] = new Point(coords[i] [0], coords[i] [1]);
                                                           ^
trypackage.java:19: illegal start of type
   for(int i=0; i< points.length; i++)
   ^
trypackage.java:21: <identifier> expected
       lines[i] = new line(points[i],points[i+1}); //create a line
                                                 ^
trypackage.java:22: <identifier> expected
       totallength += lines[i].length; // adds it's length
                                     ^
trypackage.java:23: <identifier> expected
       System.out.println("Line "+ (i+1)+' '+ lines[1] + " Length is " + lines[i].length());
                         ^
trypackage.java:27: 'class' or 'interface' expected
   System.out.println("/nTotal line length = " + totallength);
   ^
trypackage.java:28: 'class' or 'interface' expected
}
^
trypackage.java:29: 'class' or 'interface' expected
^
10 errors

from source code of (1st 10 lines of code).


import geometry.*; // Import Point & Line classes that are in package geometry

public class trypackage
{

   public static void main(String[] args)
     double[] [] coords = { {1.0, 0.0}, {6.0, 0.0}, {6.0, 10.0}, {10.0, 10.0}, {10.0, -14.0}, {8.0, -14.0 } };

   //create an array of points and fill it with Point objects
   Point[] points = new Point[coords.length];


What is happening here now ???

any help from those more knowlegdable would be greatly appreciated.

dave.

ps thanks to DR POMPEll for his help.
 
Old April 5th, 2005, 01:49 PM
Authorized User
 
Join Date: Apr 2005
Location: Arequipa, Arequipa, Peru.
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Bro, well i use in this way, and always work!
for example if your package in some java is
package com.folder1.folder2;
("THAT IS NESSESARY DECLARED IN EACH *.JAVA" of your project)

compile how i told u,
javac -d . *.java

if u have correct syntax, u will see 3 nested folder (Your Package that u declared in each java file)
so, how execute

is not nesesary make a execution inside of the nested folder, try this way
(WARNING, your JAVAMAINCLASS must import your package to make the references to the other java class files ie: import com.folder1.folder.*;
)
> java com.folder1.folder2.NameJavaMainClass

thats all man,





DR POMPEII, THE PLACE OF THE OBLIVION OF GOD
 
Old April 5th, 2005, 01:56 PM
Authorized User
 
Join Date: Apr 2005
Location: Arequipa, Arequipa, Peru.
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The classpath option is only nesessary when you use a third party tools, how a .JAR (ie jar driver connection how mysql or cloudscape)

DR POMPEII, THE PLACE OF THE OBLIVION OF GOD
 
Old April 5th, 2005, 01:59 PM
Authorized User
 
Join Date: Apr 2005
Location: Arequipa, Arequipa, Peru.
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 lines[i] = new line(points[i],points[i+1}); //create a line

[i+1} <---? should be []

DR POMPEII, THE PLACE OF THE OBLIVION OF GOD
 
Old April 8th, 2005, 04:02 AM
Authorized User
 
Join Date: Feb 2005
Location: chch, n/a, New Zealand.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hope this does not solve my problem

Although I should have noticed it.

to date your suggestion on fixing my original problem was great but (because i am me i want the class files in with the source files).

Now the problem is with the program used to use the Point & Line class files as per my last post and error list.

again thanks for the help to date Dr.
 
Old April 11th, 2005, 03:35 AM
Authorized User
 
Join Date: Feb 2005
Location: chch, n/a, New Zealand.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My packages problem is NOW solved by me hope this helps someone else one day.

I had some coding errors that defied me (looking at the wood not the trees so to speak).

anyhow It has compiled and run.

Errors were....

trypackage.java:21: <identifier> expected
       lines[i] = new line(points[i],points[i+1}); //create a line

missing "}" and no r/h square bracket in for loop (see the "}" by the r/h bracket)
s(i+1});



trypackage.java:22: <identifier> expected
       totallength += lines[i].length; // adds it's length


lowercase "l" when uppercase was required

missing "()" in length.

Lines[i].length();


so it runs good :)




Similar Threads
Thread Thread Starter Forum Replies Last Post
Package Body Problem mindScape Oracle 0 March 21st, 2007 12:43 PM
package and import problem Prince Java Basics 0 May 29th, 2006 06:49 AM
Package Problem (ActiveX) bmains SQL Server DTS 4 May 31st, 2005 08:35 AM
Package Deployment Problem bveerendrakumar Pro VB 6 8 March 16th, 2005 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.