18 Replies - 1935 Views - Last Post: 31 December 2011 - 06:22 AM
#1
Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 03:31 PM
i coded this program using eclipse and exported it into a jar file using eclipse, i even picked class1 as the main class. does anyone know what would be causing this error, The program works perfectly fine on the computer i coded it on.
Replies To: Error: Could not find the main class: Class1. Program will exit.
#2
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 03:39 PM
My program name is ProgramName, and code is:
public class ProgramName {
public static void main(String[] args) {
}
}
Your class and program name should be uppercase.
#3
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 03:45 PM
Faitas, on 30 December 2011 - 03:39 PM, said:
My program name is ProgramName, and code is:
public class ProgramName {
public static void main(String[] args) {
}
}
Your class and program name should be uppercase.
JFrame Main Class
public class Class1 {
public static void main(String[] args){
SecondClass/Gui
public class MainClass extends JFrame {
Program Name is: MessageBox Creator
Faitas, on 30 December 2011 - 03:39 PM, said:
My program name is ProgramName, and code is:
public class ProgramName {
public static void main(String[] args) {
}
}
Your class and program name should be uppercase.
So for my jframe/mainclass
Change Class1 To MessageBox Creator?
#4
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 03:48 PM
#5
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 03:57 PM
Faitas, on 30 December 2011 - 03:48 PM, said:
Faitas, on 30 December 2011 - 03:48 PM, said:
Quote
Attached File(s)
-
MessageBox_Creator.zip (3.34K)
Number of downloads: 15
This post has been edited by JavaAmatureProgrammer: 30 December 2011 - 03:58 PM
#6
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 04:34 PM
JavaAmatureProgrammer, on 30 December 2011 - 03:57 PM, said:
Faitas, on 30 December 2011 - 03:48 PM, said:
Faitas, on 30 December 2011 - 03:48 PM, said:
Quote
Attached File(s)
-
HELP.zip (2.63K)
Number of downloads: 17
#7
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 04:35 PM
For example
public class Foo {
}
must appear in a file called Foo.java
For the moment, take it as given that your class name and file name must align in this way to run. So if you have a public class called Class1, it must be in a file called Class1.java. (but you really should use a name that describes the purpose of the class, never something like "Class1")
To start a Java program, you have to call a class which has a main method. If class Foo does not have a main method, then
>java Foo
will exit with an error.
I'm not sure exactly what it is you're trying to do, but it's going to be pretty difficult to sort out your code if all we have are class headers.
#8
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 04:45 PM
jon.kiparsky, on 30 December 2011 - 04:35 PM, said:
For example
public class Foo {
}
must appear in a file called Foo.java
For the moment, take it as given that your class name and file name must align in this way to run. So if you have a public class called Class1, it must be in a file called Class1.java. (but you really should use a name that describes the purpose of the class, never something like "Class1")
To start a Java program, you have to call a class which has a main method. If class Foo does not have a main method, then
>java Foo
will exit with an error.
I'm not sure exactly what it is you're trying to do, but it's going to be pretty difficult to sort out your code if all we have are class headers.
import java.awt.FlowLayout;
import java.awt.TextArea;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.io.*;
public class MainClass extends JFrame {
private JButton saveButton;
private TextArea textArea = new TextArea("msgbox(\"text\"),16,(\"tile\")", 3,50, TextArea.SCROLLBARS_VERTICAL_ONLY);
public MainClass(){
super("MessageBox Creator");
setLayout( new FlowLayout());
add(textArea);
saveButton = new JButton("Create");
add( saveButton );
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
try {
FileWriter outFile = new FileWriter("messageBox.vbs");
PrintWriter out = new PrintWriter(outFile);
out.write(textArea.getText());
out.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
)
;
}
;
{
}
{
;
}
}
import javax.swing.JFrame;
public class MessageBoxCreator {
public static void main(String[] args){
MainClass creationFrame = new MainClass();
creationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
creationFrame.setSize(400,143);
creationFrame.setVisible(true);
}
}
I'm Exporting The Jar File As MessageBoxCreator
And Choosing The Main Class As, MessageBoxCreator.
I DON'T UNDERSTAND!!!!!!!!!!!!
Any Suggestions Now?
This post has been edited by JavaAmatureProgrammer: 30 December 2011 - 04:51 PM
#9
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 04:50 PM
> javac MessageBoxCreator.java
> javac MessageBoxCreator
Opens a window with some text in it.
Were you trying to run MainClass?
#10
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 04:54 PM
jon.kiparsky, on 30 December 2011 - 04:50 PM, said:
> javac MessageBoxCreator.java
> javac MessageBoxCreator
Opens a window with some text in it.
Were you trying to run MainClass?
No, it works perfect on my computer, but i posted it in share projects and no one can open it, i cant even open it on my laptop(another computer)?
#13
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 05:03 PM
I'm going to go drink beer and play music. I think you'll probably be able to create an executable jar from clear instructions, and you have clear instructions, so I think I'm not needed here.
This post has been edited by jon.kiparsky: 30 December 2011 - 05:05 PM
#14
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 05:05 PM
http://docs.oracle.c...asicsindex.html
and read and understand it
You can't have read jon.kiparsky's link in 3 minutes
This post has been edited by pbl: 30 December 2011 - 05:07 PM
#15
Re: Error: Could not find the main class: Class1. Program will exit.
Posted 30 December 2011 - 05:13 PM
pbl, on 30 December 2011 - 05:05 PM, said:
http://docs.oracle.c...asicsindex.html
and read and understand it
You can't have read jon.kiparsky's link in 3 minutes
I'm honestly reading these, But I'm not understanding this at all.
I went from not being able to open a jar file that is already created to getting links about making jar files?
|
|

New Topic/Question
Reply



MultiQuote



|