Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

[java] NoSuchMethodError

Started by Tanax 9 replies 2.1k views
Original Post
Tanax
Tanax
Hey! I have a really weird error. I've read about the error on Java's API, but I have no idea why this error is thrown in my case.

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: FileManager.choose()Ljava/lang/String;
    at Logic.saveFile(Logic.java:67)
    at GUI.actionPerformed(GUI.java:390)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1220)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1261)
    at java.awt.Component.processMouseEvent(Component.java:6041)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    at java.awt.Component.processEvent(Component.java:5806)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4413)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4243)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2440)
    at java.awt.Component.dispatchEvent(Component.java:4243)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)



GUI ActionPerformed at 690:

else if(option.equals("Export customers"))
			{
				
				if(this.logic.hasCustomers())
				{
					
					try
					{
						
						this.logic.saveFile();
						
					}
					
					catch(IOException e)
					{
						
						JOptionPane.showMessageDialog(null, "Something went wrong");
						
					}
					
				}
				
				else JOptionPane.showMessageDialog(null, "There are no customers yet!");
				
			}



Logic at 67:

public void saveFile() throws IOException
	{
		
		this.custs = this.convertCustomers();
		String filename = this.filemanager.choose();
		
		if(filename != "")
		{
			
			this.filemanager.file(filename).write(this.custs);
		
		}
		
	}
	
	public Customer[] convertCustomers()
	{
		
		Customer[] custs = new Customer[this.customers.size()];
		
		for(int i = 0; i < this.customers.size(); i++)
		{
			
			custs = (Customer) this.customers.get(i);
			
		}
		
		return custs;
		
	}



And finally, FileManager's choose() function:

public String choose()
	{
		
		int status = this.chooser.showSaveDialog(null);
		String filename = "";
		
		if(status == JFileChooser.APPROVE_OPTION)
		{
			
			filename = this.chooser.getSelectedFile().getAbsolutePath();
			
		}
		
		return filename;
		
	}



Anyone can see the problem here? [Edited by - Tanax on May 17, 2009 10:13:03 AM]
Glass_Knife
Glass_Knife
The error is saying that Java can not find the method. I am assuming that you have all the code and compiled it. Is the FileManager part of a library in another *.jar file?

It would also help if you post the complete file for the FileManager and the Logic classes.

Anyone else have any thoughts?
Lord_Evil
Lord_Evil
Seems like the classpath is not set properly.

How do you start the app?
Do you use jars? If so, is FileManager in another jar file than Logic, like Glass_Knife suggested? Did you add that jar file to the class path?

If you don't use jars, where in your filesystem (relative to the project's root directory) are Logic.class and FileManager.class located after compilation? What packages did you put them into?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Tanax
Tanax
Quote:
Original post by Glass_Knife
The error is saying that Java can not find the method. I am assuming that you have all the code and compiled it. Is the FileManager part of a library in another *.jar file?

It would also help if you post the complete file for the FileManager and the Logic classes.

Anyone else have any thoughts?


FileManager is just a class that I've built myself, and it's located in the same dir as all the other java classes that I've built(including the program class that contains the mainmethod).

Logic class:
import java.util.*;import java.io.*;public class Logic{		// FileManager	private FileManager filemanager;		// Customers	private List customers;		// Customer	private Customer customer;	private int id;	private long nr;	private String name;		// Account	private int acc;	private int accLimit;	private int accBalance;	private String accType;	private double totalInterest = 0.0;	private String accTransactions;		private Customer[] custs;		/**	* Beskrivning: Initierar klassen	*	* @params void	* @return void	**/	public Logic()	{				this.customers = new ArrayList();		this.filemanager = new FileManager();			}		public void openFile() throws IOException, ClassNotFoundException	{				String filename = this.filemanager.open();		if(filename != "")		{						this.custs = this.filemanager.file(filename).read();					}			}		public void saveFile() throws IOException	{				this.custs = this.convertCustomers();		String filename = this.filemanager.choose();				if(filename != "")		{						this.filemanager.file(filename).write(this.custs);				}			}		public Customer[] convertCustomers()	{				Customer[] custs = new Customer[this.customers.size()];				for(int i = 0; i < this.customers.size(); i++)		{						custs = (Customer) this.customers.get(i);					}				return custs;			}		/**	* Beskrivning: Laddar en kund baserat på id i arrayen	*	* @params int id	* @return void	**/	public void load(int id)	{				this.id = id;		this.customer = (Customer) this.customers.get(id);			}		/**	* Beskrivning: Laddar ett konto baserat på kontonummer	*	* @params int account	* @return void	**/	public void loadAcc(int account)	{				this.acc = account;		this.accType = this.getAccountType();		this.accLimit = this.getAccountLimit();		this.accBalance = this.getAccountBalance();			}		/**	* Beskrivning: Returnerar objektet på den laddade kunden	*	* @params void	* @return (Customer) this.customer	**/	public Customer get()	{				return this.customer;			}		/**	* Beskrivning: Returnerar kontonumret på det laddade kontot	*	* @params void	* @return (int) this.acc	**/	public int getAcc()	{				return this.acc;			}		/**	* Beskrivning: Returnerar id't på den laddade kunden	*	* @params void	* @return (int) this.id	**/	public int id()	{				return this.id;			}		/**	* Beskrivning: Returnerar personnumret på den laddade kunden	*	* @params void	* @return (long) this.nr	**/	public long getNumber()	{				this.nr = this.customer.getCustomerNumber();		return this.nr;			}		/**	* Beskrivning: Returnerar namnet på den laddade kunden	*	* @params void	* @return (String) this.name	**/	public String getName()	{				this.name = this.customer.getCustomerName();		return this.name;			}		/**	* Beskrivning: Returnerar kontotyp på det laddade kontot	*	* @params void	* @return (String) this.accType	**/	public String getAccType()	{				return this.accType;			}		/**	* Beskrivning: Returnerar kontogräns på det laddade kontot	*	* @params void	* @return (int) this.accLimit	**/	public int getAccLimit()	{				return this.accLimit;			}		/**	* Beskrivning: Returnerar kontosaldo på det laddade kontot	*	* @params void	* @return (int) this.accBalance	**/	public int getAccBalance()	{				this.accBalance = this.getAccountBalance();		return this.accBalance;			}		/**	* Beskrivning: Returnerar kontotransaktioner på det laddade kontot	*	* @params void	* @return (String) this.accTransactions	**/	public String getAccTransactions()	{				this.accTransactions = this.getAccountTransactions();		return this.accTransactions;			}		/**	* Beskrivning: Lägger till en kund i systemet	*	* @params (int) number	* @params (String) name	* @return (Boolean) true or false	**/	public Boolean addCustomer(long number, String name)	{				if(name == "" || number == 0)		{						return false;					}				Customer cust;		Iterator iterator = this.customers.iterator();				int invalid = 0;					while(iterator.hasNext())		{							cust = (Customer) iterator.next();			long custNr = cust.getCustomerNumber();			if(custNr == number)			{									invalid = 1;								}						}					if(invalid == 1)		{							return false;						}					Customer person = new Customer(name, number);		this.customers.add(person);				return true;			}		/**	* Beskrivning: Returnerar alla kunder som finns i systemet	*	* @params void	* @return (String) returnValue	**/	public String getCustomers()	{				String returnValue = "";		Customer cust;		Iterator iterator = customers.iterator();		int i = 0;					while(iterator.hasNext())		{							cust = (Customer) iterator.next();			long custNr = cust.getCustomerNumber();			String custName = cust.getCustomerName();						returnValue = returnValue + i + "\t\t" + custName + "\t\t" + custNr + "\n";						i++;						}				return returnValue;			}		/**	* Beskrivning: Kollar om det finns en kund med det specifierade id't	*	* @params (int) ID	* @return (Boolean) true or false	**/	public Boolean isCustomer(int ID)	{				Customer customer = (Customer) this.customers.get(ID);		if(customer instanceof Customer)		{						return true;					}				return false;			}		/**	* Beskrivning: Ändrar namnet på den laddade kunden	*	* @params (String) text	* @return void	**/	public void editCustomer(String text)	{				this.customer.setName(text);			}		/**	* Beskrivning: Returnerar en sträng med alla sparkonton som den laddade kunden har	*	* @params void	* @return (String) append	**/	public String getSavingsAccounts()	{				Map accounts = this.customer.getSavingsAccounts();		SavingsAccount currentAcc;		String append = "";		this.accBalance = 0;				Map.Entry account;    	Iterator allSavingsAccounts = accounts.entrySet().iterator();    	    	while(allSavingsAccounts.hasNext())    	{    		    		account = (Map.Entry) allSavingsAccounts.next();    		currentAcc = (SavingsAccount) account.getValue();    		this.loadAcc(currentAcc.getAccountNumber());    		    		append = append + this.accType + "\t\t" + this.acc + "\t\t" + this.accBalance + "\n";    		    	}    	    	return append;			}		/**	* Beskrivning: Returnerar en sträng med alla kreditkontot som den laddade kunden har	*	* @params void	* @return (String) append	**/	public String getCreditAccounts()	{				Map accounts = this.customer.getCreditAccounts();		CreditAccount currentAcc;		String append = "";		this.accBalance = 0;				Map.Entry account;    	Iterator allCreditAccounts = accounts.entrySet().iterator();    	    	while(allCreditAccounts.hasNext())    	{    		    		account = (Map.Entry) allCreditAccounts.next();    		currentAcc = (CreditAccount) account.getValue();    		this.loadAcc(currentAcc.getAccountNumber());    		    		append = append + this.accType + "\t\t" + this.acc + "\t\t" + this.accBalance + "\n";    		    	}    	    	return append;			}		/**	* Beskrivning: Skapar ett konto åt den laddade kunden baserat på specifierad kontotyp	*	* @params (int) type	* @return (int) number	**/	public int createAccount(int type)	{				int number = this.customer.createNewAccount(type);		return number;			}		/**	* Beskrivning: Returnerar kontotyp på det laddade kontot	*	* @params void	* @return (String) acc.getAccountType()	**/	public String getAccountType()	{				int accType = this.customer.getAccountType(this.acc);		if(accType == 1)		{						SavingsAccount acc = this.customer.getSavingsAccount(this.acc);			return acc.getAccountType();					}				CreditAccount acc = this.customer.getCreditAccount(this.acc);		return acc.getAccountType();			}		/**	* Beskrivning: Returnerar kontosaldo	*	* @params void	* @return (int) acc.getAccountBalance()	**/	public int getAccountBalance()	{				int accType = this.customer.getAccountType(this.acc);		if(accType == 1)		{						SavingsAccount acc = this.customer.getSavingsAccount(this.acc);			return acc.getAccountBalance();					}				CreditAccount acc = this.customer.getCreditAccount(this.acc);		return acc.getAccountBalance();			}		/**	* Beskrivning: Returnerar kontotransaktioner	*	* @params void	* @return (String) transactions	**/	public String getAccountTransactions()	{				String transactions = "";				int accType = this.customer.getAccountType(this.acc);		if(accType == 1)		{						SavingsAccount acc = this.customer.getSavingsAccount(this.acc);			transactions = acc.getLatestTransactions();						return transactions;					}				CreditAccount acc = this.customer.getCreditAccount(this.acc);		transactions = acc.getLatestTransactions();				return transactions;			}		/**	* Beskrivning: Returnerar kontogräns	*	* @params void	* @return (int) acc.getAccountLimit()	**/	public int getAccountLimit()	{				int accType = this.customer.getAccountType(this.acc);		if(accType == 1)		{						SavingsAccount acc = this.customer.getSavingsAccount(this.acc);			return acc.getAccountLimit();					}				CreditAccount acc = this.customer.getCreditAccount(this.acc);		return acc.getAccountLimit();			}		/**	* Beskrivning: Lägger till pengar på det laddade kontot	*	* @params (int) amount	* @return void	**/	public void addMoney(int amount)	{				int accType = this.customer.getAccountType(this.acc);		if(accType == 1)		{						SavingsAccount acc = this.customer.getSavingsAccount(this.acc);			acc.add(amount);					}				else		{						CreditAccount acc = this.customer.getCreditAccount(this.acc);			acc.add(amount);					}				}		/**	* Beskrivning: Tar bort pengar från det laddade kontot	*	* @params (int) amount	* @return void	**/	public void deductMoney(int amount)	{				int accType = this.customer.getAccountType(this.acc);		if(accType == 1)		{						SavingsAccount acc = this.customer.getSavingsAccount(this.acc);			acc.deduct(amount);					}				else		{						CreditAccount acc = this.customer.getCreditAccount(this.acc);			acc.deduct(amount);					}			}		/**	* Beskrivning: Returnerar ett objekt innehållande alla idn på kunder i systemet	*	* @params void	* @return (Object[]) customers	**/	public Object[] getCustomersAsArray()	{				int length = this.customers.size();		Object[] customers = new String[length];				Customer cust;		Iterator it = this.customers.iterator();		int i = 0;				while(it.hasNext())		{						cust = (Customer) it.next();			customers = i + "";						i++;					}				return customers;			}		/**	* Beskrivning: Returnerar ett objekt innehållande kontonummer på alla konton tillhörande den laddade kunden	*	* @params void	* @return (Object[]) accounts	**/	public Object[] getAccountNumbersAsArray()	{				SavingsAccount currentSAccount;		CreditAccount currentCAccount;		int length = this.customer.getCreditAccountsLength() + this.customer.getSavingsAccountsLength();		Object[] accounts = new Integer[length];		int i = 0;				Map sAccounts = this.customer.getSavingsAccounts();		Map cAccounts = this.customer.getCreditAccounts();				Map.Entry account;    	Iterator allSavingsAccounts = sAccounts.entrySet().iterator();    	Iterator allCreditAccounts = cAccounts.entrySet().iterator();    	    	while(allSavingsAccounts.hasNext())    	{    		    		account = (Map.Entry) allSavingsAccounts.next();    		currentSAccount = (SavingsAccount) account.getValue();    		accounts = currentSAccount.getAccountNumber();    		i++;    		    	}    	    	while(allCreditAccounts.hasNext())    	{    		    		account = (Map.Entry) allCreditAccounts.next();    		currentCAccount = (CreditAccount) account.getValue();    		accounts = currentCAccount.getAccountNumber();    		i++;    		    	}    	    	return accounts;			}		/**	* Beskrivning: Kollar om det finns kunder i systemet	*	* @params void	* @return (Boolean) true or false	**/	public Boolean hasCustomers()	{				if(this.customers.size() > 0)		{						return true;					}				return false;			}		/**	* Beskrivning: Kollar om det finns konton på den laddade kunden	*	* @params void	* @return (Boolean) true or false	**/	public Boolean hasAccounts()	{				String cAccounts = this.getCreditAccounts();		String sAccounts = this.getSavingsAccounts();					if(cAccounts != "" || sAccounts != "") return true;				return false;			}		/**	* Beskrivning: Tar bort det laddade kontot från den laddade kunden	* och returnerar räntan	*	* @params void	* @return (double) interest	**/	public double deleteAccount()	{				int type = this.customer.getAccountType(this.acc);		if(type == 1)		{						SavingsAccount acc = this.customer.getSavingsAccount(this.acc);			double interest = acc.prepareDelete();			this.customer.removeAccount(this.acc);			return interest;					}				CreditAccount acc = this.customer.getCreditAccount(this.acc);		double interest = acc.prepareDelete();		this.customer.removeAccount(this.acc);		return interest;			}		/**	* Beskrivning: Tar bort alla konton tillhörande den laddade kunden	*	* @params void	* @return (String) accounts	**/	public String deleteAccounts()	{				SavingsAccount currentSAccount;		CreditAccount currentCAccount;		String accounts = "";		double interest = 0.0;		this.totalInterest = 0.0;				Map sAccounts = new TreeMap(this.customer.getSavingsAccounts());		Map cAccounts = new TreeMap(this.customer.getCreditAccounts());				Map.Entry account;    	Iterator allSavingsAccounts = sAccounts.entrySet().iterator();    	Iterator allCreditAccounts = cAccounts.entrySet().iterator();    	    	while(allSavingsAccounts.hasNext())    	{    		    		account = (Map.Entry) allSavingsAccounts.next();    		currentSAccount = (SavingsAccount) account.getValue();    		interest = currentSAccount.prepareDelete();    		    		if(accounts != "") accounts += ", ";    		    		accounts += currentSAccount.getAccountNumber() + ": " + interest;    		this.totalInterest += interest;    		    		this.customer.removeAccount(currentSAccount.getAccountNumber());    		    	}    	    	while(allCreditAccounts.hasNext())    	{    		    		account = (Map.Entry) allCreditAccounts.next();    		currentCAccount = (CreditAccount) account.getValue();    		interest = currentCAccount.prepareDelete();    		    		if(accounts != "") accounts += ", ";    		    		accounts += currentCAccount.getAccountNumber() + ": " + interest;    		this.totalInterest += interest;    		    		this.customer.removeAccount(currentCAccount.getAccountNumber());    		    	}    	    	return accounts;					}		/**	* Beskrivning: Tar bort den laddade kunden från systemet	*	* @params void	* @return (double) this.totalInterest	**/	public double removeCustomer()	{				this.customers.remove(this.customer);		return this.totalInterest;			}	}


FileManager class:
import java.io.*;import javax.swing.*;import javax.swing.filechooser.*;import java.util.*;class FileManager{		private static final String EXT = "bank";	private static final String DESC = "Bank source files";		private String file_name;	private File file_write;	private File file_read;		private FileOutputStream write_stream;	private FileInputStream read_stream;		private ObjectOutputStream write_objectStream;	private ObjectInputStream read_objectStream;		private Customer[] customers_write;	private Customer[] customers_read;		private JFileChooser chooser;		public FileManager()	{				this.chooser = new JFileChooser();		this.chooser.setFileFilter(new BankFilter(EXT, DESC));			}		public String open()	{				int status = this.chooser.showOpenDialog(null);		String name = "";				if(status == JFileChooser.APPROVE_OPTION)		{						File file = this.chooser.getSelectedFile();			name = file.getName();					}				return name;			}		public String choose()	{				int status = this.chooser.showSaveDialog(null);		String filename = "";				if(status == JFileChooser.APPROVE_OPTION)		{						filename = this.chooser.getSelectedFile().getAbsolutePath();					}				return filename;			}		public FileManager file(String file)	{				this.file_name = file;		return this;			}		public Customer[] read() throws IOException, ClassNotFoundException	{				this.file_read = new File(this.file_name);		this.read_stream = new FileInputStream(this.file_read);		this.read_objectStream = new ObjectInputStream(this.read_stream);				this.customers_read = (Customer[]) this.read_objectStream.readObject();		this.read_objectStream.close();				return this.customers_read;			}		public void write(Customer[] customers) throws IOException	{				this.customers_write = customers;				this.file_write = new File(this.file_name);		this.write_stream = new FileOutputStream(this.file_write);		this.write_objectStream = new ObjectOutputStream(this.write_stream);				this.write_objectStream.writeObject(this.customers_write);		this.write_objectStream.close();			}	}


And just to be on the safe side, here's BankFilter aswell:
import java.io.File;import javax.swing.*;import javax.swing.filechooser.*;class BankFilter extends FileFilter{		private static final char DOT = '.';		private String Ext;	private String Desc;		public BankFilter(String ext, String desc)	{				this.Ext = ext;		this.Desc = desc;			}		public boolean accept(File f)	{				if(f.isDirectory())		{						return true;					}				if(extension(f).equalsIgnoreCase(this.Ext))		{						return true;					}				else		{						return false;					}			}		public String getDescription()	{				String desc = this.Desc + " (" + DOT + this.Ext + ")";		return desc;			}		private String extension(File f)	{				String filename = f.getName();		int loc = filename.lastIndexOf(DOT);				if(loc > 0 && loc < filename.length() - 1)		{						return filename.substring(loc + 1);					}				else		{						return "";					}			}	}


Quote:
Original post by Lord_Evil
Seems like the classpath is not set properly.

How do you start the app?
Do you use jars? If so, is FileManager in another jar file than Logic, like Glass_Knife suggested? Did you add that jar file to the class path?

If you don't use jars, where in your filesystem (relative to the project's root directory) are Logic.class and FileManager.class located after compilation? What packages did you put them into?


I start the app via a class called GUI, which contains the method static void main, but it is also a class that handles all the layout of the program.

I do not use jars, and as said before, FileManager.class and Logic.class is located in the same directory as all the rest of the files(see screenshot).
http://img34.imageshack.us/img34/2678/files.jpg
candelas
candelas
I have no idea why you'd be getting that message, but you might want to try deleting the class files of Logic and FileManager and recompiling them. Have you checked that filemanager is even a FileManager? Looks like it is, but this is a weird error. I don't think those suggestions will actually help you, but you might as well try if you haven't already.

But what made me decide to post is this. Why is there a
FileManager.choose()Ljava/lang/String in the error message?

I believe that Ljava/lang/String is an array of strings. It's been a while since I've used Java, and I have no idea why that would be showing up. Maybe you do. If not, maybe you can look into that.

I wish I could be more help, but I thought you might not have noticed that.
Lord_Evil
Lord_Evil
candelas is right, the code looks for a method String[] choose() in FileManager, but that method's not there. Did you compile all of your source files? Is there another FileManager.java floating around somewhere?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Tanax
Tanax
Hi!

I solved it. I did what you suggested, I delete ALL classfiles, and recompiled everything, and now it works.

Though, I hit another problem.
if(this.logic.hasCustomers())				{										try					{												this.logic.saveFile();											}										catch(IOException e)					{												JOptionPane.showMessageDialog(null, "Something went wrong");											}									}


I get the "Something went wrong" message when I try to export the current list of customers, but the file is still being saved. Any thoughts about that?

Thanks for all the help by the way, I really appreciate it!
Tanax
Tanax
I just debugged the write method in FileManager:
public void write(Customer[] customers) throws IOException	{				this.customers_write = customers;				this.file_write = new File(this.file_name);		JOptionPane.showMessageDialog(null, "File created");		this.write_stream = new FileOutputStream(this.file_write);		JOptionPane.showMessageDialog(null, "File outputstream created");		this.write_objectStream = new ObjectOutputStream(this.write_stream);		JOptionPane.showMessageDialog(null, "File object outputstream created");				this.write_objectStream.writeObject(this.customers_write);		JOptionPane.showMessageDialog(null, "Write to file suceeded");		this.write_objectStream.close();		JOptionPane.showMessageDialog(null, "File closed");			}


And it outputs:
File created
File outputstream created
File object outputstream created
Something went wrong

So it fails when it tries to writeObject.
Lord_Evil
Lord_Evil
I guess it should be writeArray(...) instead of writeObject(...) since customers_write is an array.

Btw, is Customer serializable?

Edit: Oops, writeArray is private. Forget about the first line [grin].
Edit2: output the message or the name of the exception -> e.getMessage() or e.getClass().getName()
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Tanax
Tanax
Mmm, that did it. I had to implement Serializable in every object that was meant to be stored in the file.

However, I got a new problem(hopefully the last one) when trying to open a file now.

Do you see anything wrong with this?
public Customer[] read() throws IOException, ClassNotFoundException	{				this.file_read = new File(this.file_name);		this.read_stream = new FileInputStream(this.file_read);		this.read_objectStream = new ObjectInputStream(this.read_stream);				this.customers_read = (Customer[]) this.read_objectStream.readObject();		this.read_objectStream.close();				return this.customers_read;			}
Tanax
Tanax
Actually, nevermind :D
I solved it, and it works now to save and open bank files ^^

Thanks for all the help guys!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.