@w1024020103
2017-06-15T23:13:31.000000Z
字数 4493
阅读 1200
CS61B
采用17年的skeleton
when I try to run MapServer.java, I get these errors:
Error:(19, 23) java: 程序包com.google.gson不存在
Error:(21, 20) java: 程序包spark不存在
Error:(98, 9) java: 找不到符号
符号: 方法 staticFileLocation(java.lang.String)
位置: 类 MapServer
The following resources actually helped me out: I need to open Project Structure > Library > add > from Maven > search for "Gson 2.8.0" > Download > Add dependencies to pom.xml
resouces:
Google GSON Dependency not found
Gson User Guide
google/gson
每次run之前要先关掉console那里的tab,不然会报错java.net.BindException: Address already in use.
捣鼓了一下,pass了test.html.此处注意一下2D array的初始化:
String [][] images = new String [][] {{"aaa","bbb","ccc"},{"ddd","eee","fff"},{"ggg","eee","hhh"}};
I found these words most useful in this part:
The problem of finding the correct images for a given query is thus equivalent to going to the shallowest level whose LonDPP is less than or equal to the query box, and finding all images at that level that intersect the query box.
报错:java.lang.StackOverflowError
at Rasterer QuadTree.(Rasterer.java:40)
at Rasterer QuadTree.(Rasterer.java:40)
at Rasterer QuadTree.(Rasterer.java:40)
helpful resources for constructing QuadTree:
However, when I try to NEW a QuadTree as the initialQuadTree, I ran into one problem:
'QuadTree' is not an enclosing class
initialQuadTree = new QuadTree(new QuadTree.Node());
然后干脆新建了一个QuadTree类,但还是报同样的错。
this helped me out:
Is not an enclosing class Java
现在,运行出来的结果只显示了这些code对应的:
System.out.println(params);
System.out.println(biggestLonDPP);
其余的都没有显示,说明运行出问题了:
System.out.println(bestLonDPP);
System.out.println(returnTiles.size());
卡了好几天没进展,实在觉得做不下来,问了YYN要proj3的代码。跟学Algorithm Part 1第一遍时候一样,我希望自己至少能读懂别人的代码,理解的基础上能模仿着写出来。但这也让我担心开学后做作业会很困难。没有办法,转专业的道路前段肯定会有难捱的时期,刷完CS61B必须开始刷算法课,刷题,有机会最好再刷一些Project,为开学做好准备。
很大的知识漏洞,java IO这一块儿。
写到RasteredImages.java里的getDepth()方法时有一疑惑,为什么要写
public int getDepth() {
//images[i][j] = "img/" + images[i][j] + ".png"
return images[0][0].length() - 8;
}
这里的images难道不是process之前的images吗,按理说应该是
123
这样的格式,还没有
img/ + 123 + .png
呀?为什么depth要-8呢?
上一个问题还没有解决,按照参考答案写的,然后测试却始终不通过,报以下错:
看样子是我的ArrayList nodes 是空的,但一直没法debug,找不到问题出在哪儿。
我一部分一部分地测试,发现出错的方法有:
getNodes():java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
helpGetNodes():java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
getImages():java.lang.ArrayIndexOutOfBoundsException: 3
insert:java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
如果不按照它的Insert里面的num而是按照我自己的,会出现出来的图不完整的问题:
检查来检查去,发现我出问题的地方是二位数组的row和col分不清:
//return all images corresponding to the qualified nodes
public String[][] getImages(ArrayList<Node> nodes){
double firstULlat = nodes.get(0).upLeftLatitude;
int col = 0;
for(Node node: nodes){
if(node.upLeftLatitude == firstULlat){
col += 1;
}
}
int row = nodes.size() / col;
//[[img/13.png, img/14.png, img/23.png, img/24.png],
//[img/31.png, img/32.png, img/41.png, img/42.png],
//[img/33.png, img/34.png, img/43.png, img/44.png]]
//2D array, [][] first bracket stands for the number of 1D array which equals to the number of rows,
//second stands for the number of element of the 1D array which equals to the number of cols.
String[][] images = new String[row][col];
int count = 0;
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
images[i][j] = nodes.get(count).getImgFile();
count += 1;
}
}
return images;
}
在这个方法里,我先开始写成了
int count = 0;
for(int i = 0; i < col; i++){
for(int j = 0; j < row; j++){
images[i][j] = nodes.get(count).getImgFile();
count += 1;
}
}
导致一直出错。
注意到,返回的String[][]是这样的格式:
[[img/13.png, img/14.png, img/23.png, img/24.png],
[img/31.png, img/32.png, img/41.png, img/42.png],
[img/33.png, img/34.png, img/43.png, img/44.png]]
它是由3个1D array构成,每个1D array有四个元素,所以row是3,col是4.
写入二维数组的时候,应该是先row后col.
The first step of this part of the project is to build a graph representation of the contents of berkeley.osm.
Your job will be to override the startElement and endElement methods so that when the SAX parser has completed, you have built a graph.
Part of your job will be decide how to store the graph itself in your GraphDB class. Note that the final step of graph construction is to "clean" the graph, i.e. to destroy all nodes that are disconnected. Unlike the Princeton graph implementation, your GraphDB will need to permit the insertion and deletion of nodes.
int:
int 数据类型是32位、有符号的以二进制补码表示的整数;
最小值是 -2,147,483,648(-2^31);
最大值是 2,147,483,647(2^31 - 1);
一般地整型变量默认为 int 类型;
默认值是 0 ;
例子:int a = 100000, int b = -200000。
long:
long 数据类型是 64 位、有符号的以二进制补码表示的整数;
最小值是 -9,223,372,036,854,775,808(-2^63);
最大值是 9,223,372,036,854,775,807(2^63 -1);
这种类型主要使用在需要比较大整数的系统上;
默认值是 0L;
例子: long a = 100000L,Long b = -200000L。
"L"理论上不分大小写,但是若写成"l"容易与数字"1"混淆,不容易分辩。所以最好大写。