Java fehlermeldung

Angus13

Mitglied
hey leute

was bedeutet :

the public type ... must be defined in its own file

und

the method broadcast(string) is undefined for the type...

weiß das jemand? und wie behebt man den fehler?
 
in dem code ist die fehlermeldung : the public type... must be defined in its own file

import java.net.*;
import java.io.*;
import java.awt.*;
import java.applet.*;

public class chatapplet extends Applet implements Runnable
{
public static final int PORT = 8765;
Socket socket;
DataInputStream in;
PrintStream out;
TextField inputfield;
TextArea outputarea;
Thread thread;

public void init()
{
inputfield = new TextField();
outputarea = new TextArea();
outputarea.setFont( new Font("Dialog", Font.PLAIN, 12));
outputarea.setEditable(false);

this.setLayout(new BorderLayout());
this.add("South", inputfield);
this.add("Center", outputarea);

this.setBackground(Color.lightGray);
this.setForeground(Color.black);
inputfield.setBackground(Color.white);
outputarea.setBackground(Color.white);
}

public void start()
{
try
{
socket = new Socket(this.getCodeBase().getHost(), PORT);
in = new DataInputStream(socket.getInputStream());
out = new PrintStream(socket.getOutputStream());
} catch (IOException e)
{
this.showStatus(e.toString());
say("Verbindung zum Server fehlgeschlagen!");
System.exit(1);
}

say("Verbindung zum Server aufgenommen...");

if (thread == null)
{
thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
}


public void stop()
{
try
{
socket.close();
} catch (IOException e)
{
this.showStatus(e.toString());
}

if ((thread !=null) && thread.isAlive())
{
thread.stop();
thread = null;
}
}


public void run()
{
String line;

try
{
while(true)
{
line = in.readLine();
if(line!=null)
outputarea.appendText(line+'\n' );
}
} catch (IOException e) { say("Verbindung zum Server abgebrochen"); }
}


public boolean action(Event e, Object what)
{
if (e.target==inputfield)
{
String inp=(String) e.arg;

out.println(inp);
inputfield.setText("");
return true;
}

return false;
}


public void say(String msg)
{
outputarea.appendText("*** "+msg+" ***\n");
}
}
 
Code:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.applet.*;

public class chatapplet extends Applet implements Runnable
{
	public static final int PORT = 8765;
	Socket socket;
	DataInputStream in;
	PrintStream out;
	TextField inputfield;
	TextArea outputarea;
	Thread thread;

	public void init()
	{
		inputfield = new TextField();
		outputarea = new TextArea();
		outputarea.setFont( new Font("Dialog", Font.PLAIN, 12));
		outputarea.setEditable(false);

		this.setLayout(new BorderLayout());
		this.add("South", inputfield);
		this.add("Center", outputarea);

		this.setBackground(Color.lightGray);
		this.setForeground(Color.black);
		inputfield.setBackground(Color.white);
		outputarea.setBackground(Color.white);
	}

	public void start()
	{
		try
		{
			socket = new Socket(this.getCodeBase().getHost(), PORT);
			in = new DataInputStream(socket.getInputStream());
			out = new PrintStream(socket.getOutputStream());
		} catch (IOException e)
		{
			this.showStatus(e.toString());
			say("Verbindung zum Server fehlgeschlagen!");
			System.exit(1);
		}

		say("Verbindung zum Server aufgenommen...");

		if (thread == null)
		{
			thread = new Thread(this);
			thread.setPriority(Thread.MIN_PRIORITY);
			thread.start();
		}
	}


	public void stop()
	{
		try
		{
			socket.close();
		} catch (IOException e)
		{
			this.showStatus(e.toString());
		}

		if ((thread !=null) && thread.isAlive())
		{
			thread.stop();
			thread = null;
		}
	}


	public void run()
	{
		String line;

		try
		{
			while(true)
			{
				line = in.readLine();
				if(line!=null)
					outputarea.appendText(line+'\n' );
			}
		} catch (IOException e) { say("Verbindung zum Server abgebrochen"); }
	}


	public boolean action(Event e, Object what)
	{
		if (e.target==inputfield)
		{
			String inp=(String) e.arg;

			out.println(inp);
			inputfield.setText("");
			return true;
		}

		return false;
	}


	public void say(String msg)
	{
		outputarea.appendText("*** "+msg+" ***\n");
	}
}
 
Wie? Also wenn ich deinen Code kopiere und in die Klasse chatapplet kopiere bekomme ich keinen Compilererror oder sonstiges. Ich kann die Anwendung starten. Gut mit anderen Fehlern aber das ist eine andere Geschichte.

Also die erste Fehlermeldung ist ziemlich kurz kann aus der Beschreibung erstmal auf nichts schließen. Die zweite sieht für mich so aus als würde irgendeiner benutzten Klasse die die Methode broadcast(string) einer Klasse aufruft die Klasse oder die dependency fehlen. Hierfür ist nunmal ein Stacktrace oder die genaue Fehlermeldung wichtig.

Wo bekommst du denn die Fehler angezeigt? In deiner IDE? Beim starten?
 
Zurück