我有一个代码,如果我使用HashMap可以工作,但如果我使用的是TreeMap则不行,任何人都可以告诉为什么会这样?
这是我的代码:
package ka.fil;
import java.util.HashMap;
import java.util.Map;
public class ModelInMemory implements Model {
private Map<String,BeanRecord> map = new HashMap<>();
@Override
public void putRecord(BeanRecord beanRecord) {
map.put(beanRecord.getEmail(), beanRecord);
}
@Override
public BeanRecord getRecord(String email) {
BeanRecord r = map.get(email);
return r;
}
@Override
public Iterable<BeanRecord> allRecord() {
return map.values();
}
public ModelInMemory() {
}
}
Run Code Online (Sandbox Code Playgroud)
我的意思是不工作是当我在主方法中使用它时,我得到这个:
Exception in thread "main" java.lang.NullPointerException at
java.util.TreeMap.compare(Unknown Source) at java.util.TreeMap.put(Unknown Source)
at ka.fil.ModelInMemory.putRecord(ModelInMemory.java:11)
at ka.fil.AppBatch.main(AppBatch.java:10)
Run Code Online (Sandbox Code Playgroud) 任何人都可以告诉我为什么当我明确将其设置为60px时,我的标签的宽度设置为自动?
这是我的HTML(带嵌入式CSS):
<!DOCTYPE html>
<html>
<head>
<title>TestMenu </title>
</head>
<style type="text/css">
.container{
padding: 0px 10px;
background-color: #eee;
}
ul li a{
width:60px;
text-align: center;
color: red;
}
ul{
border: red solid 1px;
width: 492px;
}
ul li{
width: auto;
display: inline-block;
padding: 5px;
margin: auto;
}
</style>
<body>
<div class="container">
<ul>
<li><a href="#">Lundi</a></li>
<li><a href="#">Mardi</a></li>
<li><a href="#">Mercredi</a></li>
<li><a href="#">Jeudi</a></li>
<li><a href="#">Vendredi</a></li>
<li><a href="#">Samedi</a></li>
<li><a href="#">Dimanche</a></li>
</ul>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的猜测是,这是由于继承或浏览器特定的东西,但我无法弄清楚到底是什么.
我正在学习Java I/O,当我编译这段代码时:
import java.io.File;
public class Main {public static void main(String[] args){
//Creation of the File object
File f = new File("test.txt");
System.out.println("File absolute path : " + f.getAbsolutePath());
System.out.println("File name : " + f.getName());
System.out.println("Does it exist ? " + f.exists());
System.out.println("Is it a directory? " + f.isDirectory());
System.out.println("Is it a file ? " + f.isFile());
}
Run Code Online (Sandbox Code Playgroud)
问题是f.exists() 并f.isFile()返回false
这怎么可能呢 ?