Solved

package thing

Posted on 2004-09-21
13
165 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now