No Main Method?

Jul 23, 2014

I'm trying to make a TBG (Text Based Game) in Java for Android. Now, when I try to run it, it says No Main Method to run this program. The compiler also checks the program and tell me there are no errors.

View Replies


ADVERTISEMENT

How To Return Array From A Method / Back Into Main Method That Prints Out Stuff

May 27, 2014

I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?

View Replies View Related

Writing A Method That Returns Words Without Four Letters Back To Main Method

May 27, 2014

I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.

Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.

import java.util.Scanner;
 public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
 
[Code] ....

I have to make new string array in the method and return words without four letters in the main method

View Replies View Related

How To Call A Method That Exist Within A Class Into Main Method

Feb 13, 2014

I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?

public class locker { 
public static void main(String[] args) {
CombinationLock();

[code]....

View Replies View Related

Main Method Separated From Other Method

Jan 13, 2014

Here's a class called Fibonacci

Java Code:

public class Fibonacci {
public static int fib(int n) {
if (n < 2) {return n;}
else {return fib(n-1)+fib(n-2);}

[code]....

it contains one method called fib() and one main method.If I would want to have the main method in another class than fib(), how would I write the two classes? Only cutting the main method from this class to another one doesn't work.My question is, is the reason it doesn't work because I then would have to have a constructor in the Fibonacci class, and create a Fibonacci object first which I then use the method on?

View Replies View Related

Why Is Main Method Static

Oct 1, 2014

in java why main method is always static in nature...

View Replies View Related

Calling A Method From Main

Jan 26, 2014

The idea is to create a program to add plants and retrieve plants from a Nursery. I created a class with the properties of the plants and also there is the class an Array list to keep track of the plants entered ( they will have to be printed later) (I am not too sure if adding a public class there is the best option.

The program will allow the user to pick and action and from there the code will do something. I don't want to have all the code inside 'main' The problem is in line 114.This is what I have so far.

Java Code:

package plant.nursery;
import java.util.ArrayList;
import java.util.Scanner;
/**Class to create a plant for a nursery.
public class PlantNursery

[code]....

View Replies View Related

Define Main Method

Apr 26, 2014

this is my program error occured run time,but compile sucessfully

{error msg-Error: Main method not found in class helloworldapp.HelloWorldApp, please define the main method as:
public static void main(String[] args)}
class HelloWorldApp
{
private int empno;
private float salary;
void setHelloWorldApp()
{
empno=12;
salary=1200;

[code]....

View Replies View Related

Calling A Method To Main

Nov 17, 2014

I'm trying to call a method to my main method, but I can't seem to get it to work and it keeps resulting in a compile error.

import java.io.*;
import java.awt.Point;
import java.text.DecimalFormat;
import java.util.Random;
public class Chase {
public static void main(String args[]){

[Code] .....

View Replies View Related

Calling A Method To The Main

Sep 10, 2014

I have been reading about methods and I do have a beginner level understanding on how they work. I was trying to mess around and make a dog calculator using methods. I ran into a small snag; I cannot get the method to call to the main or the program to compile correctly. The first code below is the original. To me it looks like (based off of some examples I looked at) there should be no problems, but NetBeans gives me a few errors. 1) line 8- "cannot find symbol, variable dogYearCalc; 2) line 18 illegal start of expression; and 3) line 22 - unreachable statement.

import javax.swing.JOptionPane;
public class KrisExample {
public static void main (String[] args) {
double dogYears = 0;
JOptionPane.showInputDialog (null,"Please enter you dog's age in human years:");

[Code] ....

Someone told me that I was calling dogYearCalc without any arguments in your main method. I take that to mean that I needed to add it to the main, so I did here:

public static void main (String[] args, double dogYearCalc) {

That got rid of my first error, but then when I tried to run the program NetBeans said that I have no main class, so switched back to the original program above.

I thought that when I calling the dogYearCalc method on line 10 was the whole purpose of using a method. It seems to me that putting it somewhere in the main is counter productive.

View Replies View Related

Recall Main Method After Calling Of JVM?

Jul 28, 2014

Can we recall the main method? I'm trying a code to recall main method (after the calling of JVM). I know this doesn't make any sense but I'm trying this just like that.

Code:

class derived {
public static void main(String args[]) {
System.out.println("Main Method class");
show();
}
static void show()

[code]....

View Replies View Related

Splitting Up Main Method / Class?

Jan 29, 2014

I've written a program just for the sake of it (to learn) and it seem's like theres quite a lot in the main method that perhaps could be split up into seperate classes. I'm not too sure where should start with this though, or what my thought process should have been as I was writing the program.

import java.util.Scanner;
 public class Loops {
 public static void main(String[] args) { 
int answer = 16; 
Scanner scan = new Scanner(System.in); 
// Question
 System.out.println("What is 4 x 4 ?"); 

[code]...

--- Update ---

here's a version without code comments as they might make it harder to read here -

import java.util.Scanner;
 public class Loops {
 public static void main(String[] args) {
 int answer = 16;
 Scanner scan = new Scanner(System.in);
 System.out.println("What is 4 x 4 ?");
 int userAnswerInt = 0;

[code]...

View Replies View Related

Void And Static In Main Method?

Jan 7, 2014

What does void and static mean in the main method?

View Replies View Related

How To Have Multiple Classes But Only One Main Method

Nov 1, 2014

I was reading the book, "Head First Java" and it was talking about how there may be multiple classes in a large application, but there will be only one main method.how does it work that way? How can you have multiple classes, but only one main method?

View Replies View Related

Access A Method Of Class From Main

Feb 9, 2014

This time I have to make a Black Jack game ( I guess this is a classic) I have created Three classes for this BlackJack( Main), Card, and Player.

What I am trying to do is put the Give one card to the player and remove it from the deck into a separate procedure because I will be doing this several times during the game.

This is the code I have so far Under the class BlackJack.

Java Code:

package black.jack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

[Code] .....

View Replies View Related

Cannot Call Child Method From Main

May 7, 2015

I can call a child method from a main method. If I have a parent called "Assessment", a child called "Quiz", and another child called "test". Can I instinate an object like Assessment a = new test(); and call a method in test.I know the method can be called if I instinate the test t = new test() but that defeats the purpose of inheritance which I'm learning in class.

View Replies View Related

Calling Object To Main Method

Oct 26, 2014

When I try to call an object it can't find the symbol in the argument list. NetBeans says that it cannot find the movieCategory symbol when I try to call it. When I compile it to test a popup comes up that states "One or more projects were compiled with errors. Application you are running may end unexpectedly. I ran it anyways and everything runs up to the point of where it should call the object.

At this point it should get the Movie object and run the code within that, but if I put one of the categories it throws. "Exception in thread "main" java. lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>at MovieApp.main(MovieApp.java:33)Java Result: 1"

From my understanding to call an object it requires objectName.methodName(argumentList). Here is my Main method

/**
*This application will store a list of 100 movies and display them by category
*/
import java.util.Scanner;
public class MovieApp
{
public static void main(String args[])
{
//Displays <code>String</code> welcome message
System.out.println("Welcome to the Movie Application.");
System.out.println("There are 100 movies in the list.");
System.out.println("What category are you interested in?");
System.out.println();

[code].....

View Replies View Related

Return Int X To Main Method And Print It Out

Oct 10, 2014

I tried to create a simple program. The main method is supposed to call out the secondary method to use Scanner in order to ask a person to type in a number, which will be assigned to int x. Then the secondary method supposed to return the int x to main method, which supposed to print it out. And for some reason I just can't do it. No matter what the main method refusing to accept the int x.

import java.util.Scanner;
public class Return{
static Scanner newNum= new Scanner(System.in);
public static void main(String[] args){
getInt();
System.out.println(x);
}
public static getInt( ) {
// TODO Auto-generated method stub
int x;
System.out.print("give a num");
x= newNum.nextInt();
return x;
}}

View Replies View Related

Why Main Method Has Argument String

Oct 6, 2014

One interviewer has asked me one question that why main() method has argument "String[] arg".What is reason behind this ??I am unable to explain it because i never think about it ..

View Replies View Related

Create Method In Main Class And Use It On Object

Feb 26, 2015

I've been writing classes over and over for school. So I create a class outside of my main class. I create a new constructor and then create objects from my main class. I hope that makes sense. So i use methods in that class to work with the object. So I have an object name I've created <dot> method name. So I can create objects and then use methods from the class, but I'm wondering can I create a method in my main class and use it on that object? I don't understand how to do that.

View Replies View Related

Pass Arguments From Main To Paint Method

Feb 5, 2015

I want to take command line arguments and pass them to a paint method. This is a test program that will just draw some equations. How can I get the input array clinputs[] to be used in public void paint( Graphics g) ?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LinePlot extends JFrame {
public LinePlot() {
super( "Line Plot" );
setSize(800,600);

[Code] .....

View Replies View Related

How To Run A Normal Java Program Without Main Method

Nov 19, 2009

Is it possible to run a program(a method) without a main method?

View Replies View Related

Event Driven Programming / No Main Method

Jan 29, 2015

I'm reading a book titled 'Intro to Java Programming'. I understand all the Main Method stuff. I'm now reading a chapter that talks about event driven programming. I know how to do this in VBA and in C#, ut I can't figure out how this works in Java. Here's the sample code that I'm trying to run.

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

[code]....

I'm using Net Beans IDE. When I paste that code into the IDE, I get all kinds of errors. Also, since there is no Main, I don't know how this is supposed to run. Java needs a Main Method for everything, I think. Does the Main call some kind of class?

View Replies View Related

Error In Main Method - Cannot Find Symbol

Dec 15, 2014

I am writing a palindrome program. I don't understand what is wrong with my Main method. It is giving me error and error is "Can not find symbol in main method"

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PalindromeA extends JFrame {
private JTextField inText;
private JTextField outText;

[Code] ....

View Replies View Related

Calling Multiple Methods Into Main Method

Sep 30, 2014

This current one is to calculate a planes holding pattern. I have to write a method to prompt user to enter speed in knots, then it converts it to km/hr. Another method to calc. pattern width using the speed, another method to calc. pattern length, than a main method which would call and print out the speed in knots, speed in km, pattern width and length.My current problem is on the second method. It works in that I can enter the values and it gives me the correct answers, however it's asking me to enter the speed twice, instead of just once. Anything I try just results in errors and won't compile.

import java.util.Scanner ;
//main method
public class TitleRemoved {
public static void main(String[] args) {
double airSpeedKm = airSpeedOts () ;
System.out.println("That speed is " + airSpeedKm + " km/hr.") ;

[code].....

I want my code to not only work, but be organized and easily readable as well, so I want to avoid bad habits.

View Replies View Related

Main Method Returned To Earlier If Statement

Jun 10, 2014

This program should display the sum, average, product, smallest and largest of the numbers.

Java Code:

//Displays the sum, average, product, smallest and largest of the numbers
import java.util.Scanner;
public class Practice6 {
public static void main( String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");

[Code] ....

The problem is when I enter

The first integer: 7
The second integer: 5
The third integer: 9

The program displays "The third integer is the largest and the second integer is the smallest" then displays "The first integer is the largest and the second integer is the smallest". The main method returned to the IF statement in the line 23. How or why?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved