Home arrow static arrow Java Programming [Archive] - Return Values Help Please
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Return Values Help Please
This topic has 1 reply on 1 page.

Posts:112
Registered: 10/8/03
Return Values Help Please  
Jun 22, 2004 7:10 AM



 
Hi,

I wrote some code to serialize and deserialize an object. It does that all good, but when I try to send the object back to the main file (like in loading a game), it won't let me. The error is "cannot return a value from method whose result type is void" What should I do?
import java.io.*;import java.util.*;import java.awt.*;import java.awt.event.*; public class loadGame extends Panel{	Graphics draw;	Image back; 	public void set(Image a, Graphics b)	{		back = a;		draw = b;	} 	public void draw()	{		System.out.println("|       User loading a game       |");		draw.setColor(Color.black);		draw.fillRect(0,0,500,500);		draw.setColor(Color.green);		draw.drawString("|       User loading a game       |", 100, 150);	} 	void loadSett()	{		try		{			Chara foo = new Chara();			try			{				FileInputStream fis = new FileInputStream("data.bin");				ObjectInputStream ois = new ObjectInputStream(fis);				foo = (Chara)ois.readObject();				fis.close(); 				return foo;			}			catch (IOException ex)			{				ex.printStackTrace();			}		}		catch (ClassNotFoundException e)		{			e.printStackTrace();		}	}}
 

Posts:329
Registered: 1/6/04
Re: Return Values Help Please  
Jun 22, 2004 7:50 AM (reply 1 of 1)



 
How to return a value from a method:
http://java.sun.com/docs/books/tutorial/java/javaOO/methoddecl.html#returnvalue
 
This topic has 1 reply on 1 page.