Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

package thing

Posted on 2004-09-21
13
Medium Priority
?
173 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

610 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