Getting started with simple packages and it's not working

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 529 Views - Last Post: 25 April 2013 - 05:01 PM Rate Topic: -----

#1 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Getting started with simple packages and it's not working

Posted 25 April 2013 - 02:28 PM

Hi.

I'm trying to do the sample package exercise in the Thinking in Java book by Bruce Eckel.

I have 3 files.

//List.java
package simple;

public class List{
    public List(){
    System.out.println("net.
mindview.simple.List");
}
}


//Vector.java
package simple;

public class Vector{
public Vector(){
System.out.println("net.mindview.simple.Vector");
}
}

//LibTest.java
import simple.*;
public class LibTest{
    public static void main(String[] args) {
    Vector v = new Vector();
    List l = new List();
}
}



I compile Vector and List, they're in the package folder. Path to it is C:\Learning Java\AccessControl\package

When I try to run LibTest.java, I get

error: cannot access Vector
Vector v = new Vector();
^

bad class file: \Vector.class
class file contains wrong class: simple.vector
Please remove or make sure it appears in the correct directory of the classpath.

I'm using the Thinking in Java Book and http://docs.oracle.c...e/packages.html

Thank you for your time.

Is This A Good Question/Topic? 0
  • +

Replies To: Getting started with simple packages and it's not working

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,730
  • Joined: 20-September 08

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 02:33 PM

Quote

I compile Vector and List
How? (Show command line and prompt if using command line)
Was This Post Helpful? 0
  • +
  • -

#3 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 02:36 PM

View Postg00se, on 25 April 2013 - 02:33 PM, said:

Quote

I compile Vector and List
How? (Show command line and prompt if using command line)


javac -d . Vector.java
javac -d . List.java

and creates them in the simple folder, which is the name of the package.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,730
  • Joined: 20-September 08

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 02:51 PM

Please post the output of the following three commands

dir Vector.java


dir /b simple


type Vector.java

This post has been edited by g00se: 25 April 2013 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

#5 jjh08  Icon User is offline

  • D.I.C Head

Reputation: 55
  • View blog
  • Posts: 198
  • Joined: 13-July 12

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 02:52 PM

Quote

I compile Vector and List, they're in the package folder.

According to your code, the name of the package is simple so there should be a directory named 'simple' right?
Because you can't declare a package named 'package'.
Also, you say the path is:

Quote

C:\Learning Java\AccessControl\package

Shouldn't it be:
C:\Learning Java\AccessControl\simple
Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#6 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 02:54 PM

View Postjjh08, on 25 April 2013 - 02:52 PM, said:

Quote

I compile Vector and List, they're in the package folder.

According to your code, the name of the package is simple so there should be a directory named 'simple' right?
Because you can't declare a package named 'package'.
Also, you say the path is:

Quote

C:\Learning Java\AccessControl\package

Shouldn't it be:
C:\Learning Java\AccessControl\simple
Hope this helps :)/>

Yeah, the package folder is named simple. packages are on my mind and I got the wording mixed up.
Was This Post Helpful? 0
  • +
  • -

#7 jjh08  Icon User is offline

  • D.I.C Head

Reputation: 55
  • View blog
  • Posts: 198
  • Joined: 13-July 12

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 02:59 PM

View PostCrewd, on 25 April 2013 - 02:54 PM, said:

Yeah, the package folder is named simple. packages are on my mind and I got the wording mixed up.

Ok I see. Go try what g00se said in post #4. See if that helps because I haven't compiled from the command line in quite a while :P
Was This Post Helpful? 0
  • +
  • -

#8 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 03:03 PM

View Postg00se, on 25 April 2013 - 02:51 PM, said:

Please post the output of the following three commands

dir Vector.java


c:\Learning Java\AccessControl\simple

1 file Vector.java 131 bytes

dir /b simple


c:\Learning Java\AccessControl

List.class
List.Java
Vector.class
Vector.java

type Vector.java


c:\Learning Java\AccessControl\simple

package simple;

public class Vector{
public Vector();
System.out.println("net.mindview.simple.Vector");
}
}


Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,730
  • Joined: 20-September 08

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 03:08 PM

Quote

c:\Learning Java\AccessControl

List.class
List.Java
Vector.class
Vector.java

LibTest.java should be in there - where is it?
Was This Post Helpful? 0
  • +
  • -

#10 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 03:24 PM

View Postg00se, on 25 April 2013 - 03:08 PM, said:

Quote

c:\Learning Java\AccessControl

List.class
List.Java
Vector.class
Vector.java

LibTest.java should be in there - where is it?


I thought if it's importing the whole package, it doesn't have to be in the same folder.

I just placed the LibTest.java in the folder to see if it works, and it gets the same errors.
Was This Post Helpful? 0
  • +
  • -

#11 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,730
  • Joined: 20-September 08

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 03:27 PM

c:\Learning Java\AccessControl\>del *.class

c:\Learning Java\AccessControl\>javac -d . *.java

c:\Learning Java\AccessControl\>java LibTest

Was This Post Helpful? 0
  • +
  • -

#12 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 03:38 PM

View Postg00se, on 25 April 2013 - 03:27 PM, said:

c:\Learning Java\AccessControl\>del *.class

c:\Learning Java\AccessControl\>javac -d . *.java

c:\Learning Java\AccessControl\>java LibTest


It does everything up to c:\Learning Java\AccessControl\>java LibTest, and gives me a could not find or load main class LibTest.
Was This Post Helpful? 0
  • +
  • -

#13 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,730
  • Joined: 20-September 08

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 03:42 PM

You told me you put it in there - obviously not - or you took it out again ;)/>

Quote

I just placed the LibTest.java in the folder to see if it works

This post has been edited by g00se: 25 April 2013 - 03:43 PM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#14 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 04:04 PM

View Postg00se, on 25 April 2013 - 03:42 PM, said:

You told me you put it in there - obviously not - or you took it out again ;)/>/>

Quote

I just placed the LibTest.java in the folder to see if it works


It's still in the simple folder.
Was This Post Helpful? 0
  • +
  • -

#15 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,730
  • Joined: 20-September 08

Re: Getting started with simple packages and it's not working

Posted 25 April 2013 - 04:09 PM

c:\Learning Java\AccessControl\>move simple\LibTest.java .

c:\Learning Java\AccessControl\>del *.class

c:\Learning Java\AccessControl\>javac -d . *.java

c:\Learning Java\AccessControl\>java LibTest


Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2