#terminal instantly quits even though JRE is installed

1 messages ยท Page 1 of 1 (latest)

untold osprey
#

@shrewd junco can you take a look here please

tender zephyrBOT
#

<@&987246399047479336> please have a look, thanks.

tender zephyrBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

I'm sorry, but as a language model AI, I cannot directly access your computer or view any specific code or terminal output. However, I can try to provide some general troubleshooting steps that might help you resolve the issue.

  1. Make sure you have the latest version of Java Runtime Environment (JRE) installed on your system. You can download it from the official Oracle website.

  2. Check if your system's environment variables are correctly set up for Java. Ensure that the "JAVA_HOME" variable points to the correct JRE installation directory and that the "PATH" variable includes the path to the Java bin directory.

  3. If you are running a Java program from the command line, make sure you are using the correct command to execute it. The standard command is "java <ClassName>" where <ClassName> is the name of your Java class containing the main method.

  4. Check if there are any error messages displayed in the terminal before it quits. These messages can provide valuable information about what might be causing the issue.

  5. If possible, try running your Java program on a different machine or with a different JRE installation to see if it works correctly there. This can help identify if there is an issue with your specific setup.

If none of these steps resolve your problem, please provide more specific details about your environment, any error messages received, and any relevant code snippets so that others may be able to assist you further.

untold osprey
#

I tested my app in another pc, I ran it through batch file and through command line but it just instantly quits

#

however it works fine on my machine

#

@shrewd junco would really like it if you could help me out

shrewd junco
#

i can't help u if u don't provide any info to work with

#

neither can others

untold osprey
#

i can post the code here, (its really small)

shrewd junco
#

let the user start it in terminal and report back the error messages that are shown in the terminal

#

and share the file

untold osprey
shrewd junco
#

the error is in the command line window

#

that's why im saying to start it from there

#

and not double click

untold osprey
#

should i share the code?

warm lichen
#

it's because your program is exiting after it's finished running

untold osprey
#

it works on my computer tho

warm lichen
#

the only other time this happens is if there's no java found/wrong version

shrewd junco
untold osprey
#
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;


public class Server implements Serializable
{
    public static void main(String[] args) throws IOException
    {
        ServerSocket serverSocket = new ServerSocket(Integer.parseInt(args[0]));

        System.out.println("Waiting for client ");
        Socket socket = serverSocket.accept();
        System.out.println("Client connected");


        BufferedReader socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        while (true) {
            float num = Float.parseFloat(socketReader.readLine());
            System.out.println(num + " doubled is: " + num * 2);
        }
    }
}
tender zephyrBOT
# untold osprey ```java import java.io.*; import java.net.ServerSocket; import java.net.Socket; ...

Detected code, here are some useful tools:

Formatted code
import java.io. * ;
import java.net.ServerSocket;
import java.net.Socket;

public class Server implements Serializable {
  public static void main(String[] args) throws IOException {
    ServerSocket serverSocket = new ServerSocket(Integer.parseInt(args[0] ));
    System.out.println("Waiting for client ");
    Socket socket = serverSocket.accept();
    System.out.println("Client connected");
    BufferedReader socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    while (true) {
      float num = Float.parseFloat(socketReader.readLine());
      System.out.println(num + " doubled is: " + num * 2);
    }
  }
}
warm lichen
#
@echo off
java -jar <jar> <args>
pause
``` if you save this as a .bat the cmd window still stay open
untold osprey
#

one sec

untold osprey
warm lichen
#

just to be sure, you replaced <jar> <args> right?

#

and java -version shows something?

untold osprey
#

btw here is the client code, the server interacts with it

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;

public class Client
{
    private static ArrayList<Socket> sockets = new ArrayList<>();

    public static void main(String[]args) throws IOException
    {
        sockets.add(new Socket("localhost", 9001));
        sockets.add(new Socket("localhost", 9002));
        sockets.add(new Socket("localhost", 9003));

        BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));

        while (true)
        {
            System.out.println("Enter a number: ");

            float num = Float.parseFloat(inputReader.readLine());

            Integer socketIndex = ThreadLocalRandom.current().nextInt(0, sockets.size());

            CallServer(socketIndex, num);
        }
    }

    private static void CallServer(Integer socketIndex, Float numberToDouble) throws IOException
    {
        PrintWriter socketWriter = new PrintWriter(sockets.get(socketIndex).getOutputStream(), true);

        socketWriter.println(numberToDouble);
    }

}
tender zephyrBOT
# untold osprey btw here is the client code, the server interacts with it ```java import java.i...

Detected code, here are some useful tools:

Formatted code
import java.io. * ;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;

public class Client {
  private static ArrayList<Socket> sockets = new ArrayList<>();
  public static void main(String[] args) throws IOException {
    sockets.add(new Socket("localhost", 9001));
    sockets.add(new Socket("localhost", 9002));
    sockets.add(new Socket("localhost", 9003));
    BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
      System.out.println("Enter a number: ");
      float num = Float.parseFloat(inputReader.readLine());
      Integer socketIndex = ThreadLocalRandom.current().nextInt(0, sockets.size());
      CallServer(socketIndex, num);
    }
  }
  private static void CallServer(Integer socketIndex, Float numberToDouble) throws IOException {
    PrintWriter socketWriter = new PrintWriter(sockets.get(socketIndex).getOutputStream(), true);
    socketWriter.println(numberToDouble);
  }
}
untold osprey
untold osprey
warm lichen
#

hang on - is this for the client or server ur getting the issue?

untold osprey
#

well i am supposed to open 3 instances of server first

warm lichen
#

<jar> needs to be replaced with the name of your jar and <args> should be any args you need (if null)

untold osprey
#

client without 3 servers open is supposed to crash

warm lichen
#

which one is not loading though, the server or clients?

untold osprey
#

i just added the echo and pause

untold osprey
#

i am supposed to open the server first

warm lichen
#

show the .bat?

untold osprey
#

1 sec

#

well i changed it on the other computer

#

on this one it worked fine as it was

#

but it would be this

#

@echo off
start java -jar server.jar 9001
pause

warm lichen
#

remove start

#

the only other thing I can think of right the top of my head is that your jar is probably wrong?

untold osprey
#

ohh yeeh now i get the error

#

i cant copy paste here but

#

it says

warm lichen
#

ss is fine

untold osprey
#

Server has been commpiled by a more recent version of the Java runtime

warm lichen
#

okay great we have the issue

untold osprey
#

this version of java runtime only recognizes class file version up to 5 whatever whatever

warm lichen
#

you have the wrong jre installed on your system

untold osprey
#

i literally installed the most recent one

#

i just installed it

warm lichen
#

what's the output of java --version

untold osprey
#

java -version you mean?

warm lichen
#

yeah myb

untold osprey
#

java version 1.8.0_381

warm lichen
#

yeah that's java 8 not the latest

untold osprey
#

along with someo ther lines

warm lichen
#

java 8 is class version 52

untold osprey
#

but i just installed it from the website

warm lichen
#

that has java 8 ;p

untold osprey
#

yeah

tender zephyrBOT
#

Eclipse Adoptium provides prebuilt OpenJDK binaries from a fully open source set of build scripts and infrastructure. Supported platforms include Linux, macOS, Windows, ARM, Solaris, and AIX.

https://adoptium.net

Eclipse Adoptium provides prebuilt OpenJDK binaries from a fully open source set of build scripts and infrastructure. Supported platforms include Linux, macOS, Windows, ARM, Solaris, and AIX.

#

Download latest Java from https://adoptium.net/, run the installer.

Open a CMD and type java -version and javac -version, if both show your new Java version, you have successfully installed Java! ๐ŸŽ‰
https://i.imgur.com/CurMujt.png

In order to prevent issues with old installations you may want to remove them. Type where java and where javac. They should only show the new and no old entries:
https://i.imgur.com/x5k1GxG.png

If that is not the case, you may want to clean up. Therefore, type "environment variable" into the Windows search and follow the dialog. You will see two entries for a variable called Path, one for your user and one for the system. This variable tells Windows where to look for commands, like java and javac.
https://i.imgur.com/3bN9QE2.png

Edit both. Make sure that they only list the entry to your new Java installation and remove all the old entries you have seen with the where command before:
https://i.imgur.com/JAYog1U.png

Confirm and close all dialogs. Restart your CMD window and try where java and where javac again. It should only list the new installation now and nothing else.

Congratulation, your Java is now finally ready, happy coding ๐ŸŽ‰

Eclipse Adoptium provides prebuilt OpenJDK binaries from a fully open source set of build scripts and infrastructure. Supported platforms include Linux, macOS, Windows, ARM, Solaris, and AIX.

untold osprey
#

so what should i download here

warm lichen
#

^ follow this

untold osprey
#

how do i remove the old ones exactly

warm lichen
#

control panel

#

uninstall program

untold osprey
#

cant i compile the program with older java? so it works for more ppl?

warm lichen
#

yeah the clients you should

#

usually with the server you can expect people to install the correct version to get it working

untold osprey
#

how would i compile with an older version

warm lichen
#

(since the server isn't normally something you give to end users) - in this case you can

#

how did you compile before?

untold osprey
#

i just exported the jar file from eclipse

warm lichen
#

ah rip you'll need to do some googling, i can't remember much about how to use eclipse

untold osprey
#

ah okay, also does this adoptium install thing work for any OS?

warm lichen
#

yeah

untold osprey
#

so there is 1 installer right?

warm lichen
#

yup

untold osprey
#

ah okay sweet let me try it out for the other pc

#

also how come removing the "start" fixed the error

#

i mean showed the error

warm lichen
#

i've never seen people use start

#

but i'm guessing, start is another application in windows

#

so it hides the output of the second program

#

by removing start you're directly calling the java program which is defined in your path

untold osprey
#

ah okay

#

ahaha now it doesnt work on my current machine

#
 LinkageError occurred while loading main class Server
        java.lang.UnsupportedClassVersionError: Server has been compiled by a more recent version of the Java Runtime (class file version 64.0), this version of the Java Runtime only recognizes class file versions up to 61.0
#

this happened after i installed adoptium

warm lichen
#

ah okay it's because you compiled using java 20

#

and class version 61 is java 17

#

under this section, choose 20

untold osprey
#

let me first see if i can compile with older version in eclipse

warm lichen
#

cool - gl - i'm heading out now

untold osprey
#

okay thanks a lot for your help