#Eclipse Error: Could not find or load main class
1 messages · Page 1 of 1 (latest)
Let's not curse in our messages.
oh wait sorry
//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
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:
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.
is that bad?
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?
wdym multiple registers
Or deposit system, whatever you're building.
do you have a main function?
da program is still ongoing im not yet done
im using eclipse cuz intellij wont run the code
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
how do i do dis?
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
in intelliJ? or are you using eclipse now
intellij bro
as for the eclipse thing
imma reinstall it
here the three dots
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
add new
entee the name of your main file that contains your main function
you can also name your run config
got it?
it says not found for some reason
.java
still da same
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
public class Main
all i have in my class
is (String[]args) really required?
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
theres stuff upcoming to make it more flexible but for now, yes, its required
yeah i learned this a while ago, the main method is the one always to be executed first
it a need
mb
so just add the main function and it should be able to start
and from the main function you can call your other functions
its also personal preference but I always think it looks better to write out "public" in the function declarations (just my personal opinion)
oh yeah, as for referencing my main method?
how do i do that again>
mhm what do you mean?
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
okay sure, but how do i get back to that main method?
move ur logic into a separate method and call that
but u sbould avoid doing recursions for multiple reasons
after the function call Menu() is finished, the rest of your main function will be executed
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
basically in your main method you should only call funcrtions that do stuff and nothing else
(btw, its String[] args. not String args[]. hence its also marked yellow)
im pretty sure i typed it correctly but yeah i will do dat.
okie imma do that too
thanks guys