DEV Community

Calin Baenen
Calin Baenen

Posted on

Unresolved compilation problem (with no explanation?).

So, I'm making RuntDeale, and I tried compiling a test I made, it compiled with no (visually displayed (as they WOULD be, if there were any)) errors, and it creates the .jar file, but when I double click it, it doesn't run (or rather, does not do what it's supposed to do (which is to create a window with the title "RuntDeale", that has a black background, and is NOT resizable)).

So, I try running tests where I know how to test best, VSCode, and, this time, I do see an error. Specifically:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
        at RuntDeale.code.Main.main(Main.java:44)
Enter fullscreen mode Exit fullscreen mode

Main.main(String[] args) looks like this:

public static void main(String[] args) {
    Main program = new Main();
    try {
        program.run();
    } catch(Exception exc) {
        program.setTitle("Exception: "+exc.getLocalizedMessage());
    }
}
Enter fullscreen mode Exit fullscreen mode



I only really have one theory, that it (for some reason) can not resolve the class RuntDeale.code.Backpack (which is just meant to be something to help me save time, so I don't have to rewrite code).
If any additional information is needed, please ask, but please, tell me what you think the problem is.

Thanks
Cheers!

Top comments (28)

Collapse
 
baenencalin profile image
Calin Baenen

Maaaan, I can't believe I even considered Java for this.
I'm so glad I moved this project to Rust.

Collapse
 
ducaale profile image
Mohamed Dahir • Edited

off-topic question have you tried using JavaFX instead of Swing? and what type of game are you trying to make?

Collapse
 
baenencalin profile image
Calin Baenen

Just looked at the example code, and dear God, what the fuck is that library!?

It looks like the Java equivalent of TKinter, and I switched to Java because TKinter was complicated (but also mostly because Python is slow, and not compiled).

Collapse
 
ducaale profile image
Mohamed Dahir • Edited

Fair enough. There are game libraries for python which also take care of creating a runnable executable.

Collapse
 
baenencalin profile image
Calin Baenen

I'm trying to make a game like Undertale. And no, I haven't, because I've never heard of it.

Collapse
 
ducaale profile image
Mohamed Dahir • Edited

I don't think the slowness of a programming language would matter for a game like Undertale. What game libraries have you tried so far? (doesn't matter if it is Java or Python)

Thread Thread
 
baenencalin profile image
Calin Baenen

Actually, to me, speed matters for performance maximization.
Plus, that isn't the only reason I left, I left because I also wanted the language I'm using to be compiled, and I also wanted the language to be strongly typed (to save me a hassle in debugging).

Thread Thread
 
baenencalin profile image
Calin Baenen

Libraries for what, Python?

PyGame (which fucking sucks ass).
And TKinter (which works well, but is exceptionally complicated, and underpowered).

Thread Thread
 
ducaale profile image
Mohamed Dahir

One reason I wouldn't use Java for gamedev, is that it requires the user to install the Java runtime.

If your main priority is speed and performance, I would suggest looking at either C++ or Rust. Both have a steep learning curve, but I am sure that you will benefit from them in your career as a game developer.

Thread Thread
 
baenencalin profile image
Calin Baenen

Wouldn't Rust require you to install something as well (since it doesn't sound like a native language)? Is it compiled? And will the compiled product work on all devices, like it would Java or C#?

Also, again, I said I'm bad with tools, and tried dipping my toes into C#, but I can't even figure out how to compile my .cs file with .NET through Command Prompt, like I do Java.

Thread Thread
 
ducaale profile image
Mohamed Dahir • Edited

Wouldn't Rust require you to install something as well

When you compile your game, a statically linked binary will be created. This means end-users will not have to install anything.

Is it compiled?

Yes, and it is the fastest language out there (just behind C/C++)

And will the compiled product work on all devices, like it would Java or C#?

You just have to compile for each platform you need to target.

I can't even figure out how to compile my .cs file with .NET through Command Prompt, like I do Java

The best thing about Rust is Cargo which is a modern package manager / build tool that just works™.

If you're interested, check macroquad which supports Windows, macOS, Linux, Android, iOS and HTML5.

Thread Thread
 
baenencalin profile image
Calin Baenen

Regarding question three's answer, is there ANY way I don't have to recompile for EACH platform, is there like some "master-platform" compilation?

If not, how do I compile for a specific platform? And can I merge the binaries in to one whole so that they will work on any device when installed?

Thread Thread
 
ducaale profile image
Mohamed Dahir

What people usually do is to setup CI/CD pipeline that automatically builds the project for each target when a new release is made.

For example, you can see in the assets section of this project, the different binaries that target different platforms.

However, you could always write a script to do this step locally. Take a look at rust-lang.github.io/rustup/cross-c...

And can I merge the binaries in to one whole so that they will work on any device when installed?

I believe having a seperate binary for each platform, will lead to smaller and faster binaries.

Thread Thread
 
baenencalin profile image
Calin Baenen

A lot of this confused my since I hate (am not friends with (never got to know)) external tools outside of compiling. Wjy can't it just be Files -> Compiler => Product, instead of all this extra vomplex BS??

Though, thanks for the advice, I'll try to look in to it further, and see if I can learn anything.

Collapse
 
eelstork profile image
Tea

Adding line numbers would help.

Collapse
 
baenencalin profile image
Calin Baenen

I thought about this more, since I'm awake now, and, line numbers are (implicitly) shown, line 44 to 51. What do you want me to do, add the rest of the Main class, and number that?

Collapse
 
eelstork profile image
Tea

Not sure where it did say the code started at line 44 initially but erm. Having every line numbered is the way to make it easier for people to help you. Screenshot would be fine imho.

Thread Thread
 
baenencalin profile image
Calin Baenen

Is this good? This is all of Main.java:

package RuntDeale.code;

import javax.imageio.ImageIO;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.lang.String;
import java.awt.Color;



/**
* The game's main class.
*/
final class Main {

    private static final Dimension APP_MINSIZE = new Dimension(500, 400);
    private static final String APP_NAME = "RuntDeale";
    private static final float APP_VER = 0.01f;

    private final Entity player = new Entity();
    private final JFrame window;
    private final JPanel ctx;



    private Main() {
        window = new JFrame(APP_NAME);
        window.setResizable(true);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.getContentPane().setBackground(Color.BLACK);
        window.setMinimumSize(APP_MINSIZE);
        window.setLayout(null);

        window.setVisible(true);


        ctx = new JPanel();
    }



    public static void main(String[] args) {
        Main program = new Main();
        try {
            program.run();
        } catch(Exception exc) {
            program.setTitle("Exception: "+exc.getLocalizedMessage());
        }
    }



    /**
    * Run the current program instance.
    */
    protected void run() {
        Graphics g = ctx.getGraphics();
        while(true) {
            try {
                g.drawImage(ImageIO.read(Backpack.getResource(
                    "resources/textures/characters/Chloe/front/walk_0.png"
                )), (int) player.getX(), (int) player.getY(), null);
            } catch(Exception exc) {}
            window.repaint();
        }
    }



    /**
    * Set the title of program's window.
    */
    protected void setTitle(String s) {
        window.setTitle(s);
    }

}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
eelstork profile image
Tea

Ha. Perhaps it is. I'll have a quick look tomorrow.
Do you not have teachers or colleagues to help with your stuff?

Thread Thread
 
baenencalin profile image
Calin Baenen

I don't have teachers, I'm 14, and don't have any classes pertaining.
Also, I live alone (excluding family), so I don't really have colleagues either.

So no, sadly.

Thread Thread
 
eelstork profile image
Tea

If you feel like, drop by here: discord.gg/Y4MJgc244A
If you introduce yourself in general, it's mostly a tiny coder hideout I run.

Collapse
 
baenencalin profile image
Calin Baenen

The line number was shown (44)?

Collapse
 
eelstork profile image
Tea

Probably missed this.
Did you solve your problem?

Thread Thread
 
baenencalin profile image
Calin Baenen

No, not yet.

Collapse
 
eelstork profile image
Tea

Somewhere on SO: "Either way a sequence of refresh and clean build [...] should surface the problem".
I think there's a little flair to this. Errors where the compiler doesn't know what the error is are more often some refresh issues like happens when sources have moved/been repackaged perhaps creating dupes and so forth.

Collapse
 
baenencalin profile image
Calin Baenen

They were both created in the same package initially, and still are(?).

Collapse
 
eelstork profile image
Tea

Well, doing a full refresh is more a thing to try than to reason with, unless the problem becomes chronic.

Thread Thread
 
baenencalin profile image
Calin Baenen

Full refresh?
What? How? Where(?)?