| | 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. |
| Nov 21, 2009 |
How Do I Create An Array Of Objects? - The code in the tutorial I have read returns an error upon compilation |
|
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; }
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.
yep, I did but this post was like a month ago. Thanks anyway.
Similar Topics
Keywords : create, array, objects, code, read, returns, error, compilation
New Javascript Objects for Wii (2) I found on Nintendo.com a while back some new javascript objects dealing with the Wii Remote. I (9) I did a tutorial on ajax started to write my own It was all working well under safari but when i Opacity Issue (2) I use the Lightbox JS script for displaying images ( seen here ). It works great, but the trouble (1) Well Last night, after a week of irritation and errors I finally created an easy Javascript object always databases (1) Hi everyone! i am having a (12) hi, I am new in web development i want to make a page in which there are few buttons and on click (0) Here's a good Fire code:- -easy to install -super small -lag free(in most browsers) -great I need help setting an image as the background. (3) Ok, now for scripts like this i am not to well of working with..and i am in need of a bit of help, i javascript code (2) ok i have alot of pictures on my site and i need a way in which i can hold my mouse over the none (1) When i run my war file in tomcat5.5.9 it is display Unsupported version 49.0 error .Do you have any Does anyone know were I can get this code? (2) Hi I would like to know if anyone knows a javascript that makes an thumbnail 'slideshow' How to insert into a div an amount of code (11) Hi, I have the next html page CODE function insertcode() { var code =" blablabal babala The Code is Pretty Nice! (5) OpaQue, where did you get that JavaScript for the error 404 page for Trap17? It's something - a full code for a dynamic drop down (2) Introduction This is a code that I use to dynamically create the drop down menus. First, you have Java Code Review Tool (0) hi friends, I came across another useful tool, Hammurapi. It is a code review tool for Java. It Looking for create, array, objects, code, read, returns, error, compilation
|
![]() How Do I Create An Array Of Objects? - The code in the tutorial I have read returns an error upon compilation |
Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com