#Eclipse Error: Could not find or load main class

1 messages · Page 1 of 1 (latest)

rotund forumBOT
#

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

charred carbon
#

Let's not curse in our messages.

hasty verge
#

//u stupid
package stat;

import java.util.HashMap;
import java.util.Scanner;

public class Main {
static String name;
static int pin;
static int balance = 0;

static Scanner f = new Scanner(System.in);
static HashMap<String, Object> info = new HashMap<>();


static public void Menu() {
    int m = Integer.parseInt(f.nextLine());

    System.out.println("Login = 0 | Register = 1 | Deposit = 2 | Withdraw = 3 | Information = 4");

    switch (m) {
        case 0:
            Login();
        case 1:
            Register();
        case 2:
            Deposit();
        case 3:
            Withdraw();
        case 4:
            Information();
    }
}

static public void Login() {
    System.out.println("Welcome to the Fucking Bank");
    System.out.println("Proceed to the Login page or Register");
    System.out.println("/n" + "Login = Yes | Register = No");

    String YN = f.nextLine();

    switch (YN.toUpperCase()) {
        case "YES":
            break;
        case "NO":
            Register();
    }
    //TO THE LOGIN
}

static public void Register() {
    System.out.println("Input your Name: ");
    info.put("String", name = f.nextLine());
    System.out.println("Input your Pin: ");
    info.put("String", pin = Integer.parseInt(f.nextLine()));
}
static public void Withdraw() {
    System.out.println("Withdraw");
    info.put("String", balance - Integer.parseInt(f.nextLine()));
}
static public void Deposit() {
    System.out.println("Deposit");
    info.put("String", balance + Integer.parseInt(f.nextLine()));
}

static public void Information() {

}

}

#

dis should be better

charred carbon
#

Check your run configuration in I'd wagger Eclipse. And why are all your methods static instead of acting upon an object?

#

I also recommend using this next time:

rotund forumBOT
#

Please use this format for posting code:

```java
// Example java program
int value = 5;
System.out.println(value);
```

Which results in:

// Example java program
int value = 5;
System.out.println(value);

For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.

charred carbon
#

Java's on object oriented programming language. Also in your case if it's all on class, and not object level. How would you support multiple registers?

charred carbon
#

Or deposit system, whatever you're building.

livid gyro
#

do you have a main function?

hasty verge
#

im using eclipse cuz intellij wont run the code

livid gyro
#

because the file you showed doesnt have a main function

#

you need to create a run config that sets the file that is to be executed to your Main.java that includes your main function

hasty verge
#

i had problems with this, so i searched online and couldnt find da probs

#

so i apologize if im being stupid

#

i just used it like a few hours ago

livid gyro
#

in intelliJ? or are you using eclipse now

hasty verge
#

as for the eclipse thing

#

imma reinstall it

livid gyro
hasty verge
livid gyro
#

then create a new run config for java application or something similar named (im not on pc right now) and there you can set thr main class

livid gyro
#

maybe im mixing up stuff

hasty verge
livid gyro
#

add new

hasty verge
hasty verge
#

whats the new?

#

theres a lot here

livid gyro
#

on the top left + buttln

#

Application

#

the first

hasty verge
#

then whats the next?

livid gyro
#

entee the name of your main file that contains your main function

#

you can also name your run config

#

got it?

hasty verge
hasty verge
livid gyro
#

.java

rotund forumBOT
# livid gyro .java

Looks like you attempted to use a command? Please note that we only use slash-commands on this server 🙂

Try starting your message with a forward-slash / and Discord should open a popup showing you all available commands.
A command might then look like /foo 👍

livid gyro
#

Main.java

#

the file ending is needed here

hasty verge
#

still da same

hasty verge
livid gyro
#

mhmm

#

does your Main.java have a main function?

#

uhh

#

try stat/Main.java
im not sure maybe you need the package path aswell

#

its been a while for me aswell

hasty verge
#

all i have in my class

#

is (String[]args) really required?

livid gyro
#

ok so thats the problem probably
every project needs one main function. thats the entry point for the application

#

it has to be named "public static void main(String args[])

#

the class name that contains the main function is not really relevant, but its (as far as I know) standart to call it Main.java

mossy barn
hasty verge
#

it a need

#

mb

livid gyro
#

so just add the main function and it should be able to start

#

and from the main function you can call your other functions

livid gyro
# hasty verge public class Main

its also personal preference but I always think it looks better to write out "public" in the function declarations (just my personal opinion)

hasty verge
#

how do i do that again>

livid gyro
#

mhm what do you mean?

hasty verge
#

i cant reference it because its (String[]args)

livid gyro
#

you have to do it the other way around

#

in the main function you call your functions

#

so
public static void main(...)
Menu()

#

so basically you never have to call main() as it is automatically being called at the start

hasty verge
mossy barn
#

move ur logic into a separate method and call that

#

but u sbould avoid doing recursions for multiple reasons

livid gyro
#

after the function call Menu() is finished, the rest of your main function will be executed

mossy barn
#

instead u should work with loops

#

if u want to repeat sth, use a loop

#

calling a method again will just nest the calls, create bugs that are impossible to debug and eventually crash after doing it 200x

livid gyro
#

basically in your main method you should only call funcrtions that do stuff and nothing else

mossy barn
#

(btw, its String[] args. not String args[]. hence its also marked yellow)

hasty verge
hasty verge
#

thanks guys

livid gyro
#

no problem

#

got me something to do during my train ride