• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem on Generic example from K&B study guide

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please could someone help ,

I tried to compile the program below but it fails;



What could be the problem?

Thank you
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We won't know, unless you post the error, and the Adder class.
 
Chidimma Juliana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Stephan,

Am sorry providing incomplete information.



Below is compiler error message.

C:\Documents and Settings\Chidimma\Desktop\Allfiles>javac TestLegacy.java
TestLegacy.java:5: non-static method iterator() cannot be referenced from a stat
ic context
Iterator it = List.iterator();
^
TestLegacy.java:8: cannot find symbol
symbol : method intValue()
location: class Integer
int i = ((Integer)it.next()).intValue();
^
TestLegacy.java:19: cannot find symbol
symbol : method add(int)
location: interface java.util.List<Integer>
myList.add(4);
^
TestLegacy.java:20: cannot find symbol
symbol : method add(int)
location: interface java.util.List<Integer>
myList.add(6);
^
.\Integer.java:9: cannot find symbol
symbol : constructor Integer()
location: class Integer
Integer y = new Integer();
^
.\Integer.java:11: cannot find symbol
symbol : method intValue()
location: class Integer
int x = y.intValue();




Thank you
 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iterator it = List.iterator();

it should be :
Iterator it = list.iterator();

 
Chidimma Juliana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have corrected List to list which was used to invoke the iterator method. But the compilation still fails.



 
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiles fine on my machine.
 
Ranch Hand
Posts: 73
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compiles and runs fine on my machine too.

I guess you are not using any IDE to run this. I copied the code into Eclipse and changed compiler compliance level. I can see that 1.6 and 1.5 work just fine, but setting it to 1.4 shows problem in Eclipse for Integer.
 
Chidimma Juliana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Am using command prompt and compiler is jdk, below is the version of the compiler;

C:\Documents and Settings\Chidimma\Desktop\Allfiles>javac -version
javac 1.6.0_26
 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chidimma Juliana wrote:
C:\Documents and Settings\Chidimma\Desktop\Allfiles>javac -version
javac 1.6.0_26


It works even on command prompt.Your version is also valid.
 
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic