Questions tagged [main-method]

115 questions
3
votes
4 answers

Error: main class not found

When compiling the program I get the error as Could not find the main class: Solution. Program will exit. The program is: import java.util.*; public class Solution{ public static long[] factors(long a){ long[] b; b=new long[50]; …
harvish
  • 195
  • 1
  • 4
  • 11
3
votes
1 answer

main methods and key listener

Would anyone be able to tell me why this program says I am missing a main method? I have one at the bottom of this code. import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class Collision extends…
Martin Marino
  • 355
  • 2
  • 4
  • 13
2
votes
2 answers

How do I run a main method in a Java Gradle project from command line?

I have a Gradle project (say, MyProject) that has a main method that I only want to use to run a small Java app. Say, the script is in a class and package as follows: MyScript.Java package com.car.ant; import…
aCarella
  • 2,032
  • 7
  • 41
  • 75
2
votes
2 answers

Java app lifecycle

When does a typical Java app finish? If I start a new thread in the main method and then the main method finishes, but the other thread continues working, the app would still be on until all it's threads have died, wouldn't it? Thanks & Merry…
Albus Dumbledore
  • 11,500
  • 22
  • 60
  • 102
2
votes
2 answers

How to get an element from argv[]

This is C++ At the windows cmd line user types p3.exe X
greg
  • 167
  • 3
  • 14
2
votes
2 answers

How to create an object of List from another class in main method?

I have to create an Object of List in main Method but i have no idea how to do it. Constructor of class, that i want to create an Object has an List as a parameter. How can i create an Object of CashMachine class? By the way I am not going to write…
merdle
  • 264
  • 2
  • 20
1
vote
5 answers

Java methods and classes, how do they fit together?

Currently I am writing a program for an introductory Java class. I have two pieces to my puzzle. Hopefully this is a relatively simple to answer question. Firstly, here is what I am trying to use as my main program: import java.util.Scanner; public…
None
1
vote
2 answers

Run a CHILD in Eclipse of which the PARENT class has the main method but the CHILD class itself is just a class without the main method

//Package in which I have both the Parent and the Child class package learningJava; public class MainMethodDemoParent { //Main method of the parent class public static void main(String... args) { System.out.print("This is the…
Amrit
  • 65
  • 3
1
vote
3 answers

How can I determine which class's `main` method was invoked at runtime?

I'd like to dynamically determine which class's main method was invoked, in order to allow for an easier to digest combined log file. Currently, a single (rotated) log file aggregates all the log output from a number of daemons, but there is no…
apg
  • 2,511
  • 1
  • 17
  • 18
1
vote
5 answers

How come there is no error if we name args[] as arhs[](or any other name) in java main method?

I'm a beginner in java.When executing a simple program I noticed that in main method public static void main(String args[]) args[] can be given any name and it executes successfully. Why is that?
1
vote
2 answers

Instantiating an inner class within a main method

When we try to instantiate an Inner class (aka: non-static Nested class) in java, say we do that in two cases: 1.in a main method in the same file of the outer Class in which we have two options: (ex:) public class Test1 { class InnerClass { …
Profess Physics
  • 307
  • 4
  • 9
1
vote
1 answer

Repeating the main method

I'm new to java and this forum. I wrote a code for a simple calculator. It's working. But how can I repeat the main method if I (let's say) put "=" instead of "(+, -, *, /)"? Should I use a loop, or something else? Thanks in advance! import…
Un_lh
  • 9
  • 2
1
vote
0 answers

Better way to call my methods in the main method for Connect Four

I'm building a program to play Connect Four. I have all my methods done and I'm just building my main method up to actually play the game. Is there a more efficient way to use my Play class than manually inputting the code the way I am? I was fine…
Pizaz
  • 21
  • 2
1
vote
4 answers

Uninitialized local variable - No error : Java

Here are two uninitialized local variables. Still this does not give compile time or runtime error and executes completely. Is this thing permissible in Java and How (explanation will be welcome). class A2{ } public class A { public static void…
1
vote
1 answer

Cannot find Symbol - variable. In main method when symbol is used in other method

This program is used to calculate Pi by random numbers of throws(x,y coordinates) then iterate the whole process a number of times. I get an error on the last line of code double average = average(pi) where it says cannot find symbol variable pi,…