6 Replies - 2172 Views - Last Post: 20 September 2012 - 07:17 PM Rate Topic: -----

#1 HardToHandle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 21-November 11

No main methods applets or midlets found in file?

Posted 20 September 2012 - 03:53 PM

Hey guys, I have two files, both of them compile, but when I try to run the one with main in it in jgrasp I get the following message : "No main methods applets or midlets found in file" I have trouble figuring out what I am doing wrong, here is the code of the two files, I hope somebody can help me :)


public interface JFQueue
{
/**
@param s is a string to be added to the queue
@return true if new element is successfully added, false otherwise
*/
	public boolean queue(String s);

/**
deletes the element in the head of first position of the queue
@ return the value of the deleted element
*/
	public String deQueue();
}




import java.util.*;

/*
public interface JFQueue
{

//@param s is a string to be added to the queue
//@return true if new element is successfully added, false otherwise

	public boolean queue(String s);


//deletes the element in the head of first position of the queue
//@ return the value of the deleted element

	public String deQueue();
}
*/




 public class ArrayQueue implements JFQueue
{

public static void main (String[] args)
{
 int maxSize = 8;
 
 ArrayQueue myQueue = new ArrayQueue (maxSize);
 
 myQueue.getSize();
}



private int maxSize; //maximum queue size
int head; //Location of the head or first element
int tail; //Location of the last element
int size; //number of elements in the queue
String[] data; //Array to hold the data


/** Constructor
@param maxSize sets up the maximum queue size
*/
public ArrayQueue(int maxSize)
{
	this.maxSize = maxSize;
	head= 0;
	tail= maxSize - 1;
	size = 0;
	data = new String[maxSize];
	
	
}


// Add an element to the end of the queue
public boolean queue(String s)
{

if(size==0)
{
size++;
head= 0;
tail= (tail + 1) % size;
return true;
}

if(size == maxSize)
{
      expand();  
}

       size ++;
int n = (tail+1) % maxSize;
data[n]= s;
tail=n;
return true;
}

// Remove the element at the front of the queue
public String deQueue()
{
String temp = data[head];

if(temp==null) //Queue is empty!!
{
return null;
}


head = (head + 1) % maxSize;
size --;

if (size <= (0.1 * maxSize)) 
{
	compact(); 
}

return temp;
}

// Return the size of the queue
public int getSize()
{
return size;
}


// The traverse method verify that we correctly implemented the queue
public void traverse()
{
for(int i= 0; i< size; i++)
{
System.out.println ("Array Location " +(head + i)% maxSize +" Value "+
data[(head + i)% maxSize]);
}
}

// Expand the array to double its current size if the queue is full and reallocate the array
private void expand()
{
 int newSize = 2 * size;
 String [] newData = new String [newSize];
 int j = head;
 
 for (int i = 0; i < size; i ++)
 {
  newData[i] = data[i];
  j = (j + 1) % maxSize;
 }
 
 head = 0;
 tail = size - 1;
 size = newSize;
 data = newData;
 
 
}

// Reduce the size of the array to half if it is only 10% full and reallocate the array
private void compact()
{
 double newSize = 0.5 * size;
 String [] newData = new String [newSize];
 int j = head;
 
 for (int i = 0; i < size; i ++)
 {
 newData[i] = data[i];
 j = (j+1) % maxSize;
 }
 
 head = 0;
 tail = size - 1;
 size = newSize;
 data = newData;
 
}





}






This post has been edited by HardToHandle: 20 September 2012 - 03:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: No main methods applets or midlets found in file?

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,658
  • Joined: 20-September 08

Re: No main methods applets or midlets found in file?

Posted 20 September 2012 - 04:14 PM

I suspect you have not set the correct one as your main class (the one with the main method)
Was This Post Helpful? 0
  • +
  • -

#3 HardToHandle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 21-November 11

Re: No main methods applets or midlets found in file?

Posted 20 September 2012 - 04:21 PM

View Postg00se, on 20 September 2012 - 04:14 PM, said:

I suspect you have not set the correct one as your main class (the one with the main method)


How may that be fixed? I think I did it the right way, but I might be wrong, of course.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,658
  • Joined: 20-September 08

Re: No main methods applets or midlets found in file?

Posted 20 September 2012 - 04:39 PM

No idea sorry - i don't use JGrasp. Just answering from first principles
Was This Post Helpful? 1
  • +
  • -

#5 HardToHandle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 21-November 11

Re: No main methods applets or midlets found in file?

Posted 20 September 2012 - 06:31 PM

View Postg00se, on 20 September 2012 - 04:39 PM, said:

No idea sorry - i don't use JGrasp. Just answering from first principles

So let me get this straight : that might be a jgrasp error and not a coding error?
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

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

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: No main methods applets or midlets found in file?

Posted 20 September 2012 - 06:58 PM

It is not a JGrasp error
it is you that didn't inform, correctly, JGrasp about which class has the main() method
so in another world where your project should start
Was This Post Helpful? 1
  • +
  • -

#7 HardToHandle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 21-November 11

Re: No main methods applets or midlets found in file?

Posted 20 September 2012 - 07:17 PM

View Postpbl, on 20 September 2012 - 06:58 PM, said:

It is not a JGrasp error
it is you that didn't inform, correctly, JGrasp about which class has the main() method
so in another world where your project should start

Oh ok, thanks for your help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1