willisoften Posted February 18, 2003 Report Share Posted February 18, 2003 Sun SDK 1.4.1 Importing packages aren't working. The package root directory is being found (it's in the class directory) and according to Javac's verbose output the package is being loaded. Trouble is although application classes compile OK they don't work properly. The programs are very simple import uuInOut; class Testy { public static void main(String [] args) { int x; System.out.println("Enter number "); x = uuInOut.ReadInt(); System.out.println("Success!" +x); } } Javac Output shows : [loading ./uupack/uuInOut.class] The code from this package isn't an issue it works under Windows and with SDK 1.3 under linux any ideas? I have searched the internet religiously for 3 days trying to find out about this so far all i've got are a bundle of unhappy 1.4 users.. Quote Link to comment Share on other sites More sharing options...
phunni Posted February 21, 2003 Report Share Posted February 21, 2003 Could it be a package problem? Is uuInOut in a package? What happens if you declare both classes as public? These are just initial thoughts - and may be red herrings. BTW uuInOut should be called UuInOut if you want to be a good java boy(girl?) :wink: Quote Link to comment Share on other sites More sharing options...
willisoften Posted February 21, 2003 Author Report Share Posted February 21, 2003 Hi, thanks that was at least a partial success. The .java files reliant on uuInOut do compile when it's declared as public but the program only accepts the first input then sits there doing nothing. It doesn't come up with the next user prompt and it doesn't terminate. maybe the SDK is fussier under Linux than windows? Quote Link to comment Share on other sites More sharing options...
phunni Posted February 21, 2003 Report Share Posted February 21, 2003 The compiler and runtime should be fairly standard, regardless of platform - although there are some differences and it could just be a problem with the linux version. I would suggest that this is a last resort diagnosis though. If you could fnd out if it's ok to show me the source - via private message if you'd prefer - we might be able to figure this out further Quote Link to comment Share on other sites More sharing options...
willisoften Posted February 21, 2003 Author Report Share Posted February 21, 2003 Thanks for the offer. It may be the way I've done things I'm trying to find a complete beginning to end tutorial on creating and using packages. I intended to ask my lecturer today if it was ok to publish his code or pass it on but I didn't see him. I'll let you know. Quote Link to comment Share on other sites More sharing options...
phunni Posted February 22, 2003 Report Share Posted February 22, 2003 If I get a chance later - I'll put together a simple step by step guide to packages in Java - it's pretty straightforward Quote Link to comment Share on other sites More sharing options...
phunni Posted February 22, 2003 Report Share Posted February 22, 2003 Hope this isn't too basic - I'm trying to assume no knowledge OK - here goes: (deep breath) There are two steps to putting a class into a package - I'll use the example of a simple HelloWorld class. 1) Create the directory structire for a package - so, if we want org.mandrakeusers.HelloWorld then we create an org directory containing a mandrakeusers directory containing HelloWorld.class Note: We often use domain names in reverse to guaruntee uniqueness of packages 2) We need to put a package decalration at the very top of our class so: package org.mandrakeusers; public class HelloWorld { ... } Note: package declarations MUST be at the top of the class - only comments can go above HelloWorld is now in a package. You can have as many classes in one package as you like. In order to use HelloWorld in aonther class, we have two options: 1) simply refer to it by it's full package name - e.g.: org.mandrakeusers.HelloWorld hello = new org.mandrakeusers.HelloWorld(); 2) import it and then refer to it without the package structure: import org.mandrakeusers.HelloWorld; public class Whatever{ ... HelloWorld hello = new HelloWorld(); ... } Note that you can use wildcards to import packages - although they only import the classes in the specified directory so: import org.mandrakeusers.* will NOT import any classes in org.mandrakusers.otherproject. In order for the class to be found the org directory - NOT the class file - needs to be directly on the classpath. So if my classpath = /home/user/MyClasses then the structure will be: /home/user/MyClasses/org/mandrakeusers.HelloWorld.class Final thing to mention is privacy declarations: private = only visible to this class public = visible to all classes protected = visible to subclasses and classes in the same package default = visible to classes in the same package I realise that I probably should have put this on the web somewhererr and just linked to it - but, frankly, I couldn't be bothered :) Any questions - or anything unclear, then let me know Phew! Quote Link to comment Share on other sites More sharing options...
willisoften Posted February 23, 2003 Author Report Share Posted February 23, 2003 Thanks I'll try this as soon as possible! Quote Link to comment Share on other sites More sharing options...
willisoften Posted February 25, 2003 Author Report Share Posted February 25, 2003 Phunni I've been pretty careful and thorough about this over the last couple of days and I still haven't got it working! I haven't finished trying but I've got to spend some time preparing for an exam:) I must be doing something wrong as it appears to be working under Windows/jdk1.3 when I import an unpackaged class. It's me! Thanks for bothering I appreciate your efforts. I'll be back! Quote Link to comment Share on other sites More sharing options...
phunni Posted February 25, 2003 Report Share Posted February 25, 2003 Your import statement just imports uuInOut - but it should be fully package qualified - i.e.: import uuPack.uuInOut; Have you tried that? It wouldcertainly cause some problems if you haven't :wink: Quote Link to comment Share on other sites More sharing options...
phunni Posted February 25, 2003 Report Share Posted February 25, 2003 Phunni I've been pretty careful and thorough about this over the last couple of days and I still haven't got it working! I haven't finished trying but I've got to spend some time preparing for an exam:) I must be doing something wrong as it appears to be working under Windows/jdk1.3 when I import an unpackaged class. It's me! Thanks for bothering I appreciate your efforts. I'll be back! Importing an upackaged class would be fine - but uuInOut is in a package - or it's declared to be Quote Link to comment Share on other sites More sharing options...
willisoften Posted February 25, 2003 Author Report Share Posted February 25, 2003 I've done everything you've suggested but it still not working! What you say is working fine under Windows. Under Mandrake but it either can't find it or else compiles fine but doesn't work properly when run. (This to me is the really confusing bit) Quote Link to comment Share on other sites More sharing options...
phunni Posted February 26, 2003 Report Share Posted February 26, 2003 Hmmmm... would you be able to zip all the code up and send it to me? I think I'll need to actually try this for myself. Obviously I won't redistribute any code. Quote Link to comment Share on other sites More sharing options...
willisoften Posted February 27, 2003 Author Report Share Posted February 27, 2003 I'll send you what I can when I get a breathing space. I've been informed that the problem might be the difference between carriage return in Windows and Linux so when I run the application it just sits there waiting for the enter key to be pressed after the first input value is entered. I haven't tried yet but I'm told that pressing Ctrl and M instead should solve the problem. Check you personal messages. Thanks again Will Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.