Click here to Skip to main content
15,888,984 members
Home / Discussions / Java
   

Java

 
GeneralRe: simple question nested for loop to solve array problem Pin
Member 125938652-Jul-16 17:52
Member 125938652-Jul-16 17:52 
Question3 x 3 plane,clockwise or counterclockwise rotate the four tiles Pin
zarkerBlack20-Jun-16 0:43
zarkerBlack20-Jun-16 0:43 
AnswerRe: 3 x 3 plane,clockwise or counterclockwise rotate the four tiles Pin
Richard Deeming20-Jun-16 1:40
mveRichard Deeming20-Jun-16 1:40 
GeneralRe: 3 x 3 plane,clockwise or counterclockwise rotate the four tiles Pin
zarkerBlack20-Jun-16 3:09
zarkerBlack20-Jun-16 3:09 
GeneralRe: 3 x 3 plane,clockwise or counterclockwise rotate the four tiles Pin
Richard MacCutchan20-Jun-16 4:00
mveRichard MacCutchan20-Jun-16 4:00 
GeneralRe: 3 x 3 plane,clockwise or counterclockwise rotate the four tiles Pin
zarkerBlack21-Jun-16 3:17
zarkerBlack21-Jun-16 3:17 
GeneralRe: 3 x 3 plane,clockwise or counterclockwise rotate the four tiles Pin
Richard MacCutchan21-Jun-16 3:25
mveRichard MacCutchan21-Jun-16 3:25 
QuestionSerializing object to disc. Only retreives one object. Pin
larsp77714-Jun-16 1:42
larsp77714-Jun-16 1:42 
I have class:

Java
public class book implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String title = "N N";
	private String author = "N N";
	private int price = 0;
			
			
	public book()	
	{
	}
	

	//Construktor
	public book(String title, String author, int price)
	{
	    setTitle(title);
	    setAuthor(author);
	    setPrice(price);
	}
			
	//Setters
	public void setTitle(String title)
	{
	      this.title = title;
	}
	
	public void setAuthor(String author)
	{
	      this.author = author;
	}

	public void setPrice(int price)
	{
	      this.price = price;

	}	
	
		
	//Getters
	public int getPrice()
	{
	     return price;
	}	
	public String getTitle()
	{
	     return title;
	}	
	public String getAuthor()
	{
	     return author;
	}


	//Utskriftsmetod
	public void skrivUt()
	{
	     System.out.println("");
         System.out.println("Titel: " + title);
	     System.out.println("Författare: " + author);
	     System.out.println("Pris: " + price);
	}


}


And then a list to which I save the objects:

Java
book aBook = new book(title, anAuthor , thePrice);
aList = new ArrayList<book>();
aList.add(aBook);


I save the list:

Java
FileOutputStream fil = new FileOutputStream("C:\\SavedObjects\\Objektfil.dat");
ObjectOutputStream oostr = new ObjectOutputStream(fil);
oostr.writeObject(aList);
oostr.close();


And gets it back:

Java
FileInputStream fil = new FileInputStream("C:\\SavedObjects\\Objektfil.dat");
ObjectInputStream oistr = new ObjectInputStream(fil);
aList = (ArrayList<book>) oistr.readObject();
oistr.close();


Goes through the list in a textArea:

Java
for (book b : aList) {
ta1.append("Titel " + b.getTitle() + "\n");
ta1.append("Författare: " + b.getAuthor() + "\n");
ta1.append("Pris: " + Integer.toString(b.getPrice()) + "\n");
ta1.append("\n");
}//foreach


This works fine. The problem is that I only get back (or so it seems) the first object in the list.
AnswerRe: Serializing object to disc. Only retreives one object. Pin
Richard MacCutchan14-Jun-16 3:47
mveRichard MacCutchan14-Jun-16 3:47 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
larsp77714-Jun-16 22:22
larsp77714-Jun-16 22:22 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
Richard MacCutchan14-Jun-16 22:47
mveRichard MacCutchan14-Jun-16 22:47 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
larsp77714-Jun-16 23:28
larsp77714-Jun-16 23:28 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
Richard MacCutchan14-Jun-16 23:39
mveRichard MacCutchan14-Jun-16 23:39 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
larsp77714-Jun-16 23:52
larsp77714-Jun-16 23:52 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
Richard MacCutchan15-Jun-16 0:43
mveRichard MacCutchan15-Jun-16 0:43 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
larsp77716-Jun-16 21:28
larsp77716-Jun-16 21:28 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
Richard MacCutchan16-Jun-16 22:16
mveRichard MacCutchan16-Jun-16 22:16 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
larsp77716-Jun-16 22:43
larsp77716-Jun-16 22:43 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
Richard MacCutchan17-Jun-16 2:56
mveRichard MacCutchan17-Jun-16 2:56 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
larsp77717-Jun-16 12:48
larsp77717-Jun-16 12:48 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
Member 1211167124-Jun-16 20:57
Member 1211167124-Jun-16 20:57 
GeneralRe: Serializing object to disc. Only retreives one object. Pin
Richard MacCutchan24-Jun-16 21:02
mveRichard MacCutchan24-Jun-16 21:02 
Questionapplication architecture Pin
AppNewbie6-Jun-16 5:35
AppNewbie6-Jun-16 5:35 
AnswerRe: application architecture Pin
Richard MacCutchan6-Jun-16 6:39
mveRichard MacCutchan6-Jun-16 6:39 
Questionhow do i get IP address of the email sender's PC Pin
Member 125677045-Jun-16 23:43
Member 125677045-Jun-16 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.