Results 1 to 3 of 3
  1. #1
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default problem with hasmap

    I wanted to introduce various names associated with an identification in a hasmap and then present that information. But when i print the values they give me null :\
    Java Code:
    public class Biblioteca {
        static User Uti = new User();
        public static String name;
        public static String identify;
        public Biblioteca(){
            
        }
        public static void main(String[] args) {
            // TODO code application logic here
            try {
          
            
            String option;
            System.out.println("Introduce your optin");
            Scanner scan = new Scanner(System.in);
            opcao = scan.nextLine();
            while (option != "0"){
            if(option.equals("1")){
               System.out.println("Introduce your name");
               name = scan.nextLine();
               System.out.println ("Introduce your identification");
               identify = scan.nextLine();
               newRegister(name, identify);
              }}} catch (Exception e) {
                System.err.println("IOException:  " + e);
            }
     
               
           
           }
    
            
        
        private static void newRegister(String User, String pass) throws FileNotFoundException{
            System.out.println("o seu"+pass);
            Uti.userRegister(User, pass, "4");
        }
    Java Code:
    public class User {
        private static HashMap<String , String[]> info = new HashMap<>();
       
        String name;
        String identify;
        String typeUser;
    
    public User() {
            
    }
    
       
    public void userRegister(String user, String identify, String typeUser){
        
        info.put(identify, new String[]{name, typeUser, identify});
        for (int i = 0; i < info.size(); i++)  
            System.out.println(info.get(i)); 
    }
    public void loginUser(String nIdentify){
        
    }
    public void typeOfUser(){
        
    }
        
    }
    someone could help me?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: problem with hasmap

    You'll want to post your real code as the code posted is full of errors making it not able to be compiled.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: problem with hasmap

    Java Code:
    info.get(i)
    'i' is an int.
    'info' is keyed on a String.
    You'll never get a match.
    You can't loop over a Map like this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •