Error: Could not find the main class: Class1. Program will exit.

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 3411 Views - Last Post: 31 December 2011 - 06:22 AM Rate Topic: -----

#1 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 03:31 PM

i made a program but when other people and myself(another Computer) downloaded it i got this error,
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.
Is This A Good Question/Topic? 0
  • +

Replies To: Error: Could not find the main class: Class1. Program will exit.

#2 Faitas  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 44
  • Joined: 04-November 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 03:39 PM

Okay. Can you show me the program header? public class [class_name] and can you say waht is the original program name? Something like this:

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.
Was This Post Helpful? 0
  • +
  • -

#3 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 03:45 PM

View PostFaitas, on 30 December 2011 - 03:39 PM, said:

Okay. Can you show me the program header? public class [class_name] and can you say waht is the original program name? Something like this:

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

View PostFaitas, on 30 December 2011 - 03:39 PM, said:

Okay. Can you show me the program header? public class [class_name] and can you say waht is the original program name? Something like this:

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?
Was This Post Helpful? 0
  • +
  • -

#4 Faitas  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 44
  • Joined: 04-November 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 03:48 PM

No, you can change your Class1 to MessageBoxCreator, and main file name MessageBoxCreator.
Was This Post Helpful? 0
  • +
  • -

#5 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 03:57 PM

View PostFaitas, on 30 December 2011 - 03:48 PM, said:

No, you can change your Class1 to MessageBoxCreator, and main file name MessageBoxCreator.


View PostFaitas, on 30 December 2011 - 03:48 PM, said:

No, you can change your Class1 to MessageBoxCreator, and main file name MessageBoxCreator.


Quote

could not find that main class: MessageBoxCreator. Program will exit.

Attached File(s)


This post has been edited by JavaAmatureProgrammer: 30 December 2011 - 03:58 PM

Was This Post Helpful? 0
  • +
  • -

#6 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 04:34 PM

View PostJavaAmatureProgrammer, on 30 December 2011 - 03:57 PM, said:

View PostFaitas, on 30 December 2011 - 03:48 PM, said:

No, you can change your Class1 to MessageBoxCreator, and main file name MessageBoxCreator.


View PostFaitas, on 30 December 2011 - 03:48 PM, said:

No, you can change your Class1 to MessageBoxCreator, and main file name MessageBoxCreator.


Quote

could not find that main class: MessageBoxCreator. Program will exit.

Attached File(s)

  • Attached File  HELP.zip (2.63K)
    Number of downloads: 36

Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,716
  • Joined: 19-March 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 04:35 PM

A public class has a name ("Name"), and it must be contained in a file called "Name.java".

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.
Was This Post Helpful? 0
  • +
  • -

#8 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 04:45 PM

View Postjon.kiparsky, on 30 December 2011 - 04:35 PM, said:

A public class has a name ("Name"), and it must be contained in a file called "Name.java".

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

Was This Post Helpful? 0
  • +
  • -

#9 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,716
  • Joined: 19-March 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 04:50 PM

Yeah. Compile it and run it.

> javac MessageBoxCreator.java
> javac MessageBoxCreator


Opens a window with some text in it.

Were you trying to run MainClass?
Was This Post Helpful? 0
  • +
  • -

#10 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 04:54 PM

View Postjon.kiparsky, on 30 December 2011 - 04:50 PM, said:

Yeah. Compile it and run it.

> 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)?
Was This Post Helpful? 0
  • +
  • -

#11 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,716
  • Joined: 19-March 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 04:59 PM

So the problem is that you're trying to create a jar, and it's not working?


Read this and see if that helps.
Was This Post Helpful? 0
  • +
  • -

#12 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 05:02 PM

View Postjon.kiparsky, on 30 December 2011 - 04:59 PM, said:

So the problem is that you're trying to create a jar, and it's not working?


Read this and see if that helps.


That didn't Help.
Was This Post Helpful? -1
  • +
  • -

#13 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,716
  • Joined: 19-March 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 05:03 PM

I posted it three minutes ago. You haven't read it yet.

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

Was This Post Helpful? 1
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 05:05 PM

Put that one in your Favorites

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

Was This Post Helpful? 0
  • +
  • -

#15 JavaAmatureProgrammer  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 94
  • Joined: 28-December 11

Re: Error: Could not find the main class: Class1. Program will exit.

Posted 30 December 2011 - 05:13 PM

View Postpbl, on 30 December 2011 - 05:05 PM, said:

Put that one in your Favorites

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?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2