Java Packaging Woes.
質問
OKだから私はJavaのテストファイルにSomeMoreを作業することにしました。問題?私がコンパイルしたとき - 私は得る:
C:\Documents and Settings\djasnowski\Desktop\gJson\readGoogle.java:1: package com.google.gson does not exist
import com.google.gson.*;
^
C:\Documents and Settings\djasnowski\Desktop\gJson\readGoogle.java:37: cannot find symbol
symbol : class Gson
location: class readGoogle
data = new Gson().fromJson(fileString, Data.class);
^
2 errors
.
それは面白いです。私は自分のファイルを手に入れず、私の家のPCでうまくいったところでこれを手に入れました。ファイルはうまく設定されています。Google JSON Javaファイルを含むフォルダにMy Com.Google.GSONがあり、正しいディレクトリにgoogleread.javaファイルがあります...そして私のMap1.txtもあります...奇妙な?私はそう思います。
これは私のファイルです:
import com.google.*;
import java.util.*;
import java.io.*;
public class readGoogle {
public static String MapTitle;
public static Data data;
public static Item item;
public static String dan;
public static FileReader fr;
public static void main(String[] args) {
try {
fr = new FileReader("map1.txt");
}catch(FileNotFoundException fne) {
fne.printStackTrace();
}
StringBuffer sb = new StringBuffer();
char[] b = new char[1000];
int n = 0;
try {
while ((n = fr.read(b)) > 0) {
sb.append(b, 0, n);
}
}catch(IOException rex) {
rex.printStackTrace();
}
String fileString = sb.toString();
try {
data = new Gson().fromJson(fileString, Data.class);
}catch (Exception er) {
er.printStackTrace();
}
System.out.println("Name of map: " + data.getTitle());
System.out.println("File of map: " + data.getName());
System.out.println("Current Map: " + data.getCurrentMap());
System.out.println("Right Map: " + data.getRightMap());
}
public static class Item {
public static String name;
public static int x;
public int y;
public static String getName() { return name; }
public static int getX() { return x; }
public int getY() { return y; }
public void setName(String name) { this.name = name; }
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
}
public static class Data {
private String name;
private String title;
private int currentMap;
private int leftMap;
private int rightMap;
private int upMap;
private int downMap;
private List<Item> items;
private int[][] map;
public String getName() { return name; }
public String getTitle() { return title; }
public int getCurrentMap() { return currentMap; }
public int getUpMap() { return upMap; }
public int getDownMap() { return downMap; }
public int getLeftMap() { return leftMap; }
public int getRightMap() { return rightMap; }
public List<Item> getItems() { return items; }
public int[][] getMap() { return map; }
public void setName(String name) { this.name = name; }
public void setTitle(String title) { this.title = title; }
public void setCurrentMap(int currentMap) { this.currentMap = currentMap; }
public void setItems(List<Item> items) { this.items = items; }
public void setMap(int[][] map) { this.map = map; }
}
}
. 解決
最初の誤差は次のとおりです。
package com.google.gson does not exist
.
これは、 Google Google Google Google Google Google Google Google Google Google Google Google Google が見つかりませんでした。それはあなたがすでにあなたの仕事PCにGSON Jarをダウンロードしたように聞こえます。まだ持っていない場合は最初にそれをしてください。
次に、GSON JARをクラスパスに追加してコンパイルを再試行してください。クラスパスを変更する詳細は、Toolsetに依存します。コマンドライン上のjavac
の手動呼び出しと比較して、ステップはIDEに対して超微妙に異なります。 CLASSPATHを操作する方法とコマンドラインを使用している方法がわからない場合は、マニュアルまたは Google 。私は質問からあなたのファイルのレイアウトを理解できなかったので、私はより多くの情報なしではそれ以上になることはできません。
この問題を解決すると、 Apache Maven のようなツールの使用を検討することができます。コンパイル、包装。