| | |
passing arrays to classes?
![]() |
•
•
Join Date: Oct 2004
Posts: 44
Reputation:
Solved Threads: 0
//main method
int number = 1;
int num = 3;
details[] Darray = new details[number][num];
String name = JOptionPane.showInputDialog(null,
"Enter the name",
"Enter details",
JOptionPane.QUESTION_MESSAGE);
String DOB = JOptionPane.showInputDialog(null,
"Enter the DOB",
"Enter details",
JOptionPane.QUESTION_MESSAGE);
class details
// i have default construtors aswell
String getName(){
return name;
}
heres the problem - i was told that you are only ment to input data in the main method. I need a 2d array to store many people info.
I tried Darray[0] = name; but this came up
C:\Documents and Settings\java:34: incompatible types
found : java.lang.String
required: details
since classes are ment to store information (possibley privately) I was wondering the easiest way to store it in a array and pass it. I also want to use the array in the main method after the have finished storing it.
any ideas?
thanks for looking
int number = 1;
int num = 3;
details[] Darray = new details[number][num];
String name = JOptionPane.showInputDialog(null,
"Enter the name",
"Enter details",
JOptionPane.QUESTION_MESSAGE);
String DOB = JOptionPane.showInputDialog(null,
"Enter the DOB",
"Enter details",
JOptionPane.QUESTION_MESSAGE);
class details
// i have default construtors aswell
String getName(){
return name;
}
heres the problem - i was told that you are only ment to input data in the main method. I need a 2d array to store many people info.
I tried Darray[0] = name; but this came up
C:\Documents and Settings\java:34: incompatible types
found : java.lang.String
required: details
since classes are ment to store information (possibley privately) I was wondering the easiest way to store it in a array and pass it. I also want to use the array in the main method after the have finished storing it.
any ideas?
thanks for looking
Darray is a multidimential array of class details so you neede to use Darray[0][0] something like that in order to access details object in Darray.
Darray[0][0] = name won't work because java compiler can't convert string to details.
i am not sure but you might need to initilize every object in the array before you are going to use them. May be java compiler does this for you by calling default constructer for each element in array...
Darray[0][0] = name won't work because java compiler can't convert string to details.
i am not sure but you might need to initilize every object in the array before you are going to use them. May be java compiler does this for you by calling default constructer for each element in array...
![]() |
Similar Threads
- Arrays in classes (but not class arrays) (VB.NET)
- Problem when passing arrays from c# to matlab (C#)
- Passing arrays between subs (VB.NET)
- Help: Passing arrays between functions (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the Java Forum
- Previous Thread: Breaking out of a Loop
- Next Thread: Begin my first lesson to learn java
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






