Results 1 to 3 of 3
Thread: Array of objects
- 07-31-2010, 10:19 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
Array of objects
Hello,
I'm trying to make array of 5 object but not in traditional way. When want to see data from int rodzaj from class Kasa i'm getting error coused by System.out.println(kasa[0].rodzaj);
Java Code:public class Bank { public static void main(String[] args) { Kasa kasa[] = new Kasa[5]; Klient klient = new Klient(); BankManager men = new BankManager(klient, kasa); men.sprawdz(); } } class BankManager extends Thread{ Klient klient; Kasa kasa[]; BankManager(Klient k, Kasa ka[]){ this.klient = k; this.kasa = ka; } public void sprawdz(){ [COLOR="Red"]System.out.println(kasa[0].rodzaj);[/COLOR] //error, or System.out.println(kasa[0]); give null System.out.println(klient.priorytet); //works fine } public void run(){ sprawdz(); }} class Klient { int priorytet=2; } class Kasa { public int rodzaj=0; }Last edited by Saletra; 07-31-2010 at 10:21 AM.
- 07-31-2010, 10:31 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
When you create an array of five Kasa references those references don't point to an actual Kasa object yet, i.o.w. you have to create the individual Kasa objects and make those array references point to them; e.g.
kind regards,Java Code:Kasa[] kasa= new Kasa[5]; // 5 references, each one equals null kasa[0]= new Kasa(); // element #0 now points to a Kasa object
Jos
- 07-31-2010, 12:16 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Array of Objects
By sfe23 in forum New To JavaReplies: 19Last Post: 02-04-2009, 05:57 PM -
Array of objects
By rosh72851 in forum New To JavaReplies: 5Last Post: 10-31-2008, 04:03 AM -
Array of Objects
By bluefloyd8 in forum New To JavaReplies: 5Last Post: 01-22-2008, 06:27 PM -
Array with objects
By toby in forum New To JavaReplies: 1Last Post: 07-25-2007, 09:50 AM -
array of objects
By Jack in forum New To JavaReplies: 2Last Post: 07-02-2007, 05:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks