14 Replies - 11271 Views - Last Post: 26 April 2011 - 08:31 AM Rate Topic: -----

#1 colorlesscliche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-April 11

No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 07:13 PM

I'm working on two programs now in jGRASP, for class, and both of them are coming up with this error after I try to run them. Before I post my code, is there something I'm missing in a JDK pack or is it going to be error in the code itself?
Is This A Good Question/Topic? 0
  • +

Replies To: No main methods, applets, or MIDlets found in file

#2 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: No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 07:20 PM

we will need more details:
- if it is a JApplet it should have a public void init() method
- if it is an Application it should have a public static void main(String[] args) method
Was This Post Helpful? 0
  • +
  • -

#3 colorlesscliche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-April 11

Re: No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 07:36 PM

blic class Student
{

    private String name, address, major;
    private double gpa;

 
    public void student (String name)
	 {
        this.name = name;
    }
     

    public void address (String adress)
	 {
        this.address = address;
    }
     

    public void major(String major)
	 {
        this.major = major;
    }
         

    public String getname()
    {
        return name;
    }
     

    public String getaddress()
    {
        return address;
    }
     

    public String getmajor()
    {
        return major;
    }

     
    public double gpa()
	 {
    Random generator = new Random();

    float gpa = (float) (generator.nextDouble() * 4.0 + 0.5);

    return gpa;
    }

}


Was This Post Helpful? 0
  • +
  • -

#4 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: No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 07:39 PM

So now we see you nice class Student
In which context do you use it ?
What is your question ?
Any problem with it ?
Was This Post Helpful? 0
  • +
  • -

#5 colorlesscliche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-April 11

Re: No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 07:42 PM

View Postpbl, on 24 April 2011 - 07:39 PM, said:

So now we see you nice class Student
In which context do you use it ?
What is your question ?
Any problem with it ?


The problem is I have a tester class as well, and every time I try to run the program I get the 'no main methods, applets, or MIDlets found in file.
Was This Post Helpful? 0
  • +
  • -

#6 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: No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 07:46 PM

so post the offending class and don't less us starve waiting for the class that does not compile :)
I can we fix it if you don't post it ?
Was This Post Helpful? 0
  • +
  • -

#7 colorlesscliche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-April 11

Re: No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 07:59 PM

Let's do another problem I'm sure is correct as far as coding goes.


public class BandBooster
{

	private String name;
	private int boxesSold;

	//a. A constructor that has one parameter—a String containing
	//   the name of the band booster. The constructor should set
	//   boxesSold to 0.
	public BandBooster(String name)
	{
		this.name = name;
		boxesSold = 0;
	}


	//b. A method getName that returns the name of the band
	//   booster (it has no parameters).
	public String getName ()
	{
		return name;
	}
	
	
	//c. A method updateSales that takes a single integer parameter
	//   representing the number of additional boxes of candy sold.
	//   The method should add this number to boxesSold.
	public void updateSales(int numberSold)
	{
		boxesSold += numberSold;
	}
	
	
	//d. A toString method that returns a string containing the name
	//   of the band booster and the number of boxes of candy sold.
	public String toString()
	{
	return name + ": " + boxesSold + " boxes.";
	}
}





And the tester


import java.util.Scanner; 

public class BandBoosterTester
{

	public static void main(String[] args)  
 	{ 
		Scanner scan = new Scanner(System.in); 
   
		System.out.print("Enter the name of the first booster: "); 
		BandBooster booster1 = new BandBooster(scan.nextLine()); 
   
  		System.out.print("Enter the name of the second booster: "); 
  		BandBooster booster2 = new BandBooster(scan.nextLine());  
   
   	for(int week = 1; week <= 3; week++) 
 		{
		  
   		System.out.print("Enter the number of boxes sold by "
			+ booster1.getName() + " during week " + week + ": "); 
   		booster1.updateSales(scan.nextInt()); 
    	   System.out.print("Enter the number of boxes sold by "
			+ booster2.getName() + " during week " + week + ": "); 
   		booster2.updateSales(scan.nextInt()); 
 		}  
   
  		System.out.println("Results after 3 weeks:"); 
  		System.out.println(booster1); 
  		System.out.println(booster2); 
 	} 
}
   
  

Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10366
  • View blog
  • Posts: 38,403
  • Joined: 27-December 08

Re: No main methods, applets, or MIDlets found in file

Posted 24 April 2011 - 08:31 PM

You have to run the BandBoosterTester class, after compiling both files.
Was This Post Helpful? 0
  • +
  • -

#9 colorlesscliche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-April 11

Re: No main methods, applets, or MIDlets found in file

Posted 25 April 2011 - 08:15 AM

View Postmacosxnerd101, on 24 April 2011 - 08:31 PM, said:

You have to run the BandBoosterTester class, after compiling both files.




Which does in fact work. Is this all that needs to be done? I was under the impression for my instructor that I should be running the BandBooster class and not the tester, but if the Tester is what should be running, I suppose my problems are solved. However, is it normal to get the 'no main methods' error on the normal BandBooster class? Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10366
  • View blog
  • Posts: 38,403
  • Joined: 27-December 08

Re: No main methods, applets, or MIDlets found in file

Posted 25 April 2011 - 08:34 AM

If you try to run a class with no main() method, then that is normal. Running a class with a main() method is all you need to do, though. :)
Was This Post Helpful? 0
  • +
  • -

#11 colorlesscliche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-April 11

Re: No main methods, applets, or MIDlets found in file

Posted 25 April 2011 - 09:15 AM

Going back to the Student class issue, this is in the tester, where you find the name, address, and major of a student;

public class StudentTester
{

	public static void main(String[] args)  
 	{ 
		Scanner scan = new Scanner(System.in); 
   
		System.out.print("Enter the name of the first student: "); 
		Student student1 = new Student(scan.nextLine()); 
		System.out.print("Enter the address for the first student: ");
		Student address1 = new Student(scan.nextLine());
		System.out.print("Enter the major of the first student: ");
		Student major1 = new Student(scan.nextLine());
        }




Returns an error at every 'new Student'

symbol  : constructor Student(java.lang.String)
location: class Student
		Student student1 = new Student(scan.nextLine()); 
		                   ^

Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10366
  • View blog
  • Posts: 38,403
  • Joined: 27-December 08

Re: No main methods, applets, or MIDlets found in file

Posted 25 April 2011 - 09:24 AM

This method isn't a constructor:
public void student (String name)  



A constructor has the same name as the class, but not a return type. For example, the following are examples of valid constructors:
public Student(){}

//you can define parameters in your constructor just like other methods
public Student(String name){} 


Was This Post Helpful? 0
  • +
  • -

#13 colorlesscliche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-April 11

Re: No main methods, applets, or MIDlets found in file

Posted 25 April 2011 - 09:40 AM

public class Student
{

    private String name, address, major;
    private double gpa;
	 
	 public static void main(String args[])
	 {
 		  Student student = new Student();
	 }
 
    public Student(String name, String address, String major)
	 {
        this.name = name;
		  this.address = address;
		  this.major = major;
		  gpa();
    }
           

    public String getName()
    {
        return name;
    }
     

    public String getAddress()
    {
        return address;
    }
     

    public String getMajor()
    {
        return major;
    }

     
    public double gpa()
	 {
    Random generator = new Random();

    float gpa = (float) (generator.nextDouble() * 4.0 + 0.5);

    return gpa;
    }

}




It's been changed since the orignal post, but it's still getting an error at the
Student student = new Student();

Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10366
  • View blog
  • Posts: 38,403
  • Joined: 27-December 08

Re: No main methods, applets, or MIDlets found in file

Posted 25 April 2011 - 09:41 AM

You don't define a Student constructor that accepts no parameters.
Was This Post Helpful? 0
  • +
  • -

#15 lbarowski  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 09-December 09

Re: No main methods, applets, or MIDlets found in file

Posted 26 April 2011 - 08:31 AM

A comment on the original question: if you put your files into a project, then you can use "Run" on any file and jGRASP will find any main methods or Applets in the project. It's probably not worth the bother if you just have two files per project though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1