-2

I can't find a solution on this by myself. Please give me a tip or something

import java.util.*;


       import java.io.*;

        class Fulgleinfluens {
        public static void main(String[] args) {

        HashMap <String, Komm> Komm = new hashMap<String, Komm>();

        int teller = 0;

         try {
         Scanner FilKom = new Scanner(new File("KommuneKoordinater.txt"));

         while(FilKom.hasNextLine()) {
      String linje = FilKom.nextLine();
      String [] dellinje = linje.split(",");
      String kommune = dellinje[0];
      String fylke = dellinje[1];
      String lengdegrad = dellinje[2];
      String breddegrad = dellinje[3];

      Komm enKom = new Komm(kommune, fylke, lengdegrad, breddegrad);
      Komm.put(kommune, enKom);
      teller++;

         }
     } catch (Exception e) {
         System.out.println("En feil oppsto ved lesing av fil");
     }
     System.out.println("Lest "+teller+" antall linjer");
        }

        void getKommuneMap () {
     String kommune = "Sarpsborg";
     Komm enKom = (Komm) Komm.get(kommune);
        }
        }

        class Komm {
        String kommune;
        String fylke;
        String lengdegrad;
        String breddegrad;

        Komm(String kommune, String fylke, String lengdegrad, String breddegrad) {
             this.kommune = kommune;
             this.fylke = fylke;
             this.lengdegrad = lengdegrad;
             this.breddegrad = breddegrad;
        }
        }
danben
  • 80,905
  • 18
  • 123
  • 145
user265767
  • 559
  • 3
  • 12
  • 27
  • 2
    This can't be your code. It's full of spelling mistakes, like hashMap for HashMap. I can't tell where in the code you are getting the error in your subject. – bmargulies Feb 14 '10 at 22:02

3 Answers3

1

You can't name an instance of your map the same as the name of the class Komm. Change it to komm and it should be ok. Right now you are trying to call a static method on Komm rather than HashMap.get().

danben
  • 80,905
  • 18
  • 123
  • 145
  • `komm` is a terrible name for anything that's not an instance of `Komm`. Maybe call it `kommMap` or something. I don't know what Komm means so I'm not sure what you're trying to do here. But I really don't think a variable should be named `komm` if it's not referring to a `Komm`. – Tyler Feb 14 '10 at 22:07
  • Thanks for the quick response! I'm new to programming(java) and learning, thanks for alle the answares. When changing the HashMap name to komm, the compilator cant find variabel komm in Komm enKom = (Komm) komm.get(kommune); – user265767 Feb 14 '10 at 22:17
  • @MatrixFrog - you're right, I got confused between the types. `kommMap` is a better choice. – danben Feb 14 '10 at 23:55
  • @cbeberge - how did you change the name? Please post your updated code. – danben Feb 14 '10 at 23:55
0

Are your imports correct? Try :

import java.util.*;  // or java.util.HashMap 
import java.io.*;

I see the imports corrected. But your code is messed up. Your Komm variable is defined so many times.

fastcodejava
  • 39,895
  • 28
  • 133
  • 186
0

You're trying to call Komm.get() which will only work if get() is defined as a static method in the class Komm. As far as I can tell, it's not.

Tyler
  • 21,762
  • 11
  • 61
  • 90