This is a program that prompts a menu using the do-while iteration. If user input is not valid, the menu should be reprompted once. But when I run the code and enter an invalid value, the menu is prompted 3 times.
class Menu {
public static void main(String args[])
throws java.io.IOException {
char choice;
do {
I just wrote a java program with eclipse that has to read many-many inputs from the user. I want to test it, but I really don't want to type it everytime again and again...
Can I just write all inputs in a text file and let eclipse read this file so instead of typing it again and again, Eclipse reads every line whenever it waits for a user input?
/home/t_bmf/Java/HelloWorld/src/helloworld :will contain a .java file /home/t_bmf/Java/HelloWorld/bin :will contain all .class file
Let say a have a code:
package helloworld; public class HelloWorld { public static void main(String[] arg) { System.out.println("Hello World"); } }
a command to compile this even outside the directory /home/t_bmf/Java/HelloWorld/src/helloworld javac -d /home/t_bmf/Java/HelloWorld/bin /home/t_bmf/Java/HelloWorld/src/helloworld/HelloWorld.java
This will generate a directory /home/t_bmf/Java/HelloWorld/bin/helloworld and file inside this is HelloWorld.class
To run this program I must be in directory /home/t_bmf/Java/HelloWorld/bin and using this command:
java helloworld.HelloWorld
Question:
I already how to run the HelloWorld.class, but I must be in helloworld /home/t_bmf/Java/HelloWorld/bin to run it. Is there's a way to run the class even when I am not in directory /home/t_bmf/Java/HelloWorld/bin? Let's say I'm in /home/t_bmf, can I still run the HelloWorld.class?
I've got a problem with my home made game. When I created it as a JFrame application it runs smoothly, but when I tried to convert it to a JApplet the graphic is "lagging". I can see the graphics blinking/flashing .....
Here is the code:
public class FallingBalls extends JApplet implements KeyListener, ActionListener { // VARIABLES // boolean gameOver; boolean win; // Buttons JButton start, pause, restart; // Character "The Runner" (32px x 32 px)
I'm getting back into the swing of things with Java after using I'm asked to utilize a simple GUI in order to take in the starting data, I cannot seem to get this to work. I'm getting this error Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source) at Input.buildPanel(Input.java:53) at Input.<init>(Input.java:27) at InputDemo.main(InputDemo.java:5)
We've got a java web app (running on a Solaris machine with Weblogic) and from time to time it stops working due to this error:
Java Code: java.net.SocketException: Too many open files mh_sh_highlight_all('java');
For what I've read we are somehow exceeding the established limit of file descriptors, and it seems that this may be caused for many reasons, not only open files that we forgot to close.
I am making a list of everything that may consume a file descriptor in the system mentioned above, so I can start reanalyzing the app... if needed, as I don't know if we're wasting them or if the limit is just insufficient.
I have a problem with running my hello world aplication. Here is the code.
public class HelloWorld { public static void mаin(String[] args) { System.out.println("Hello world!"); } }
It compiles fine. But I get an exception when I try to run it.Here is the error message I'm getting:
Exception in thread "main" java.lang.NoSuchMethodException: HelloWorld.main([Ljava.lang.String;) at java.lang.Class.getMethod(Class.java:1605) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
I've been playing around with this for about an hour.
Java Code:
Runtime runTime = Runtime.getRuntime(); try { Process process = runTime.exec("notepad"); } catch (IOException e) { e.printStackTrace(); } mh_sh_highlight_all('java'); So that works. Notepad will open.
However, I'm trying to get other programs to open. Specifically, this program: C:Octave3.2.4_gcc-4.4.0inoctave-3.2.4.exe...However, using that in place of notepad doesn't work. I'm assuming that there is some sort of system variable that explains why simply typing "notepad" works? As if you type notepad into the run box, notepad will open. Soo does that snippet work by going through some sort of system variables?How would I go about opening other programs, such as the one I referenced above.
error: File .ServiceServerImpl.class does not contain type ServiceServerImpl as expected, but type serviceserver.ServiceServerImpl. Please remove the file, or make sure it appears in the correct subdirectory of the class path. error: Class ServiceServerImpl not found. 2 errors "
Here is the source code of the class file. Using Windows 8. I copied the .class file to the rmic.exe 's location later. didn't work either way. It is in a package called "serviceserver"
package serviceserver; import java.rmi.*; import java.rmi.server.*; import java.util.*; public class ServiceServerImpl extends UnicastRemoteObject implements ServiceServer { HashMap serviceList;
i have a program in UNIX directory /home/me/java/src
package bin; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
I have manage to compile it successfully(class file will be in bin directory) using command below: javac -d /home/t_bmf/java/bin HelloWorld.java
My problem now is how would I execute the class in bin directory in UNIX? I already tried different ways on how to execute it as suggested in my internet research The one I tried is this:
java $CLASSPATH:.:bin/HelloWorld but I got this error message: Exception in thread "main" java.lang.NoClassDefFoundError: :/:bin/HelloWorld Caused by: java.lang.ClassNotFoundException: :.:bin.HelloWorld
The below method shows that a JOptionPane should display when the result is null, meaning it has not found what I was trying to look for. However only the if statement that finds the query runs:
public void find(Person person) { String query = "SELECT * from employee WHERE last LIKE'" + lastName + "'"; try { statement = connection.createStatement(); resultSet = statement.executeQuery(query);
I am working on a management gui for a program. I have implemented the start server button. But now I need to get something working so that when I press stop server the javaw.exe process which is running the the other jar file is stopped and ended.
The gui is going to be using a javaw.exe as well and I don't want to end the entire thing.
I just want to end the javaw.exe process that is running the other jar file.
This is my code for starting it:
JButton btnNewButton_2 = new JButton("Start Server"); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Runtime rt = Runtime.getRuntime(); try { Process pr = rt.exec("java -jar DEDServer_release.jar");
[Code] ....
I just need to figure out what to do to stop it now.
When i run a applet file in browser(IE, Chrome, Firefox) it gives a error of security risk and block the application from running. All browser are giving same error. Programme is running correctly in Myeclipse
I've just installed the last Java kit JDK plus netbeans and I've done my first project in Java. It is running perfect from command line<but is is difficult to execute each time from there my tests> but I couldn't run the jar file from windows with double click he jar file even I've spent 3 hour on google to find different methods (registry modifying, control panel/program running in windows, a patch file etc, ) ....
I keep getting the error Admit.java:10 cannot find symbol
import java.util.*; public class Admit { public static void main(String[] args) { sayIntro(); Scanner console = new Scanner(System.in); System.out.println("Information for applicant #1:"); getScore(console); getGPA(console);
[Code] ....
The compiler then reads:
Admit.java:10: error: cannot find symbol score1(ACTScore, SATScore, GPAScore); ^ symbol: variable ACTScore location: class Admit Admit.java:10: error: cannot find symbol
import acm.util.* ; import acm.program.*; import java.awt.* ; class Chap6_ex1 extends ConsoleProgram { public void run() { println("This program displays a randomly schosen card."); int number = rgen.nextInt(1 ,13); int suit = rgen.nextInt(1 ,4);
[Code] ....
I am running the this from a Linux command line , in the cmd first i use :
javac -classpath acm.jar Chap6_ex1.java
end then :
java -cp .:acm.jar Chap6_ex1
The output i m getting after second command is :
Exception in thread "main" acm.util.ErrorException: Cannot determine the main class. at acm.program.Program.main(Program.java:1358)
I know the problem is from the RandomGenerator class in packet acm.util.* but i dont know how to fix the problem . Every other program has worked . What I am missing or how this whole issue of packet importing works when running a java file from cmd ?
I have built a Java app that uses SQLite (sqlite-jdbc-3.8.7.jar). Running the jar file on windows works as expected however, trying to run it on Ubuntu Server 14.04 has turned into quite a task!
I put together a brand new machine in VirtualBox for testing. I installed Java (sudo apt-get install default-jre) and have installed SQLite (sudo apt-get install cl-sql-sqlite3 sqlitebrowser). I created a new sub-directory within my home directory and copied over the jar file. From terminal, I then run the command: sudo java -jar ProductionView.jar and I receive a java.lang.unsatisfiedlinkerror. For troubleshooting, within the app, before making a connection to the db, I have printed out the location of where the db is to be created and it is correct (see attached pic). Is there more that needs to be configured before I can run this app on Ubuntu? I have posted the relevant code below :
(AppDatabasePath() is what is printed in the image...).
I had to make a program that ran a craps game using methods and I keep getting an error ....
Here is my code :
public class CrapsGame { public static void main(String[] args) { System.out.println(playGame()); }//end of main method public static int rollDie(int n){ return (int)(Math.random()*n)+ 1; }//end of rollDie method
[Code] .....
And this is the error im getting
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable roll might not have been initialized at CrapsGame.playGame(CrapsGame.java:29) at CrapsGame.main(CrapsGame.java:4) Java Result: 1
I've seen examples that don't use a separate Runnable Implementation, but Instead Just make a subclass of Thread and override the Thread's runO method. That way,you call the Thread's no--arg constructor when you make the new thread;
Thread t = new Thread(); 1/no Runnable"
Any simple code that demonstrates the same. I haven't fully understood what is said in the text above. I have a hunch that the last line is wrong and it should be Thread t = new <Whatever class extends Thread class and over rides its run method>()
I'm suddenly having trouble running classes from the command line. Previously, things were working. I cant imagine I'm doing anything differently. The sample code is below:
Code:
class HelloWorldTester{ public static void main(String[] args){ System.out.println("Hello World"); } }
Terminal output:
C:UsersmattmanDropboxProgrammingJava>javac helloWorldTest.java C:UsersmattmanDropboxProgrammingJava>java HelloWorldTester.class Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldTester/clas s Caused by: java.lang.ClassNotFoundException: HelloWorldTester.class at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: HelloWorldTester.class. Program will exit.
I have tried to get my dinky little program I wrote to be stored as an executable through Eclipse to no avail. It seems I have tried everything else as well, to no avail. I do not want it to go through command prompt, but rather have it be its own entity. As you can probably tell my knowledge of Java and coding is limited, but always willing to expand.
I am just learning Java and I am have a problem running programs at the command line. I have the following code:
package java_help; import java.io.IOException; class help {
[Code].....
I can run this program in net beans were I originally wrote the program and it runs fine there. I also compile the program at the command line using javac but when I go to run this program I get a error message that it cant find main.