Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

ArrayList Error in Eclipse

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to follow up with another question I asked as I am having trouble eliminating the warnings from my source code.

In eclipse, I have created the variable in the class of:



However, if I try to run my code with just this, I receive a NullPointerException. So then I set it to the following:



And I get the following message:

Multiple markers at this line
- ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
- Type safety: The expression of type ArrayList needs unchecked conversion to conform to
ArrayList<Question>




Anyone able to help me out with this one? It isn't breaking my program, but I want everything to be 100% correct, so if someone could tell me what I am doing wrong, I would appreciate it!
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are just creating a reference of generic type not instantiate the ArrayList with generic type.

So use it like this.

 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh my god, what a silly mistake to overlook...

Thank you so much for finding the error, Siva!

Sometimes there is just so much code to process and you end up not able to find an error yourself. You guys are great!
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not the error though ....it is just a warning from the compiler that you are taking some risk.
 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Err, right. That is what I meant.

I knew what it was saying, but I had no clue what it was referring to.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic