Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVERD] java.lang.ExceptionInInitializerError  (Read 1597 times)
0 Members and 1 Guest are viewing this topic.
Offline Yemto

Junior Duke


Exp: 3 years



« Posted 2013-09-20 19:16:59 »

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.<init>(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.<clinit>(PathFind.java:21)
   ... 34 more

Here is the class file
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
/*
 * 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());
        }
    }
}
Offline Jeremy
« Reply #1 - Posted 2013-09-20 19:51:32 »

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.<clinit>(PathFind.java:21)


That seems to be your problem.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline Yemto

Junior Duke


Exp: 3 years



« Reply #2 - Posted 2013-09-20 20:01:13 »

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

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeremy
« Reply #3 - Posted 2013-09-20 20:02:55 »

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

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.

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?)

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline Danny02
« Reply #4 - Posted 2013-09-20 20:19:45 »

so much state  Sad

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

Junior Duke


Exp: 3 years



« Reply #5 - Posted 2013-09-20 20:27:50 »

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

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.

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?)

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.

so much state  Sad

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

I know how to use hashcode. But I don't know how to make it work with two integers.
Offline Jeremy
« Reply #6 - Posted 2013-09-20 20:59:32 »

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

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline Yemto

Junior Duke


Exp: 3 years



« Reply #7 - Posted 2013-09-20 21:06:19 »


Thanks. But I hate auto generated methods. I can't learn anything if I don't do it myself.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (44 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (38 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!