Oy ! generics...simple newbie questions

I did read the faq- but have all sorts of problems. This is my first generics program, please critique and why am I getting this compile time error ?!
Also: if I wanted to use List<List<M>>, how would this change ?
public class GenericsTest
static class Library{
ArrayList> aislesofmedia = new ArrayList>();
public Library(){
for(int i=0; i< 20; i++) { aislesofmedia.add(i, new ArrayList(20)); }
public void storeMedia(M m, int rowid, int shelfid)
ArrayList row = (ArrayList) aislesofmedia.get(rowid);
row.add( shelfid, m);
aislesofmedia.add( (ArrayList) row); /*ERROR! Description Resource Path Location Type*
*The method add(ArrayList<M>) in the type ArrayList<ArrayList<M>> is not applicable for the arguments (ArrayList<M>) GenericsTest.java myproj/src line ...* /
static class MediaClass {
protected String name;
MediaClass( String s) { name=s; }
static class Book extends MediaClass
{ public Book(String s) { super(s); }
public static void main(String[] args)
Library lib = new Library();
Book b1= new Book("Oliver Twist");
lib.storeMedia(b1, 1,1); }
}Edited by: anikam on Oct 15, 2009 3:30 PM

Thankyou for your patience.
I am still trying to understand of generics... so I understand that I could use a different construct ...
Here is the class based on ArrayList<ArrayList<M>>
import java.util.List;
import java.util.ArrayList;
public class gtest {
    static class Library<M>{
        ArrayList<ArrayList<M>> aislesofmedia = new ArrayList<ArrayList<M>>();
        public Library(){
             for(int i=0; i< 10; i++)
                  aislesofmedia.add(i,  new ArrayList<M>(20));                  
        public <M> void storeMedia(M m, int rowid, int shelfid)
               /* The following line does not compile
              Compile error: Type mismatch: cannot convert from ArrayList<M> to ArrayList<M>
              It will compile with ArrayList<M> e = (ArrayList<M>)aislesofmedia.get(rowid); */
             ArrayList<M> e = aislesofmedia.get(rowid);             
             e.add( shelfid, m);                
        public <M> M retrieveMedia(int rowid, int shelfid)
/* The following line does not compile
              Compile error: Type mismatch: cannot convert from ArrayList<M> to ArrayList<M>
              It will compile with ArrayList<M> e = (ArrayList<M>)aislesofmedia.get(rowid); */
             ArrayList<M> row =  aislesofmedia.get(rowid);             
             return row.get(shelfid);                
    public static void main(String[] args)
        Library<String>    lib = new Library<String>();
        String book1 = "Oliver Twist";
        String book2 = "where the wild things are";
        lib.storeMedia(book1, 0,0);
        lib.storeMedia(book2,0,1);
        String m = lib.retrieveMedia(0, 0);
        String m2 = lib.retrieveMedia(0, 1);
        System.out.println(m+", "+m2);
}Edited by: anikam on Oct 16, 2009 10:54 AM

Similar Messages

  • 2 simple newbie questions!

    hi, I have some simple questions. I already searched on the web for some answers but I couldnt find any :(
    1. Is there any way to make a class execute another class's method every x minutes (say 5)? like an external signal that every 5 minutes executes "regelsysteem.genereerOverzicht()"
    2. i would like to retrieve the system's current time and date (in string format), how could i do this?
    thanks :)

    1. See Timer in the API Docs.
    2. See Date, Calendar, and DateFormat ditto.

  • Probably a simple newbie question...

    Hi. I'm teaching myself DVD SP (4.2) by putting together a very simple project but am stumped on what's probably an obvious solution.
    I have as my first play a quick slideshow with an accompanying music track. It automatically goes into my main Menu as its End Jump. I'd like that music track to continue on uninterrupted into the Menu. How do I do that? Right now it cuts out as it goes into the Menu.
    Thanks in advance...

    Make the slideshow in the other apps or you can change the slideshow to a track (make sure to make a copy it is only one way conversion) then bring that into a track (or add the other elements to the end of the converted slideshow) and use buttons over video to make a "menu"
    Often you can make the similar slideshow quickly in iMovie or iPhoto if needed then bring that into FInal Cut (or AE) to finish the rest of the movie
    Some animated background concepts
    http://dvdstepbystep.com/motion.php
    http://dvdstepbystep.com/useelements.php

  • Hopefully simple newbie question

    Hi, I just started using NetBeans 5.5 and Java in general.
    I have a created a .jar stand alone program that works fine. I created it from a general project in NetBeans.
    I would now like to "deploy" this program via the web somehow so other people can use it. I'm not sure the easiest way to do this (aside form a straight link to a .jar file in a web page).
    I saw something about JNLP files, which I don't know much about , but when I looked in the NetBeans help it seemed to suggest that I could right click on my project to have an option to build a JNLP file, but that option doesn't exist (I think I figured out that it had something to do with it only working for module suites possibly, but I don't know what that is at this stage).
    So, if JNLP is the easiest way, what is the simplest way for me to create a JNLP that will work? The information on how to do this was a bit confusing for me.
    Would trying to turn it into an applet be easier? That seems to involve a lot of recoding since it is currently stand alone.
    Thanks for any and all help.

    Java Web Start is an application-deployment technology that gives the power to launch full-featured applications with a single click from the Web browser. Java Web Start includes the security features of the Java 2 platform, so the integrity of data and files is never compromised.
    By including the following settings in the JNLP file, an application can request full access to a client system if all its JAR files are signed:
    <security>
    <all-permissions/>
    </security> An example of a JNLP file is as given below
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://name of webpage" href="myapp.jnlp">
    <information>
      <title>MY Application</title>
      <vendor>my name.</vendor>
      <homepage href="index.html"/>
      <description>name</description>
      <description kind="short">shortname</description>
    </information>
      <security>
         <all-permissions/>
      </security>
    <resources>
      <j2se version="1.4"/>
      <jar href="first.jar"/>
      <jar href="second.jar"/>
       </resources>
    <application-desc main-class="nameofmainclass"/>
    </jnlp>For complete reference to Packaging programs in jar files visit the location as below
    http://java.sun.com/docs/books/tutorial/deployment/jar/
    For complete documentation on Java WebStart you can visit the location as specified below
    http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/contents.html

  • Simple newbie question about arrays..

    Hello all,
    I have two arrays declared like so below the class header:
    String Players[];
    String Final[];
    I have a method like the following:
    public String[] CollectPlayers() {
    Players[0] = new String(txtPlayer1.getString());
    return Players;
    I am calling this method like so
    Final = CollectPlayers();
    Basically not working, giving nullpointerexception, but I feel that I am fundamentally not understanding something, so here is what I want...
    A method that returns an array and (ideally) use this method directly in creating a ChoiceGroup, like this...
    optBull = new ChoiceGroup("Bully", ChoiceGroup.EXCLUSIVE, CollectPlayers(), arrImage);
    Is this possible? Any ideas?
    Thanks in advance
    poncenby

    A few points:
    - You almost never need to call new String(String).
    - You may want to create an ArrayList (dynamic array) and then call toArray(new Players[0]) if you need it to be a fixed array.
    e.g.
    final List players = new ArrayList();
    public List collectPlayers(List players) {
        List finals = new ArrayList();
        for(int i=0;i<players.size();i++) {
            Player player = (Player) players.get(i);
            finals.add(players.getResult());
        return finals;
    players.add(new Player("anne"));
    players.add(new Player("bob"));
    players.add(new Player("fred"));
    List finals = collectPlayers(players);

  • Simple Newbie Question Re: Tutorial

    Hi,
    In the tutorial I click on a clip in FCP, send it to Motion to edit, and even before I start editing, I preview it back FCP and the video is squished. The clip went from 16x9 to 4x3. Even when I follow exact instructions it does the same thing. What can I do?
    Thanks, Chris

    Welcome to the discussions!
    Search is your friend:
    http://discussions.apple.com/thread.jspa?messageID=3320222&#3320222
    http://discussions.apple.com/thread.jspa?messageID=3438080&#3438080
    and officially:
    http://docs.info.apple.com/article.html?artnum=302121

  • Newb Question for burning DVD/CDs

    I have an external DVD writer on my iMac.
    I got the thing last month and an completely new to Apple (sorta)
    Now how do I make a data CD and DVD?
    On Winblows XP all I need to do is select the files, right click and click on SEND FILES TO CD for making data CDs.
    However for DVD I need 3rd party software.
    Will iDVD do the trick?
    Thanks for the looking at this simple newb question.
    GeekyBoy

    Now how do I make a data CD and
    DVD?Drag the files to the icon of the
    blank CD/DVD that appears in the
    Finder.However for DVD I need 3rd party
    software.You might want to try Patc
    hBurn.Will iDVD do the
    trick?No, iDVD is only for making video
    DVDs and it requires a G4 processor.
    Thanks for the tip Duane.
    I was just reading abotu burning CD on another site. It mentions about what you said, drag the files to the CD.
    However I am reading in my profiler that burning is NOT supported by OS X on this CD/DVD writer.
    Will Patchburn or any other software overcome this?
    Thanks

  • InDesign or Acrobat (newbie question)

    Hi,
    I tried posting this in the LiveCycle Designer forum, but I think it's a bit too much of a newbie question:
    Once in a blue moon when I'm at work, someone will ask me if I can add text fields to a PDF form so that they can easily type onto it and print it out. I've always done that directly in Acrobat (on the few occasions that it's been requested from me). But I was curious about Adobe LiveCycle since it came with CS3, so I played around with it a couple of days ago. I added the text fields in LiveCycle this time, and it seems to have worked fine. Which is the better program for this kind of task? I'm not 100% clear on the *main* purposes of either program or how they compare. If anyone wanted to give me a clue about it, I'd appreciate it!
    Thanks,
    Phyllis

    > I thought perhaps you could add that capability
    You can (I said I was oversimplifying). However there are contractual
    limits - to oversimplify (!) 500 users per form.
    >Which would be preferable -- receiving form data from LiveCycle or Acrobat?
    It depends what you want to do.
    >
    >I wish I knew what the difference was between these two programs. Is it purely a matter of emphasis on one task or another?
    They come to the same problem in different ways. For a simple task
    they may seem pretty much the same. Some differences:
    * A form made in Acrobat is a PDF with form fields stuck on top; it
    remains a normal PDF in every other way. Forms are almost always made
    by preparing an existing PDF, then adding form fields.
    * A form made in Designer is barely a PDF. It's a wrapper round an XML
    file. You can no longer edit it in Acrobat, ever, even for the most
    simple things. PDF files are imported and converted (sometimes with
    loss of quality or features), or forms are made from scratch.
    * Acrobat form fields are fixed size.
    * Designer form layout can be dynamic.
    Aandi Inston

  • First full Time Capsule Backup Newbie Question

    I'm most likely going to get a lot of crap for this newbie question but here it goes. When I setup my time capsule for the first time I want to backup it up hardwired to my IMac how do i do that. What are the steps involved I'm sure it's pretty simple plug the power cable in and connect the ethernet cable but then what. Thanks for your help all that reply

    Depends on how you want to setup your future wireless network. Just follow the TC Setup Guide. If there is a problem during setup, repost.
    Here are some links to get you started:
    [http://manuals.info.apple.com/en/TimeCapsule_SetupGuide.pdf]
    [http://support.apple.com/kb/HT1178]
    [http://support.apple.com/kb/HT1175]

  • IFS Newbie questions

    Two newbie questions:
    1. I have a simple batch file as below that I execute using ifsshell.
    login system/manager
    cd /FolderSystem
    put /usr/local/oracle/testifs/test.txt
    logout
    How do I copy to iFS all files in a specified local directory - /usr/local/oracle/testifs/* doesn't seem to work.
    2. Can database user be mapped to iFS user?
    Thanks in advance,
    Anandhi

    xsi wrote:
    - Is there a way to display X-Axis labels vertically in a chart?
    See Badunit's reply below.
    - Is there a way to display only specific values in a line chart?
    You can create a chart from "all the data in a table or only data in selected cells of one or more tables," according to the Numbers '09 Users Guide. Rather than reinvent the wheel, I'll refer you to Chapter 7 of that document, and specifically to Page 132.
    If I recall correctly, there is a copy of the Users Guide on the IWork installation disk. If not, the Guide is available for download in the Help menu in Numbers.
    Regards,
    Barry
    Message was edited by: Barry

  • MEGA-Newbie Question

    This has to be the most newbie of all newbie questions. Interestingly enough, it is the one that is most rarely answered in a non-technical way that the novice can understand.
    What exactly do I need Motion for? What, in common-sense, regular-language terms, does it do?
    My manuals tell me how to do all the things it does. But they assume I am an experienced editor (I'm an experienced filmmaker, but only just started working in editing) who already knows all the things that CAN be done and only wants to know HOW to do them in Motion. This is not me.
    So, say I am making a 90-minute HDV feature music doc. I have footage, I have stills. I will need captions, titles and text on screen. I will need an end credit roll. What is it I will probably want Motion to do for me that FCP can't do on its own?
    I'd appreciate an answer in somewhat non-technical language that addresses the practical use -- from a filmmaker's point of view -- of this no doubt amazing program.
    Thank you.

    hi Paul,
    You are right you can do much of the things Motion does in FCP, but Motion takes them further and often makes them easier to do.
    Briefly whereas FCP is generally for editing moving pictures from rushes to a coherent whole, Motion is used to composite or layers of moving pictures to make a new coherent whole picture.
    So i plain words, you can meld different sources of video, stills text and other sources together to make a new end peice. You can animate text, warp pictures, create fires, smoke, hide bits ( masking), animate graphical elements. In short whenever you need to layer up multiple sources of imagery Motion is your man. Sure FCP can handle a lot of this, but Motion is designed specifically and only to do this, and does it very well. ( You would not want to edit in Motion!)
    In your 90 minute example you could do it all in FCP and make it look very nice. But you might need to go the extra mile with the title sequence, perhaps the captions will have some kind of generic strap line ( lower third) under All these things could be done easier and better in motion. However you would not want to import the whole 90 minute programme into Motion and start throwing captions on it. Rather you would want to build each element ( strap line, animating titles, opening sequence etc) in Motion and then import them into FCP for the final mastering. Motion is for short sequences, and FCP is used to collect them all into one programme.
    I make music commercials for a living, do all the cutting on FCP and build all the graphic elements in Motion, take a look at my site for some examples if you'd like,
    http://www.moojoose.co.uk
    Hope this helps you
    regards
    adam

  • Newbie question. coldFusion w/ Flex 2 tutorial

    Hello.
    I am very new to F2 and CF. Fairly proficient at Flash, DW,
    css, html, etc. I have purchased and worked through a couple really
    great F2 and CF books. I am able to construct some good basic stuff
    with either. But am not really finding a tutorial or book that is
    exclusively committed just to the subject of to using CF with Flex
    2. There always seems to be a just a cursory mention, or a
    brush-by, but not much more than that. I get it: if you got this
    far, you probably arlready know everything about the two and
    shouldn't need such.
    If you could point me to a couple good references, I'd be
    very appreciative. I'm looking for a good step-by-step, just on
    this subject.

    Thank you. You are right on with the direction of your
    answer.
    Immediately, I am just trying to create a simple method of
    add/edit/delete records to tables from forms that I could access
    remotely with Flex 2. I just assumed that CF would be the best
    method, both being Macradobe products. If I am wrong about that, so
    be it. Utlimately, I would like to print specific "quotes" relative
    to specific customers and products to .pdf. This is for my own
    personal use (as an insurance broker). Not commercial. Nor is
    anyone paying me to develop this.
    Maybe a better newbie question would be: what would be the
    preferred method to add/edit/delete records, remotely, from a Flex
    2 application for later printing to .pdf based on various selection
    criteria? I have figured out how to do this on my own stand-alone
    machine. Now I want to be able to do it remotely from anywhere.
    I'm
    not looking for instruction from anyone here, just direction
    to your favorite learning tools so that I can dig in and learn.
    I bought the books you recommended (adding to my own Library
    of Congress).
    Thanks again!

  • Total Newbie Question ... Sorry :-(

    I know it's a windows thing, and I am now converted to Mac but I gotta know this because it's doing my head in. It's a complete stupid green gilled newbie question.
    When installing new programs on a Mac can you create shortcuts to the programs on the Dock? I did what I THOUGHT it would be, i.e I made an Alias and stuck it in the dock, but on rebooting my Mac later on, in place of the shortcuts where 3 question marks which when clicked on did absolutely nothing???
    Help?
    A.L.I
    Windows XP Pro Desktop, Macbook Pro, 60GB iPod Video   Mac OS X (10.4.5)   OS X

    You aren't installing something from a dmg file are you? The dmg is a disk image – kind of a virtual CD. So when you double click the dmg and then get the little disk/hardrive/custom icon on your desktop that is the same as if you had mounted a CD. You then need to drag the application off of that "CD" into your application folder. Then it is truly installed.
    You can then "eject" the icon your your desktop. This is what happens when you shutdown and without remounting the image your dock shortcut can't find the original.
    Just a thought.

  • Newbie Question. just installed IE7.. how do I set up a local host to preview sites?

    Sorry for the newbie question... but it's been a long time since I have done this
    Thanks!

    Just define your site in DW as always.  For a static site, that's all you need to do.

  • Newbie Question about FM 8 and Acrobat Pro 9

    Hello:
    I have some dcouments that I've written in FM v8.0p277. I print them to PDF so that I can have a copy to include on a CD and I also print some hard copies.
    My newbie question is whether there is a way to create a  PDF for hard copy where I mainitain the colors in photos and figures but that the text that is hyperlinked doesn't appear as blue. I want to keep the links live within the soft copy. Is there something I can change within Frame or with Acrobat?
    TIA,
    Kimberly

    Kimberly,
    How comes the text is blue in the first place? I guess the cross-reference formats use some character format which makes them blue? There are many options:
    Temporarily change the color definition for the color used in the cross-reference format to black.
    Temporarily change the character format to not use that color.
    Temporarily change the cross-reference definition to not used that character format.
    Whichever method you choose, I would create a separate document with the changed format setting and import those format into your book, create the PDF and then import the same format from the official template.
    - Michael

Maybe you are looking for

  • Error in MIGO while stock transfer from plant to Depot - Intra-company

    Dear gurus, I am facing an error while posting MIGO during intra-company plant to plant STO. Settings for STO: SPRO >IMG > MM >Purchasing > Purchase Order>set up Stock Transport Order Define Shipping Data Define/assign Checking rule Assign Delivery T

  • How to make helvetica the default font for Endesign?

    everytime that I create a document, times is the default font, but most of the time I use helvetica and I want to make it the default font. thanks.

  • BPC Classses

    Just  couple of questions on BPC: 1) Does anynone know, or heard of when BPC classess will be held in version 7.0NW? 2) I'm assuming most if not all implementations right now are using version 5.1M (not including the ramp-up projects ofcourse). Is th

  • Adding an addition feilds n the field status group

    Hi all I want to know, how to add a new field in the in the field status. e.g. in the standard  feild status group G001 we have fields namely general data, material managenment,addition account assignment,ect In additional account assignment i want t

  • Instant Messaging - EP 6.0.2.3.7

    I have installed: EP 6.0 Service pack 2 Patch level 3 Hotfix 7 (6.0.2.3.7) WebAS 6.20 J2EE Engine patch level 25 On the following system: Microsoft Windows 2000 Service pack 3 Pentium III 1400 Mhz 2 Gb RAM During the installation I faced no error mes