9 Replies - 1018 Views - Last Post: 22 November 2009 - 09:36 AM Rate Topic: -----

#1 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 21 November 2009 - 05:48 AM

Hey I have this program:
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import javax.swing.*;
 
public class Telephone {
	
	public Telephone()
	{
		JPanel speakerPanel = new JPanel();	// creats the speakerPanel
		speakerPanel.setLayout(new BorderLayout()); // sets the layout for the speakerPanel
		speakerPanel.add(new JLabel("Speaker:"), BorderLayout.NORTH);
		JTextArea speakerField = new JTextArea(10, 25);
		speakerField.add(speakerField, BorderLayout.CENTER);
		String keyLabels = "123456789*0#";
		JPanel keyPanel = new JPanel();
		keyPanel.setLayout(new GridLayout(4, 3));
		for(int i=0; i< keyLabels.length(); i++)
		{
			final String label = keyLabels.substring(i, i+1);
			JButton keyButton = new JButton(label);
			keyPanel.add(keyButton);
			keyButton.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event) 
				{
					connect.dial(label);
				}
			});
			
		}
		
		final JTextArea microphoneField = new JTextArea(10, 25);
		JButton speechButton = new JButton("Send Speech");
		speechButton.addActionListener(new ActionListener()
		{

			public void actionPerformed(ActionEvent event) 
			{
				connect.record(microphoneField.getText());
				microphoneField.setText("");
			}
		});
		
		JButton hangupButton = new JButton("hangup");
		hangupButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				connect.hangup();				
			}
		});
		
		JPanel buttonPanel = new JPanel();
		buttonPanel.add(speechButton);
		buttonPanel.add(hangupButton);
		
		JPanel microphonePanel = new JPanel();
		microphonePanel.setLayout(new BorderLayout());
		microphonePanel.add(new JLabel("Microphone:"), BorderLayout.NORTH);
		microphonePanel.add(microphoneField, BorderLayout.CENTER);
		microphonePanel.add(buttonPanel, BorderLayout.SOUTH);
		
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(speakerPanel, BorderLayout.NORTH);
		frame.add(keyPanel, BorderLayout.CENTER);
		frame.add(microphonePanel, BorderLayout.SOUTH);
		
		frame.pack();
		frame.setVisible(true);
	}
	
	public void speak(String output)
	{
		speakerField.setText(output);
	}
	
	public void run(Connection c)
	{
		connect = c;
	}
	
	private JTextArea speakerField;
	private Connection connect;
	
}


And I get the fail in the as in the topic, I think I know what the problems is.
is it not that i need something like a main method to make it run:
public static void main(String[] args)


but where to put the method and what to write I'm not certain about, should I put the entire program in the main method ? or something else

Is This A Good Question/Topic? 0
  • +

Replies To: I get a: "Exception in thread "main" java.lang.NoSuchMe

#2 AbuJaFaR  Icon User is offline

  • D.I.C Regular

Reputation: 13
  • View blog
  • Posts: 330
  • Joined: 13-December 07

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 21 November 2009 - 05:57 AM

When I compiled I got 3 errors.But anyway.

You can create a new class called TelephoneTest or something.
You can put there the main method and just initiate a telephone object.

Telephone t1=new Telephone();


Since all your code is in the constructor of Telephone class.
Make sure you place the new class in the same directory. :)
Was This Post Helpful? 0
  • +
  • -

#3 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 21 November 2009 - 06:21 AM

View PostAbuJaFaR, on 21 Nov, 2009 - 04:57 AM, said:

When I compiled I got 3 errors.But anyway.

You can create a new class called TelephoneTest or something.
You can put there the main method and just initiate a telephone object.

Telephone t1=new Telephone();


Since all your code is in the constructor of Telephone class.
Make sure you place the new class in the same directory. :)

Thanks about that I will try it out and the return to tell the effects, what are the 3 erros you get ?
Was This Post Helpful? 0
  • +
  • -

#4 AbuJaFaR  Icon User is offline

  • D.I.C Regular

Reputation: 13
  • View blog
  • Posts: 330
  • Joined: 13-December 07

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 21 November 2009 - 06:24 AM

Methods:

-dial
-record
-hangup

Just compiled it, I didnt try to fix the errors.Try what I said with main and tell me :)
Was This Post Helpful? 0
  • +
  • -

#5 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 21 November 2009 - 06:30 AM

View PostAbuJaFaR, on 21 Nov, 2009 - 05:24 AM, said:

Methods:

-dial
-record
-hangup

Just compiled it, I didnt try to fix the errors.Try what I said with main and tell me :)

Yearh I get those now but also on the main method don't know whats wrong there neither:

Quote

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method dial(String) is undefined for the type Connection
The method record(String) is undefined for the type Connection
The method hangup() is undefined for the type Connection

at Telephone.<init>(Telephone.java:27)
at telephoneTester.main(telephoneTester.java:5)

at get an error on;
	public void actionPerformed(ActionEvent event) 
	{
		   connect.dial(label);  
	}


public void actionPerformed(ActionEvent event) 
			{
				connect.record(microphoneField.getText());
				microphoneField.setText("");
			}

public void actionPerformed(ActionEvent event)
			{
				connect.hangup();				
			}

public static void main(String[] args)
	{
		Telephone t1 = new Telephone();
		
	}

Was This Post Helpful? 0
  • +
  • -

#6 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 22 November 2009 - 02:43 AM

Can anyone plz tell me why the connect.dial won't compile, I simply can't finde the error
Was This Post Helpful? 0
  • +
  • -

#7 AbuJaFaR  Icon User is offline

  • D.I.C Regular

Reputation: 13
  • View blog
  • Posts: 330
  • Joined: 13-December 07

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 22 November 2009 - 05:06 AM

I cant find any method dial or record or hangup.
I dont know where did you find them.

http://java.sun.com/...Connection.html
Was This Post Helpful? 0
  • +
  • -

#8 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 22 November 2009 - 07:41 AM

View PostAbuJaFaR, on 22 Nov, 2009 - 04:06 AM, said:

I cant find any method dial or record or hangup.
I dont know where did you find them.

http://java.sun.com/...Connection.html

I also thinks that is the problem, they just occur in the example I'm programming after
Was This Post Helpful? 0
  • +
  • -

#9 Dophert  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 60
  • Joined: 19-October 09

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 22 November 2009 - 08:40 AM

You don't have a main method. You need a

public static void main(String[] argsv)


Like you said yourself.
Was This Post Helpful? 0
  • +
  • -

#10 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: I get a: "Exception in thread "main" java.lang.NoSuchMe

Posted 22 November 2009 - 09:36 AM

View PostDophert, on 22 Nov, 2009 - 07:40 AM, said:

You don't have a main method. You need a

public static void main(String[] argsv)


Like you said yourself.

thanks now I'm down on three errors:
connect.dial
connect.recorde
connect.hangup
I think that I'll just have to ask my instructor yet I thinks it is strange that they put an example in the book that doesn't work
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1