• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

package thing

I have my current directories as:
--
  thisFile.java
  Maploader (folder)
     - graphs (folder)
         - Graph.java
---
and why doesnt this work:

MapLoader loader = new MapLoader (aFile.getName());
Graph gf = new GraphImp(); // error here
^


I have already declared files in Maploader to be "package Maploader" and files in graphs "package graphs", also, in thisFile, I have already done: import Maploader.*; import Maploader.graphs.*;

It complains:
   Cannot access Maploader.graphs.Graph
   Bad class file: ./Maploader/graphs/Graph.class
   class file contains wrong class: graphs.Graph


what's wrong?

0
jtcy
Asked:
jtcy
  • 7
  • 6
1 Solution
 
TimYatesCommented:
> files in graphs "package graphs"

package Maploader.graphs ;
0
 
jtcyAuthor Commented:
Okay, that solves the problem, but what about if Maploader needs to use classes from graphs folder? How should it import? I had "import graphs.*;", but it doesnt work now after i changed according the way you said.

0
 
TimYatesCommented:
> "import graphs.*;"

import Maploader.graphs.*;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jtcyAuthor Commented:
no, it doesnt work. There;s no a directory called Maploader within Maploader folder!~

--
  thisFile.java
  Maploader (folder)
     - graphs (folder)
         - Graph.java
---
0
 
TimYatesCommented:
what is "MapLoader" that you keep giving examples of?

You need to post more code
0
 
jtcyAuthor Commented:
see, current directory:
------------------
thisFile.java
Maploader (folder)
-------------------
within Maploader folder, there are files and folders. One of its folder is called "graphs". Thus, at the very first of the question, I needed to let thisFile use files from "graphs", so your first solution works.

But now, files within Maploader also needs to use files from "graphs". So, i should just do "import graphs.*;" in any files within Maploader (folder). But it doesnt work.

um....u get what I mean?

0
 
TimYatesCommented:
> So, i should just do "import graphs.*;" in any files within Maploader (folder). But it doesnt work.

No, if your class root is the same directory as the "thisFile.java", you need to do:

import Maploader.graphs.* ;

as imports are absolute, not relative...
0
 
jtcyAuthor Commented:
Okay, post more code:

-----------------------------------------------------------
package Maploader;

import java.io.*;                          
import java.util.Vector;
import graphs.Graph;
import java.util.StringTokenizer;

public class MapLoader {

    private String token;
    private Graph mapGraph;
               ^ // error: bad class file: class file contains wrong class file
-----------------------------------------------------------

package Maploader.graphs;

public interface Graph {
            
        // Set the area points of this factory map
        public void addAreaPoints (int x, int y);
     
        // Set name for this map
        public void setMapName(String name);

        // Get the name of this map
        public String getMapName();
      
..............
---------------------------------------------------------------








0
 
TimYatesCommented:
Does:

import Maploader.graphs.Graph;

work?
0
 
jtcyAuthor Commented:
Oh, so you mean..um...I should do "import Maploader.graphs.*;" in each files in "Maploader" and then compile within the directory of "thisFile.java"??? I could compile fine at "thisFile" directory, but got that error when i run it in "cd Maploader". So...could that be the reason?
0
 
TimYatesCommented:
Yeah, when you run it in "cd Maploader", your classpath will be wrong...

Run it in the directory above that with:

  java Maploader.MapLoader
0
 
jtcyAuthor Commented:
Ic.....alright, just to confirm:
----------------------------------
For thisFile.java:

import Maploader.*;
---------------------------------
For files in Maploader folder:

import Maploader.graphs.*;
--------------------------------

and then within the directory of thisFile, run javac *.java. ~ ei?
0
 
TimYatesCommented:
should work :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now