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.
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.
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;
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!”);
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?
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
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();
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
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?
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.
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.
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.
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.
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): ");
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.
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.
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 ".".
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
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;
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.
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: