|
|
|
|
![]() ![]() |
Jul 23 2006, 02:51 PM
Post
#1
|
|
|
Member [Level 2] ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 82 Joined: 20-October 05 Member No.: 13,144 |
I want to create an array of type Cards. Is this the right way of doing it?
CODE Card decker[]; decker = new Card[5]; I always get the error DeckofCards: java:47: missing return statement whenever I compile this. |
|
|
|
Jul 28 2006, 06:42 PM
Post
#2
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 629 Joined: 26-February 05 Member No.: 3,995 |
It would help if you posted the whole method that that's in but a "missing return statement" error generally means that you have a method with a defined return type but you never actually return anything in the method. For example:
CODE public static int sum(int a, int b) { The method has code in it but nothing is returned (in this case it should be c). The code you posted should work, but I usually put the [] on the type of object as opposed to the variable (e.g., Card[] decker), though I don't think that it matters.
int c = a + b; } |
|
|
|
Sep 2 2006, 09:55 AM
Post
#3
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 661 Joined: 31-August 06 From: Singapore Member No.: 29,189 |
I think there is a problem with your creation of the array of Card type. The correct syntax of creating an array would be something of the following
String[] aryStrTest; And lets not forget the part in instantiating the array so it would be something like aryStrTest = new String[20]; The thing about arrays is that it has a fixed size, so you really have to know how many elements are you going to expect, alternatively you could use a linklist class which accepts no boundaries with regards to the number of elements. But for that, you have to code it yourself. As for your DeckofCards: java:47: missing return statement error goes, beeseven is right, you lack a return statement, I am thinking that the method you created required you to return a variable. Have fun! I hope you have solved your problem. |
|
|
|
Sep 2 2006, 01:57 PM
Post
#4
|
|
|
Member [Level 2] ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 82 Joined: 20-October 05 Member No.: 13,144 |
yep, I did but this post was like a month ago. Thanks anyway.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 6th September 2008 - 06:31 PM |