Nov 21, 2009

How Do I Create An Array Of Objects? - The code in the tutorial I have read returns an error upon compilation

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

How Do I Create An Array Of Objects? - The code in the tutorial I have read returns an error upon compilation

Jeune
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.

Comment/Reply (w/o sign-up)

beeseven
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.

Comment/Reply (w/o sign-up)

darran
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.

Comment/Reply (w/o sign-up)

Jeune
yep, I did but this post was like a month ago. Thanks anyway.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : create, array, objects, code, read, returns, error, compilation

  1. Javascript Error
    Error "missing ) in parenthetical" with JSON statment (2)
  2. Special Wii Javascript
    New Javascript Objects for Wii (2)
    I found on Nintendo.com a while back some new javascript objects dealing with the Wii Remote. I
    have decided to post a link to these new Javascript objects here. Wii javascript These new
    Javascripts can detect whether or not a Wii Remote is enabled, the position of the pointer, and even
    the tilt of the remote. It also has an object that determines the keypress of the Wii. These can be
    very useful for Wii sites. Maybe have a menu load with AJAX when the remote is tilted. Add button
    functionality such as when the A and B button are pressed, the form is submitted. Just....
  3. Ajax Code Need Help Debugging.
    (9)
    I did a tutorial on ajax started to write my own It was all working well under safari but when i
    tried to test it out on other broswers it doesnt seem to work at all. I've spend a few hours
    already going over it and cant seem to figure it out at this stage. Heres the code that works under
    safari function createRequestObject(){ var request_o; //declare the variable to hold the object.
    var browser = navigator.appName; //find the browser name if(browser == "Microsoft Internet
    Explorer"){ /* Create the object using MSIE's method */ request_o = new ActiveXObj....
  4. Lightbox Js Error In Opera
    Opacity Issue (2)
    I use the Lightbox JS script for displaying images ( seen here ). It works great, but the trouble
    is, in Opera when you click an image to view a larger version, the image will load up and everything
    like usual but if your mouse cursor is hovered over the image the opacity will get stuck at less
    than full. When an image usually loads the opacity starts at very opaque(maybe 0) and fades in to
    full opacity. But for some reason in Opera, hovering over it will stop this function from finishing.
    Take a look at the script and see if you can help me figure out why this is happen....
  5. Ajax: Achieve Ajax Program In 5 Lines Of Code!
    (1)
    Well Last night, after a week of irritation and errors I finally created an easy Javascript object
    that easily and quickly allows you to develop an AJAX program in just 5 easy steps! Here's the
    link to the object I've created: http://www.demolaynyc.astahost.com/ajaxConn/ajaxConn.js
    Download it and read the Readme file that's under the same directory:
    http://www.demolaynyc.astahost.com/ajaxConn/Readme.html Basically what this object does is to
    connect to a server-side script (".php, .asp, .jsp, etc"), and what ever this script displays is
    sent back to t....
  6. My Code Does Not Connect To Database
    always databases (1)
    Hi everyone! i am having a
    database connection problem, i am using this code to connet to
    the database -
    *******************attempCounter = 0****
    CODE public static Connection getDbConnection(String p_db, String p_schema) { Connection
    conn = null; int attemptCounter = 0; while (conn==null && attemptCounter { att....
  7. Help Writing An Html Code (onclick Open Something)
    (12)
    hi, I am new in web development i want to make a page in which there are few buttons and on click
    of each button there is some hidden text field which becomes visible and user can enter the text he
    wish to in it. how can i ?....
  8. Fire Effect Code
    (0)
    Here's a good Fire code:- -easy to install -super small -lag free(in most browsers) -great
    look/effect! Here's the image, it goes upwards... So basically, your forum would have these
    fire images flying from bottom to the top. It is lag free, simple, looks great and best of all, it
    takes very less space in ur wrapper... All you have to do is simply put this code in your site in
    tags... That's it!!!All done!! Code From:- http://rpg.u4l.com
    Enjoy!! /cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif"....
  9. Countdown Code Help
    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
    would like to set a background image as the background not a color... CODE /* Dynamic
    countdown Script- © Dynamic Drive (www.dynamicdrive.com) For full source code, 100's more DHTML
    scripts, and TOS, visit http://www.dynamicdrive.com */ function
    setcountdown(theyear,themonth,theday){ yr=theyear;mo=themonth;da=theday } //////////CONFIGURE THE
    COUNTDOWN SCRIPT HERE////////////////// //STEP 1: Configure the countdown-to date, in the format
    year, month, day: se....
  10. Picture Enlargement
    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
    pictures and the picture can get bigger. I know it will be some kind of javascript or flash trick
    can anyone explain the prosess for it?....
  11. Error Unsupppoted Class Version 49.0
    none (1)
    When i run my war file in tomcat5.5.9 it is display Unsupported version 49.0 error .Do you have any
    idea?....
  12. Image Show With Thumbnail And Fade
    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'
    and when mouseover...it fades...and when you click...it enlarges!!! I saw it somewhere here on the
    net but i cant finf it anymore!!! Can anyone help me...or does anyone know a good javascript
    site???? THANKS ....
  13. How To Insert Code With Javascript
    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
    babababab here comes header fadfafa anchor blalbababa " var myText =
    document.createTextNode(code); document.getElementById("content").appendChild(myText); } -->
    Insert Code This code insert the data as text. The html tags are not treated like markup.
    I need to insert the code in a time. I mean i can not go tag per tag. (E.g.
    document.createElement("p")... ) Is there any method to insert a pice of html code into a div and
    keep it like code not like tex....
  14. Eror 404 For Trap17
    The Code is Pretty Nice! (5)
    OpaQue, where did you get that JavaScript for the error 404 page for Trap17? It's something
    I've looked for for a long time! I 've tried before, but couldn't achieve the typing
    effect with JavaScript. I'd be very happy if you could tell me where you got it. /wink.gif'
    border='0' style='vertical-align:middle' alt='wink.gif' /> ....
  15. Java Script Drop Down Menu With Css
    - 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
    to edit the following code and put it in your Javascript. Notice : /*** SET BUTTON'S FOLDER HERE
    ***/. Edit that to your folder. Also, the /*** SET BUTTONS' FILENAMES HERE ***/. This creates a
    mouseover when the drop down is activated. Put all your onmouseover images under: oversources = new
    array; and your onmouseout images under : upsources. Be sure to set your on and out images above
    each other. CODE /*** SET BUTTON'S FOLDER HERE ***/ var buttonFold....
  16. Hammurapi
    Java Code Review Tool (0)
    hi friends, I came across another useful tool, Hammurapi. It is a code review tool for Java. It
    parses thru java source files and generates a report stating all the violations to the standards.
    It is very much customizable so that u can define ur standards and it will report. It can be found
    at www.hammurapi.org It can also be called from an ant build file. I feel it wud be very useful
    for java projects and to maintain coding standards.....

    1. Looking for create, array, objects, code, read, returns, error, compilation

Searching Video's for create, array, objects, code, read, returns, error, compilation
See Also,
advertisement


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