• 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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: 15705
367
  • 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.
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic