I have permanently set the path of bin of JDK 1.6 in the environment variables of my system. I am able to compile any of my java programs successfully. But when I give command to run the program I am getting an error "could not find or load main class".
When I write the command "set classpath=.;" program runs successfully. I want to know whether I have to set this classpath everytime I run a new progaram. Is there any permanent way to set classpath ?
I creates this simple code (shown below) inside a package of a major opensource code (i.e., openSHA), but when i run it the following error appears. The error mentions a class named "KT_testGmpeForScenarioRupture" that i wrote before and did not run showing exactly the same error.
Code:
package org.opensha.sha.gcim.imr.attenRelImpl; public class KT_Test { private static void main(String args) { int x=4; System.out.println("x is " + x); } }
Error: Could not find or load main class org.opensha.sha.gcim.imr.attenRelImpl.KT_testGmpeF orScenarioRupture
I am using Netbeans as my IDE and I have created a program called Saluton.java
I navigate to the folder holding the class file using the command line under Windows 7 but when I issue the command java Saluton.class I get an error it cannot load or find the main class.
I tried running my program on cmd but it produces the error "could not find or load main class" ...It compiles well but it just doesn't run. Here is my code:
package writedoc; import java.io.FileWriter; import java.io.PrintWriter; import java.io.IOException; public class WriteDoc { public static void main(String[] args) throws IOException { String strDocument="grades.txt";
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 new to this java stuff and when I go to notepad++ and this keeps coming up when I try to compile it: "Error: Could not find or load main class HelloWorld" what it means...
I've just started, so right now I'm reading about declaring enums, the book lists the following code
enum CoffeeSize { //8,10 & 16 are passed to the constuctor BIG(6), HUGE(10), OVERWHELMING(16); CoffeeSize(int ounces){ //constructor this.ounces = ounces;
[Code] .....
I'm assuming that code to be in a same file since enums can be declared within and outside a class, so I saved it into a file named "Coffee.java", it compiles just fine from command line but when I try to execute "java Coffee" it throws "Error: Could not find or load main class Coffee"...
I am trying to understand how package(directory structure) and JAR files work interchangeably. From my understanding JAR is a package file format typically used to aggregate many Java classes. Since many classes are usually contained inside a package, I should be able to create a JAR file from a package, and use them interchangeably. A single JAR file is easier to handle then multiple classes and folders.
To test my understanding of the concept, I am working with the following project structure,
package BookPackage; public class Book{ private String bookname; public Book(String str){ bookname = str; } public String getBookName(){ return bookname; } }
and BookDemo.java contains the following code,
import BookPackage.Book; class BookDemo{ public static void main(String ... args){ Book b = new Book("Lord of the Rings"); System.out.println(b.getBookName()); } }
From the development_directory, I used the following commands to compile and run the project,
...and it compiles and works as expected.Now, I will try to convert the BookPackage folder(package) into single jar file for portability, and I am using the following command to do that,development_directory/ jar -cf bookpkg.jar BookPackage ...this command generates the bookpkg.jar file.
I am going to remove the BookPackage folder to see if bookpkg.jar file really works as a replacement for the BookPackage directory structure.
After removal of BookPackage folder, the development_directory structure looks like this,
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 ".".
I am trying to interact with the command line prompt and script the responses for some config. When asked if user wishes to continue I would like respond yes or no, however I would like this response to be automated without any user interaction. I am able to launch the .exe file however when the command prompt is launched I cannot get any further responses to it.
p Java Code: ublic static void runConfigure(String[] refBox1,String outDir2) throws IOException{ String s = null; try {
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.
I'm learning about the printf command, and when I have it, it is not letting me ad an input. Here is my quick little program:
import java.util.Scanner; public class TestingPrintF { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in);
[Code] ....
The first section works good, but when i move down to the second part it just automatically finishes without letting me enter a phrase.
I am reading the excellent book Algorithms. The author of this book is using his own libraries.
I have downloaded the libraries (it is a file called stdlib.jar) and I've store it in a directory called ~/Downloads(I am using a macbook pro).
Then I have created a project with IntelliJ Idea 14.1 using the default package (as it is the only way for a program to 'see' these libraries).
The program is running inside the ide, but because of the nature of this book, all the included code must be run from the command line.
The problem is that I cannot run for example the Average class from the command line because the system asks for the external library.
Specifically the error is :
I enter : java -cp . Average
and the Error I get is :
Exception in thread "main" java.lang.NoClassDefFoundError: StdIn at Average.main(Average.java:11) Caused by: java.lang.ClassNotFoundException: StdIn at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
[Code] ....
The Average class is the following :
public class Average { public static void main(String[] args) { //Average the numbers on StdIn double sum = 0.0; int cnt = 0;
I have the program written correctly, but it won't execute.
public class Welcome { public static void main(String[] args){ //Display message Welcome to Java! on the console System.out.println("Welcome to Java"); } }
I compiled the code as written below with "javac Welcome", and use the "Class" name "Welcome"
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
I want to read property file in java from command line argument,i.e. if i have some parameters which i have to use separately , i comment the parameters which i don't have to use that time , then uncomment when i have to use.
Is there and way to read the required parameters through command line arguments in java.
This is my first java program,i am using eclipse IDE-----
package day1.example;
public class MyFirstJava {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("hi"); } }
When i saved it,it shows no error.when i run it then a pop-up says "could not find the main class.the program will exit" and in the console it says---
java.lang.UnsupportedClassVersionError: day1/example/MyFirstJava : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source)