N-Sided Regular Polygon Main Method Error

Sep 5, 2014

My code is giving me an error at the main method and it says that modifier 'static' is not allowed in constant variable declarations. every program that i searched for had the same code line but none had the problem i do.

package regularpolygon;
/**
*
* @author home1
*/
import java.lang.Math;
import java.text.*;

[code]...

View Replies


ADVERTISEMENT

N-sided Regular Polygon

May 8, 2013

I'm working on is to create a program to display an n-sided regular polygon and uses two buttons named +1 and -1 to increase or decrease the size of the polygon. Also enable the the user to increase or decrease the size by clicking the right or left mouse button and by pressing the UP and DOWN arrow keys. So, first off I'm just trying to figure out how to display an n-sided polygon. I have some of the other components started, but I'm just trying to focus on getting this to work.

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Polygon;

[code]....

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

How To Change State Of Object - Main Method Exception Error

Jan 8, 2015

The error I get when I execute my java file.

Exception in thread "main" java.lang.NullPointerExceptionat DogTestDrive.main(DogTestDrive.java:19)

Here is the source

class Dog {
int size;
String name;
void bark () {
if (size < 60) {
System.out.println("Woof woof");

[code]....

Some background: I'm reading "Head first Java 2nd edition" and I'm going through the examples which is showing me how to change the state of an object. The original code looks like the code below, however the previous chapter went over creating array's of an object, so I created an array of the object "Dog" and wanted to re-write it this way. To my understanding, it should work but it's giving me that error when I execute it. The error itself isn't very clear, if I could get a line number pointed to, that would work.

class Dog {
int size;
String name;
void bark() {
if (size > 60) {
System.out.println(“Wooof! Wooof!”);
} else if (size > 14) {
System.out.println(“Ruff! Ruff!”);
} else {
System.out.println(“Yip! Yip!”);

[code]....

View Replies View Related

Error Passing Value Of A Variable From One Class To Main Method Of Another Class

Jan 8, 2014

I've 3 classes.

1. Circle
2. GetInputFromUser
3. testCircle

package ABC;
public class Circle {
private double radius;
public double getRadius() {
return radius;

[Code] .....

In the testCircle class, in the line: getRadius = ui1.GetInput();

It's showing the error: The method GetInput(float) in the type GetInputFromUser is not applicable for the arguments ()

And when I do: getRadius = ui1.GetInput(rad);

It's showing the error: rad cannot be resolved

View Replies View Related

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

Error Could Not Find Or Run Main Class

Jan 7, 2014

I made a breakout like game that runs as a applet and now i wanted to make it run in a jframe so i wrote this

Java Code:

import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class BrickBuster{
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JApplet BrickBuster = new JApplet();
frame.add(BrickBuster);
BrickBuster.init();
}
} mh_sh_highlight_all('java');

It compiles fine but whenever i try running it with the java command it says it couldnt find or load main class. also i have it save in a folder called BrickBuster so i called java BrickBusterBrickBuster.class

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

Could Not Find Or Load Main Class Error

Sep 13, 2014

I have a problem that happens randomly where i try to compile and it just comes up with error

"Error: Could not find or load main class com.productiontrackingscreens.rexam.EmployeeAddressList"

This is a program that worked fine until i started it today. Seems a bug with eclipse.

View Replies View Related

Error - Could Not Find Or Load Main Class

Sep 30, 2014

I'm trying to run a java program from cmd. I'm using Windows 8, java version "1.8_0_20". I've got two classes, the main class called Middleware and a secondary class, called WorkerThread, of which the main class is using functions. I've successfully compiled both .java files with javac, and created the .class file. So all files are in the same folder. However, when I attempt to run the main class with java Middleware, I get the error message: "Error: Could not find or load main class". Here's the main class:

package middleware;
import java.net.*;
import java.util.concurrent.*;
public class Middleware {
//Number of threads serving clients.
private static int nr_threads = 5;
private static int portNr = 6789;
private static ServerSocket welcomeSocket;
private static ExecutorService executor;

[code]....

My code compiles and runs fine in eclipse but on the console, I'm having troubles.

View Replies View Related

Stuck On Error - Could Not Find Or Load Main Class

Sep 2, 2014

I'm getting an error trying to run a welcome app from a book. I've looked at the FAQs and can't seem to solve the issue. I'm guessing my path and/or classpath are not right. Here's my path environment variable.

C:jdk1.8.0_20in;C:ProgramDataOracleJavajavapath;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program Files (x86)InteliCLS Client;C:Program FilesInteliCLS Client;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;%SYSTEMROOT%System32WindowsPowerSh

[Code] ....

Here's my output.

09/01/2014 10:23 PM 634 Welcome.class
09/01/2014 10:21 PM 422 Welcome.java
14 File(s) 126,243,703 bytes
9 Dir(s) 53,942,079,488 bytes free

[Code] .....

It looks like the version command gives me what it should, so it appears I've got java setup right, but I"m stuck on the error I'm getting :

C:jdk1.8.0_20>javac -version
javac 1.8.0_20
C:jdk1.8.0_20>

View Replies View Related

Error - Could Not Find Or Load Main Class GameTester

Oct 29, 2014

I was trying to write my own version of the game SimpleDotCom from Head First Java. I have two files:

Game.java:
package project_01;
public class Game{
byte hitCount = 0;
String result = "miss";
int counter = 0;
String checkGuess(int[] location,int userGuess){

[Code] .....

The two files are in the same directory, "project_01" and the CLASSPATH environment variable is set to ".;".
The game compiled but when I tried launching it with "java GameTester" it returned the error : Could not find or load main class GameTester. I know my game is horrible and probably extremely buggy but I'll fix all the bugs, etc. later, right now I just need to get it to run.

View Replies View Related

Error / Could Not Find Or Load Main Class HelloWorld

Jan 8, 2015

My problem is that I can compile a java HelloWorld program using javac HelloWorld.java but I cannot run the program using java HelloWorld. I didn't create the code it was developed by a professional programmer. My assignment is to compile and run, so that I see the output.

View Replies View Related

Roll Four Sided Die Between 100 And 1000 Times Depending On Input And Display Answer

Oct 29, 2014

I'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.

public class Lab08
{
public static void main(String[] args)
{
int v1 =0, v2 = 0, v3 = 0, v4 = 0;
int n;
char response;
System.out.print("Enter number of rolls (100-1000): ");
 
[Code] ....

View Replies View Related

Runtime Error - Could Not Find Or Load Main File Java

Aug 2, 2014

i have a run time error that could not find or load the main file java .

View Replies View Related

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 View Related

No Main Methods / Applets / Or MIDlets Found In File Error Message

Apr 17, 2015

I am assigned to create a program "Simpletron" that the only language understands it is Simpletron Machine Language or SML. I figured out the most but I get the message "No main methods, applets, or MIDlets found in file" when compiling the program. I pasted my program so that you can see.

//A Simpletron computer simulator */
import javax.swing.*;
import java.text.DecimalFormat;
import java.awt.*;
import java.awt.event.*;

[code]....

View Replies View Related

Using Eclipse To Maintain Java Application - Could Not Find Main Class Error

Sep 3, 2014

I currently use Eclipse to maintain our Java application. I recently upgraded from Java 6 to Java 7. I updated my Eclipse projects to use the Java 7 .jar files. I can run the application from Eclipse via the Run Configuration.

I can also run the Ant build and it completes successfully. When I install the application on my desktop, I receive the "Java Virtual Machine Launcher: Could not find main class..." error. My CLASSPATH is set to ".".

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

Java - Polygon Shrinks Before Rotating

Dec 22, 2014

I have a java program which rotates a rectangular polygon. My program is having a problem. As soon as it starts rotating, it shrinks. The polygon is rotating perfectly though. I am trying but unable to figure out the cause.Main class which has an infinite loop (game loop) to rotate polygon continuously :-Java Code:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

[code]....

View Replies View Related







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