Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

package thing

Posted on 2004-09-21
13
167 Views
Last Modified: 2010-03-31
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
Comment
Question by:jtcy
  • 7
  • 6
13 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12111896
> files in graphs "package graphs"

package Maploader.graphs ;
0
 

Author Comment

by:jtcy
ID: 12111951
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
 
LVL 35

Expert Comment

by:TimYates
ID: 12112011
> "import graphs.*;"

import Maploader.graphs.*;
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:jtcy
ID: 12112156
no, it doesnt work. There;s no a directory called Maploader within Maploader folder!~

--
  thisFile.java
  Maploader (folder)
     - graphs (folder)
         - Graph.java
---
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12112184
what is "MapLoader" that you keep giving examples of?

You need to post more code
0
 

Author Comment

by:jtcy
ID: 12112226
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
 
LVL 35

Accepted Solution

by:
TimYates earned 20 total points
ID: 12112437
> 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
 

Author Comment

by:jtcy
ID: 12112442
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
 
LVL 35

Expert Comment

by:TimYates
ID: 12112457
Does:

import Maploader.graphs.Graph;

work?
0
 

Author Comment

by:jtcy
ID: 12112469
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
 
LVL 35

Expert Comment

by:TimYates
ID: 12112516
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
 

Author Comment

by:jtcy
ID: 12112552
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
 
LVL 35

Expert Comment

by:TimYates
ID: 12112630
should work :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question