Use of Generics in ArrayList now mandatory?

Hi,
I'm writing a little Applet involving the population of ArrayList (my Java compiler is version 1.6.0_22).
My code is similar to
ArrayList vertexPoints = new ArrayList();
- it compiles OK, but when I try and run the applet, it falls out saying that there is a NullPointerException in the above line. I was under the impression that the use of generics in ArrayLists is not compulsory? Or will I have to
change the code to something like
ArrayList<3DPoint> vertexPoints = new ArrayList<3DPoint>():
Some websites with tutorials give the impression that providing a type is optional, hence my confusion.

799615 wrote:
but accessing a method of an array of objects. I'll soldier on....Since you have not provided any more information we can only make educated guesses. Perhaps you are doing something like:
Foo[] fooList = new Foo[5];
fooList[0].doStuff(); // NullPointerExceptionWhy? The first line only creates an array. It does not automagically create any Foo objects for you. Therefore the array is full of the deafult value and for Objects (reference types) it is null. So effectively the second line is null.doStuff().

Similar Messages

  • Raw use of Generics

    Something which makes me wonder: When I use own generic classes in a raw manner, I usually get the following warning:
    Type safety: The method myMethod() belongs to the raw type Generic. References to generic type Generic<T> should be parameterizedWhen using generic classes from the JDK, e.g. List or Map, I do not get any warning. Where is the trick? :)
    Is it possible to define or annotate methods of a class to not warn on raw usage? For example, when having a method in Generic<T>, that does not operate on T.
    Thanks,
    Stefan

    Well, I did not think, that code would be necessary to understand my question. And after some testing in order to reply here, I think, I may have fallen for an eclipse bug. If so, please let me know :)
    The following example might be semantically useless, but I wanted to point out my issue.
    Say we have the following custom class:
    public class Generic<T> {
         public int size() {
              return 0;
    }And a testing class:
    public class Test {
         public void testList(ArrayList aList) {
              aList.size();
         public void testGeneric(Generic aGeneric) {
              aGeneric.size();
    }Now, in eclipse I get a warning for "aGeneric.size()" but none for "aList.size()". Although, in my opinion, each call operates on a raw type. Using javac from shell does not produce any warning, so it might be eclipse.
    As a note: I know and appreciate warnings been thrown for generics. But in some cases, there is no need for warnings. For example, if a method's signature is independent of the generic's parametrization, hence the method is not "raw".
    If Java 5 already does that, I have to blame eclipse and myself for not thoroughly testing out before posting. :)
    Thanks,
    Stefan

  • When I create a New Folder (on the desktop or in Finder), the system uses the Generic Document Icon instead of the Generic Folder Icon. How can I change this back?

    When I create a New Folder (on the desktop or in Finder), the system uses the Generic Document Icon instead of the Generic Folder Icon. How can I change this back?
    All of a sudden I noticed that most of the folders on my computer were no longer using the folder icon, but the generic document icon. I had to manually change back the icon being used by opening Get Info for each folder and copying and pasting the generic folder icon from some folders that remained unchanged. Now whenever I create a New Folder (right click -> "New Folder"), the icon that shows up is the generic document icon (white page with top right corner turned down). And I have to manually change it so it shows up as a folder in Finder or on my desktop. I don't know why or how this switch happened. All of the folders now on my computer look ok, but I need to change the default so when I create a New Folder it uses the correct icon.
    I have also Forced Relaunch of my Finder and rebooted the system. I downloaded Candybar but am not sure what will fix anything, so I haven't proceeded.
    Anyone know how I can do this? Thanks.

    Anyone?

  • Justification for using HashMap and not ArrayList

    Hi, I've recently completed a project for my course and now I'm doing the write up for it. Part of my project was to load a dictionary into a data structure. I went with a HashMap because I had code from a previous project to help implement it, the dictionary was used to check possible decrypted words and return possible words that the half decrypted word could be.
    Now I should justify my use of HashMap v ArrayList. Time complexity of ArrayList is better than the hashmap if im correct, so are there any 'technical' reasons I could say why I chose the HashMap:
    ArrayList O(1)
    HashMap O(n)
    So searching 50,000 + words would be best using an arraylist? Could anyone possibly give a good reason why hashmaps would be better than arraylists?

    Linear searching is (generally) the slowest way to find something.
    If you know the exact location of what you're looking for, then obviously just accessing it using an ArrayList would be fast. Using a HashMap you can, by using the input key, figure the index of the bucket which contains your data, so you don't have to linearly search through the whole map just to find what you're looking for, your key gives you it's location.
    I'm sure these links can explain stuff better than I did:
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

  • I copied a lot of photos from an iphone to a DVD using a Windows 7 laptop, now I cannot access those photos on the DVD. HELP!

    I copied a lot of photos from an iphone to a DVD using a Windows 7 laptop, now I cannot access those photos on the DVD. HELP! In Windows Exlporer I can see the data on the disk in the details but when I click on it nothing appears as if there is nothing on it.

    It should. So they aren't shown in the Last Import smart album, right? Try the following:
    1 - launch iPhoto with the Command+Option keys held down and rebuild the library.
    2 - Run Option #4, Rebuild Database, followed by Option #1 if needed.
    OT

  • I did made a copy of all my CC programms. for using on my other workstation. now is the CC desktop app not syncing the programme information. it do not see or sync the installed programms properly. what can i do. i do not want to download the hols set. be

    I did made a copy of all my CC programms. for using on my other workstation. now is the CC desktop app not syncing the programme information. it do not see or sync the installed programms properly. what can i do. i do not want to download the hols set. because of a slow connection

    If you are getting emails from these forums then you probably accidentally clicked on one of the links on the forums page where all the questions are listed e.g. at the top right of each forum's page there is text box with Actions and Notifications in :
    So far you've posted in the iTunes Store forum :
    https://discussions.apple.com/community/itunes/itunes_store#/
    And the Using iPad forum :
    https://discussions.apple.com/community/ipad/using_ipad#/
    If on either of those forums that box says 'stop email notifications' instead of 'receive' then click on it and it should stop that forum sending emails to you.
    There are full instructions on this page for stopping emails, as there are other places where they might have been set 'on' :  https://discussions.apple.com/docs/DOC-3661
    This is your original post for iTunes Match : https://discussions.apple.com/message/22647293#22647293
    And this page lists your posts (you can click on each post on it to be taken to it's thread) : https://discussions.apple.com/people/suzettemg?view=overview

  • I have bought a new macbook pro 13 retina. I had an apple id with my iPhone 4 which I stopped using a month ago. Now I am trying to download the apps, notes and contacts onto my mac but it is not happening? Any help will be gratefully accepted

    I have bought a new macbook pro retina 13. I am not too familiar with Mac yet. I had an apple account with my iphone 4 which I stopped using a month ago. Now when I was trying to download the apps from that account  but I dont know how to do this and I am unable to do so. I would be grateful if anyone can advise me with regards to this?

    You cannot download the same Apps that you have on your iPhone. They are two seperate stores.
    The store you have on your iPhone is the same for any iDevice (iPad, iPhone and iPod)
    The store on your MacBook is only for Macs.

  • The on page search is ONLY working from top down. Search the previous doesn't work at all. I've been using firefox v.3 till now and it ain't work at all. Can you fix it???

    Just do a on page search (bring up the search bar). type a word and start searching. The search will not work until you specifically click on the page and put the cursor in the page. Why do i have to do that since i'm already viewing the page and i intend to do search??
    Once you are searching the word, click on the 'Previous' button to go to previous found word. This button NEVER work since i started using firefox v.3 till now!!! Hello, pls improve your search. Go take a look at IE same page search.

    From the Firefox help files;<BR><BR>
    Try disabling graphics hardware acceleration. Since this feature was added to Firefox, it has gradually improved, but there still are a few glitches.

  • I'm new using Logic, i've been using garageband for quite awhile now though but my question is just basic. When i want to record electric guitar while clicking the software option it brings me to alot of guitar sounds that i want to chose. I chose the twa

    I'm new using Logic, i've been using garageband for quite awhile now though but my question is just basic. When i want to record electric guitar while clicking the software option it brings me to alot of guitar sounds that i want to chose. I chose the twangy electric or the distorted strat but i only hear clean sounds. No matter what kind of guitar sound i chose in the library it only produces clean guitar. How can i make it sound like it supposed to? Did i miss something i should do?

    This definitely has me stumped as I'm unsure as to why your guitar can be heard, but with none of the channel strips plugins applied to the sound.
    On the record enabled channel strip that contains your guitar input, is the "I" button located near the "R" active? Also, if you record your guitar, can you hear the FX applied to it when you play back the recorded track?

  • I'm using iphoto9.1.3 but now it doesn't seem to work, whenever I try to open it, it just shows loading, but never loads. Can anybody help me with this ?

    I'm using iphoto9.1.3 but now it doesn't seem to work, whenever I try to open it, it just shows loading, but never loads. Can anybody help me with this ?    

    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • I share a macbook with my other half and we both use it for our iphones. When syncing using the new software I now have all of her and my contacts on my phone.  I don't want her contacts! How do I get rid?

    I share a macbook with my other half and we both use it for our iphones. When syncing using the new software I now have all of her and my contacts on my phone.  I don't want her contacts! How do I get rid?

    Hi,
    You have 2 solutions:
    1 - You can use 2 differents icloud account
    2 - You use the same account but you don't sync yours contacts.
    You configure that in  Settings > icloud
    You activate or desactivate what you want.
    Have a nice day.

  • My brother ipad was linked with old apple id and he forgot his id and never use same email.the problem now his mini ipad ask him for this id to open (activate ipad) what we can do ?

    my brother ipad was linked with old apple id and he forgot his id and never use same email.the problem now his mini ipad ask him for this id to open (activate ipad) what we can do ?

    He remember the id name and password but he can't enter we don't now if the password is wrong or the id was  lock . I have the all thing for the ipad such as his box . I now this is security thing but you could help me.

  • I have a mixer which i was using with my pc and now i bought a new macbook and it have only one jack for headphones and to use mixers i need jack for microphone too so what should i do

    i have a mixer which i was using with my pc and now i bought a new macbook and it have only one jack for headphones and to use mixers i need jack for microphone too so what should i do

    You need to get headset splitter adapter.
    http://www.startech.com/Cables/Audio-Video/Audio-Cables/35mm-4-Position-to-2x-3- Position-35mm-Headset-Splitter-Adapter-Male-to-Female~MUYHSMFF

  • Is it possible for multiple users to use a "generic" account simultaneously without screen sharing?

    Hey and thanks for checking out the thread.
    I am wondering if it is possible to have users use a generic account at the same time without any sort of screen sharing.
    I have set up a generic user account (for example useraccount, password 1234) for users to use in the time before I can set up a custom user name for them. However, I have run into some issues with this.
    When multiple users log on using this generic account, their applications seem to be shared on each screen. In the room with multiple Mac workstations, if someone starts working on Photoshop, Photoshop will open on every one elses screen who is logged on under that generic account.
    Is it possible for users to log on using a generic network account and have their own isolated work environment or is this sort of sharing a feature? I am new to Mac servers and am not sure.
    Thanks for reading the thread.

    That shared-account approach seems impractical for the various reasons you've identified, as well as the inevitable issue of cleaning up the detritus that'll inevitably build up in a shared account, and for the lack of accountability for activities occuring under the shared account for both auditing and security, and sharing directories would tend to introduce obscure conflicts around which-file-version-wins file updates when the same file is used in several places, and would probably be contrary to any per-user application software licensing agreements that might be involved.
    Put another way, get unique accounts created for folks, and work toward the ability to create accounts for arriving folks, and — if it's applicable here — talk to management about getting any per-user software licensing issues sorted out, whether that's having spare copies purchased and ahead or some advanced notice on accounts, or establishing group software licensing where that's available.
    AFAIK, there are tools around which can automate account creation, too.  Either generic, a tool such as Passenger, or it's certainly feasible to script the account creation sequence.
    Trying this shared-access generic-account approach just looks like it can create more work and more hassles and more effort to me...

  • HT204053 I purchased several apps using one Apple ID.  Now I want to change my Apple ID. Will I lose anything?

    I purchased several apps using one Apple ID.  Now I want to change my Apple ID. Will I lose anything?

    You won't lose anything, however all purchases are permanently tied to the ID used to purchase them originally so future updates of your existing apps will still require the password for your old ID (whether you are still using it for purchasing or not.

Maybe you are looking for