Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes moved class files into new package, application stopped working... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "moved class files into new package, application stopped working..." Watch "moved class files into new package, application stopped working..." New topic
Author

moved class files into new package, application stopped working...

Randy Smith
Ranch Hand

Joined: Mar 27, 2011
Posts: 44
Hi guys, I'm using eclipse, I've created a new project call part2 and a new package (a). copy classfiles from part1 into part2's package a and add

"package a;" to the first line of all class files but the things still doesn't work properly, some class file cannot access other class files. what should I check for?
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 71

You should check for broken imports, since you moved your sources to a different package.
You can check the compilation errors easily by viewing the Errors tab.

Cheers
Claudiu
Randy Smith
Ranch Hand

Joined: Mar 27, 2011
Posts: 44
Claudiu Chelemen wrote:You should check for broken imports, since you moved your sources to a different package.
You can check the compilation errors easily by viewing the Errors tab.

Cheers
Claudiu


everything compiled without issue, but certain methods doesn't work anymore. for example, static objects created are no longer accessible. that is very strange... those are marked as public, so it doesn't make any sense
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Randy Smith wrote: doesn't work anymore.

Are you seeing any Exceptions? Can you try deleting all previously created class files and then re-compile and run?
Randy Smith
Ranch Hand

Joined: Mar 27, 2011
Posts: 44
John Jai wrote:
Randy Smith wrote: doesn't work anymore.

Are you seeing any Exceptions? Can you try deleting all previously created class files and then re-compile and run?


i'm not getting any exceptions, but methods ..e.g. class 1 that call methods in class 2 is use to work, now class 2 methods are not returning anything.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Can you try to post some code of Class1 and Class2?
Randy Smith
Ranch Hand

Joined: Mar 27, 2011
Posts: 44
Ok...I found out what is wrong now..

certain method execution are dependent on the name of the class, so if there is a package, it must be renamed into this formate package.classname
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Sounds like iffy design. If possible it's better to compare to class literals. So not but Can you show us the pieces of code that's using class names to perhaps help you find alternatives?

Also, Eclipse allows you to move classes from one package to another while updating references, both in code and in comments. I'm sure Strings can be updated as well. Just right-click, select Refactor, Move.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Randy Smith
Ranch Hand

Joined: Mar 27, 2011
Posts: 44
Rob Spoor wrote:Sounds like iffy design. If possible it's better to compare to class literals. So not but Can you show us the pieces of code that's using class names to perhaps help you find alternatives?

Also, Eclipse allows you to move classes from one package to another while updating references, both in code and in comments. I'm sure Strings can be updated as well. Just right-click, select Refactor, Move.


Yes I did just that, i realise that it's bad design, and I'll get penalised for that. I'm too far out to fix that. I'm working on an inventory system and I was thinking having a massive arraylist that hold different kinds of item would be better than having to manage several arraylists that each hold just one kind of item. I wrote a a base class and extended subclasses. One arraylist defined as base class and I dumped eveything inside.

man... i'm so wrong, i had to write code here and there to keep things together. Any minor modifications or type-po breaks the code.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
Randy Smith wrote: . . . Any minor modifications or type-po breaks the code.
That is called tight coupling. If you depend on the name of the class, or its package, you are tightly coupling the implementation of one part of the code to the implementation of another. And you have seen how easily one can break such code.

I would have thought that you are linking number of items to type of items for an inventory. That doesn’t sound like a List at all, but a Map<Item, Integer>.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: moved class files into new package, application stopped working...