[英]Hashtable “Unresolved compilation” in java
這是我的課
package main;
import java.util.Hashtable;
public class Information {
private final static String name = "Info Name";
private final static String direccion = "direction street number";
Hashtable<String,String> coordenates = new Hashtable<String,String>();
coordenates.put("lat", "36.564565465");
coordenates.put("lng", "64.584616511");
}
我從oracle文檔中學到了
This example creates a hashtable of numbers. It uses the names of the numbers as keys:
Hashtable<String, Integer> numbers
= new Hashtable<String, Integer>();
numbers.put("one", 1);
numbers.put("two", 2);
numbers.put("three", 3);
To retrieve a number, use the following code:
Integer n = numbers.get("two");
if (n != null) {
System.out.println("two = " + n);
}
我的代碼有什么問題...
我在Windows 7 64位上使用Eclipse for Java EE Developers Java SE SDK 7(1.7)
謝謝!
您正在嘗試在方法,構造函數或static
初始化程序的上下文之外執行代碼...
public class Information {
private final static String name = "Info Name";
private final static String direccion = "direction street number";
Hashtable<String,String> coordenates = new Hashtable<String,String>();
/**
This belongs in a constructor or method
coordenates.put("lat", "36.564565465");
coordenates.put("lng", "64.584616511");
**/
}
您正在嘗試在方法外調用hashtable.put(),則可以在構造函數內進行操作,我不確定您的要求是什么,但我想您可以避免hashtable的開銷並定義兩個字段lat和long
1.寫在主要功能上
public static void main(String args[]) {
Hashtable<String,String> coordenates = new Hashtable<String,String>();
coordenates.put("lat", "36.564565465");
coordenates.put("lng", "64.584616511");
}
2.用構造函數編寫
Information() {
access setter of coordinates to put values
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.