• 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

HashMap wrong number of type arguments

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi everyone,

I have an error in my program and  I don´t know how to fix it.It´s my first time programming with Java Swing and using collections . Can you help me? Please.



------------------------------------------------------------------------------------------------------------------------------------------


 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaime Gomez wrote:java.util.HashMap<pkgModelo.clsNombre>hashmap;  //<---------ERROR(wrong number of type arguments; required 2)



The HashMap type requires you to provide both the type of the key and the type of the value. Hence its declaration is "public HashMap<K, V>". You only provided one type -- that might be the key or the value, but you need to provide both.
 
Jaime Gomez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jaime Gomez wrote:java.util.HashMap<pkgModelo.clsNombre>hashmap;  //<---------ERROR(wrong number of type arguments; required 2)



The HashMap type requires you to provide both the type of the key and the type of the value. Hence its declaration is "public HashMap<K, V>". You only provided one type -- that might be the key or the value, but you need to provide both.





It´s part, isn´t? I think...

public Hashmap(java.awt.Frame parent, boolean modal) {
       super(parent, modal);
         
       hashmap = new java.util.HashMap<String, String>();
       initComponents();
   }

 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaime Gomez wrote:It´s part, isn´t? I think...

public Hashmap(java.awt.Frame parent, boolean modal) {
       super(parent, modal);
         
       hashmap = new java.util.HashMap<String, String>();
       initComponents();
   }



Yes, that line you posted there is indeed correct. But the line you identified in your original post as " //<---------ERROR" is not correct.

So I don't understand what you are trying to do with that map. First of all you declare a variable as a HashMap<clsNombre> -- whether clsNombre is supposed to be the type of the key or the value I can't tell. And later you assign a HashMap<String, String> to that variable. That would be a map whose keys are String objects and whose values are also String objects, which has nothing to do with the clsNombre class.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I recommend not naming a class so closely to a major utility class in Java?
It's very confusing...
 
Jaime Gomez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jaime Gomez wrote:It´s part, isn´t? I think...

public Hashmap(java.awt.Frame parent, boolean modal) {
       super(parent, modal);
         
       hashmap = new java.util.HashMap<String, String>();
       initComponents();
   }



Yes, that line you posted there is indeed correct. But the line you identified in your original post as " //<---------ERROR" is not correct.

So I don't understand what you are trying to do with that map. First of all you declare a variable as a HashMap<clsNombre> -- whether clsNombre is supposed to be the type of the key or the value I can't tell. And later you assign a HashMap<String, String> to that variable. That would be a map whose keys are String objects and whose values are also String objects, which has nothing to do with the clsNombre class.



Well, it have to add elements in a table (Id and Name), just that.
 
Jaime Gomez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can I recommend not naming a class so closely to a major utility class in Java?
It's very confusing...



Thank you for the recommendation.
 
Jaime Gomez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem here, I don´t understand ver well how to do that, because i have mi classNombe(Name) in a package and  the JDialog of Hashmap in another one. It´s a bit confused for me.
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaime Gomez wrote:Well, it have to add elements in a table (Id and Name), just that.



And so you decided to use a HashMap for that table? Okay, then. Now, what are the data types of those elements? Are they both String? In that case you'd have a HashMap<String, String>.

But then you have that clsNombre class. (Please, please call it "ClsNombre" so that other Java programmers recognize it as a class. Class names should start with capital letters.) That already seems to contain those two data items. So why do you need a HashMap at all?

Hint: You should explain why you need to use a Map rather than a List.
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic