?
Solved

package thing

Posted on 2004-09-21
13
Medium Priority
?
171 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
[X]
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
  • 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
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!

 

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 80 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

771 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