• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program executes in Command Prompt, but not in netbeans  RSS feed

 
Sachin H. Gupta
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the code in netbeans and executed it, but I getting an error
"Error: Could not find or load main class CaesarCipher
Java Result: 1"
When I am running it in command prompt, it executes successfully. Please tell me why I am getting this error and the remedy.



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import java.io.*;
/**
*
* @author Administrator
*/
class CaesarCipher {

private static BufferedReader buf;



public static void main(String[] args) {
buf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("ex");
CaesarCipher obj = new CaesarCipher();
obj.showMenu();
}

void showMenu(){
System.out.println("1. Encrypt");
System.out.println("2. Decrypt");
System.out.println("3. Exit");
System.out.println("\n Enter your choice");
int ch=0;
try {
ch = Integer.parseInt(buf.readLine());
} catch (Exception e) {
System.out.println("Please Enter a number");
}
switch(ch){
case 1: encrypt();
break;
case 2: decrypt();
break;
case 3: System.exit(0);
default: System.out.println("please enter a valid choice");

}

}

void encrypt(){
System.out.println("Enter the Plain text:");
StringBuilder input=null;
try {
input = new StringBuilder(buf.readLine());

} catch (Exception e) {
}
for (int i = 0; i < input.length(); i++) {
System.out.println((int)input.charAt(i));
}
}

void decrypt(){

}




}

 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please remember the code button.
The error has nothing to do with your code. It is that somehow you have instructed NetBeans to use a different class as an entry point from the one with the main method. I can’t remember how you change that option.
 
Sachin H. Gupta
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I copied the program from its current project(Cryptography) to another project and it ran successfully.
I deleted the project Cryptography(including sources), and started a new project named cryptography.
Copied the file again to the project, but it does not executes even now.
The only thing that resolved the problem was
1. delete existing project
2. restart netbeans
3. create new project named cryptography(or any other) and copy files to it.

Please share any information regarding the problem if you know why exactly it is happening.
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!