Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> How Do I Create An Array Of Objects?, The code in the tutorial I have read returns an error upon compilation
Jeune
post 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.
Go to the top of the page
 
+Quote Post
beeseven
post 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) {
     int c = a + 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.
Go to the top of the page
 
+Quote Post
darran
post 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.
Go to the top of the page
 
+Quote Post
Jeune
post 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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Java Script Drop Down Menu With Css(2)
  2. How To Insert Code With Javascript(7)
  3. Image Show With Thumbnail And Fade(2)
  4. Error Unsupppoted Class Version 49.0(1)
  5. Picture Enlargement(2)
  6. Countdown Code Help(3)
  7. Fire Effect Code(0)
  8. Help Writing An Html Code (onclick Open Something)(5)
  9. My Code Does Not Connect To Database(1)
  10. Ajax: Achieve Ajax Program In 5 Lines Of Code!(1)
  11. Lightbox Js Error In Opera(2)
  12. Ajax Code Need Help Debugging.(9)
  13. Special Wii Javascript(2)
  14. Javascript Error(2)


 



- Lo-Fi Version Time is now: 6th September 2008 - 06:31 PM