[SOLVERD] java.lang.ExceptionInInitializerError

I have spend a whole hour screaming on my computer, and tried to revert to a old build of my project, and search on google to try to find a solution. But so far nothing, so I posting the error message, and the .java file and hope someone can find the error, and explain why it happens.

[quote]Exception in thread “AWT-EventQueue-0” java.lang.ExceptionInInitializerError
at village.Other.PathFinding.(PathFinding.java:47)
at village.Other.LivingEntity.pathFind(LivingEntity.java:26)
at village.controls.MouseControl.mouseClicked(MouseControl.java:64)
at java.awt.Component.processMouseEvent(Component.java:6508)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.RuntimeException: Uncompilable source code - class PathFinding is public, should be declared in a file named PathFinding.java
at village.Other.PathFinding$PathTile.(PathFind.java:21)
… 34 more
[/quote]
Here is the class file

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package village.Other;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import village.world.World;
import village.world.objects.*;
import village.tr;

/**
 * @author Johan
 */

public final class PathFinding implements Yemto.mutlicore.Task {
    private HashSet<String> searchedPath = new HashSet<>();
    private ArrayList<PathTile> processing = new ArrayList<>();
    private ArrayList<PathTile> pending = new ArrayList<>();
    private boolean finished = false;
    
    private final static Integer[][] moveTo =
    {
            {1,0},{-1, 0},
            {0,1},{ 0,-1},
            
            {-1, 1},{ 1,-1},
            {-1,-1},{ 1, 1},
            
            {0,0}
    };
    
    private PathTile lastTile = null;
    private int finishX, finishY;
    private WeakReference<World> world = new WeakReference<>(null);
    
    public PathFinding(World w, int x, int y, int x2, int y2){
        world = new WeakReference<>(w);
        
        finishX = x2;
        finishY = y2;
        
        //adding the start search tile
        PathTile tile = new PathTile(x, y, 0);//The PathTile class is down at row 168
        
        processing.add(tile);
        searchedPath.add(toDataString(x, y));
    }
    
    public PathTile getNextTile(int x, int y){
        int dist = 0;
        PathTile next = null;
        
        for(PathTile t : pending){
            //Using distance between the tiles to cut down on loops. 1.6 is used to give it more room for errors
            if(tr.distanceToPoint(x, y, t.getX(), t.getY()) <= 1.6 && dist <= t.getStep()){
                dist = t.getStep();
                next = t;
            }
        }
        
        return next;
    }
    
    private String toDataString(int x, int y){
        return x+","+y;
    }
    
    public PathTile getPathTile(int x, int y){
        for(PathTile t : pending){
            if(x == t.getX() && y == t.getY()){
                return t;
            }
        }
        
        return null;
    }
    
    public boolean isFinished(){
        return finished;
    }
    
    @Override
    public boolean hasTask(){
        return true;
    }
    
    @Override
    public void task(){
        long startTime = System.nanoTime();

        PathTile t = null;
        while(!searchedPath.contains(toDataString(finishX,finishY))){
            t = processing.get(0);
            pending.add(t);

            for(Integer[] m : moveTo){
                int movmentCost = 10;//<-- what it cost to move, this is used to backtrack
                int newX = t.getX()+m[0];
                int newY = t.getY()+m[1];
                Tile tile = world.get().getTileFromWorld(newX, newY);

                //Making moving diagonal cost more
                if(m[0] != 0 && m[1] != 0){
                    movmentCost = 15;
                }
                
                //Make sure you haven't searched the same tile twise, and add the tile to pending, if you haven't 
                if(tile != null && !searchedPath.contains(toDataString(newX,newY))){
                    PathTile pt = new PathTile(newX, newY, tile.getTerrainScore());
                    pt.setStep(t.getStep()+movmentCost);
                 
                    processing.add(pt);
                    searchedPath.add(toDataString(newX,newY));
                }
            }

            lastTile = t;
            processing.remove(0);
            Collections.sort(processing);
        }
        
        //adding last tile
        if(t != null){
            lastTile.setStep(t.getStep()+10);
            pending.add(lastTile);
        }
                
        searchedPath.clear();
        processing.clear();
        findingPath();
        
        finished = true;
        double time = (System.nanoTime() - startTime) / 1000000.0;
        System.out.println("Search time: "+time+"ms");
    }
    
    //Cleans up all dead ends but using the step score
    private void findingPath(){
        //Using used to init the cleanup code
        PathTile nextTile = lastTile;
        processing.add(nextTile);
        
        while(nextTile.getStep() > 0){
            
            //Current x and y where are intrested in
            int currentX = nextTile.getX();
            int currentY = nextTile.getY();
            
            for(PathTile t : pending){ 
                //1.6 is used instead of 1.5 to leave some room for errors
                if(tr.distanceToPoint(currentX, currentY, t.getX(), t.getY()) <= 1.6 && t.getStep() < nextTile.getStep()){
                    nextTile = t;
                }
            }
            
            //add optimum/semi-optimum tile
            processing.add(nextTile);
        }
        
        pending = new ArrayList<>(processing);
        processing.clear();
    }
    
    public class PathTile implements Comparable<PathTile>{

        private int x, y, step = 0, terrainScore;       
        private PathTile(int setX, int setY, int setTerrainScore){       
            x = setX;
            y = setY;
            terrainScore = setTerrainScore;
        }
                
        public int getX(){
            return x;
        }
        
        public int getY(){
            return y;
        }
        
        public int getDistance(){
            double distance = tr.distanceToPoint(getX(), getY(), finishX, finishY) * 100.0;
            return (int)distance;
        }

        public int getTerrainScore(){
            return terrainScore;
        }
        
        public void setStep(int i){
            step = i;
        }
        
        public int getStep(){
            return step;
        }
        
        @Override //Caculate the prefered way by reange the order in "processing"
        public int compareTo(PathTile t) {
            return (getDistance()+getTerrainScore()) - (t.getDistance()+t.getTerrainScore());
        }
    }
}

You can evaluate and inspect the exception member of that thrown exception which should give you the cause. You can also get it by invoking getCause() on the thrown exception. That will likely help you figure out what caused that exception to be thrown.

Unfortunately, at first glance, I can’t notice anything wrong with your static initializers.

As a side note, it might help if I point out that you are leaking your uninitialized object to toDataString (technically it is initialized, but the constructor hasn’t finished doing its work when you begin using the object, toDataString should be a static method.) This is OK as long as your are very careful and it is more or less required. You can easily make toDataString static to remove that worry so you mid as well.

Look at the bottom of your stack trace:
Caused by: java.lang.RuntimeException: Uncompilable source code - class PathFinding is public, should be declared in a file named PathFinding.java
at village.Other.PathFinding$PathTile.(PathFind.java:21)

That seems to be your problem.

I get

[quote]java.lang.ExceptionInInitializerError
Cause = java.lang.RuntimeException: Uncompilable source code - class PathFinding is public, should be declared in a file named PathFinding.java
[/quote]
I again did a google search, to find how to fix it. It say the class name and file name needs to be the same… which it is. Even after copy and past it over again.

I again did a google search, to find how to fix it. It say the class name and file name needs to be the same… which it is. Even after copy and past it over again.
[/quote]
If you modified the source files outside of Eclipse you need to right click on the project and select refresh to resync it with the local filesystem. Also try a clean rebuild.

It is called PathFinding.java (with the .java extension?)

so much state :frowning:

also, abandon the toDataString method pls and use hashcode as everybody else.

If you modified the source files outside of Eclipse you need to right click on the project and select refresh to resync it with the local filesystem. Also try a clean rebuild.

It is called PathFinding.java (with the .java extension?)
[/quote]
Thanks, I downloaded Eclipse and ran the code there without any problem. I used NetBeans, before… which seams to have a ton of bugs in it.

I know how to use hashcode. But I don’t know how to make it work with two integers.

FYI eclipse generates these functions for you: http://alvinalexander.com/blog/post/eclipse-ide/eclipse-faq-create-hashcode-equals-methods

Thanks. But I hate auto generated methods. I can’t learn anything if I don’t do it myself.