当前位置: 代码迷 >> J2SE >> 空指针错误,看了好久好久,实在看不出来,求帮助
  详细解决方案

空指针错误,看了好久好久,实在看不出来,求帮助

热度:53   发布时间:2016-04-24 00:55:03.0
空指针异常,看了好久好久,实在看不出来,求帮助
写一个简单的下载工具,一直报空指针异常
java.lang.NullPointerException
at index.download.StartDownload.startLoad(StartDownload.java:24)
at index.NewTaskFrame$1.actionPerformed(NewTaskFrame.java:93)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)




//单个资源类
package index.download;

import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

public class Source {
private String urlAddress;
private String savePath;
private String fileName;
private ArrayList<Part> parts;
public Source(String urlAddress,String savePath,String fileName){
this.urlAddress=urlAddress;
this.savePath=savePath;
this.fileName=fileName;
}
public ArrayList<Part> getParts(){
return parts;
}
public String getUrlAddress() {
return urlAddress;
}
public void setUrlAddress(String urlAddress) {
this.urlAddress = urlAddress;
}
public String getSavePath() {
return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public int getFileLength(){
int length=0;
try {
URL url=new URL(urlAddress);
URLConnection connection=url.openConnection();
connection.connect();
length=connection.getContentLength();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return length;
}
}


//对资源进行分块类
package index.download;

import java.util.UUID;

public class Part {
private int start;
private int length;
private int hasload;
private String partName;
private int currentLoad;
public Part(int start,int length){
this.start=start;
this.length=length;
currentLoad=0;
this.partName=UUID.randomUUID()+".part";
}

public int getCurrentLoad() {
return currentLoad;
}

public void setCurrentLoad(int currentLoad) {
  相关解决方案