高手帮忙看看这个错误怎么解决

shuiyihan 2008-05-12 03:19:06
在netbeans中运行出现错误
代码如下:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.xml.namespace.*;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import java.net.*;

import XRSystem.DataAccess.*;
import XRSystem.Util.*;
import XRSystem.Process.*;

public class StoreXMLFrame extends javax.swing.JFrame {

/** Creates new form StoreXMLFrame */
public StoreXMLFrame() {
initComponents();
}

private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jPanel2 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();

new XRSystem.Util.PlafView().ChangeView();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("\u5b58\u50a8XML\u6587\u6863");
setResizable(false);
jTextPane1.setFont(new java.awt.Font("Times New Roman", 1, 14));
jTextPane1.setEditable(false);
jScrollPane1.setViewportView(jTextPane1);

jButton1.setFont(new java.awt.Font("宋体", 1, 14));
jButton1.setText("\u6253\u5f00XML");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setFont(new java.awt.Font("宋体", 1, 14));
jButton2.setText("\u5b58\u50a8XML");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
.add(39, 39, 39)
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 88, Short.MAX_VALUE)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(54, 54, 54))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
);

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 381, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 291, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(17, 17, 17)
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(18, Short.MAX_VALUE))
);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 383, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
URL FileURL;
boolean flag;
try {
FileURL = new URL("file:\\"+FilePath);
System.out.println(FileURL.toString());
flag=ThisXRSystem.StoreData(FileURL);
if(flag)
JOptionPane.showMessageDialog(this, "文档已存入数据库");
}catch(Exception e) {
JOptionPane.showMessageDialog(this, e);
}
this.dispose();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
//String ThisPath = GetFileURL();
openFile();
}
...全文
155 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_nuo 2008-05-16
  • 打赏
  • 举报
回复
不客气,共同学习!
shuiyihan 2008-05-15
  • 打赏
  • 举报
回复
感谢您的热心帮助,那个问题解决了,非常感谢
shuiyihan 2008-05-14
  • 打赏
  • 举报
回复
已经发到您的邮箱,请帮忙看看,拜托
a_nuo 2008-05-14
  • 打赏
  • 举报
回复
你给我的还是却几个包
不过问题看出来了
是你的builder变量没有创建对象!所以此句doc = builder.parse(f); 抛出异常

在此句前加一句builder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
随后捕获ParserConfigurationException就可以了

a_nuo 2008-05-13
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 a_nuo 的回复:]
不大的话发给我
t_gaolp@jbridge.com.cn
[/Quote]错了
t-gaolp@jbridge.com.cn;
打包成rar格式
然后去掉扩展名再发给我


a_nuo 2008-05-13
  • 打赏
  • 举报
回复
不大的话发给我
t_gaolp@jbridge.com.cn
a_nuo 2008-05-13
  • 打赏
  • 举报
回复
import XRSystem.DataAccess.*;
import XRSystem.Util.*;
import XRSystem.Process.*;
你的这几个包我这里没有啊
shuiyihan 2008-05-13
  • 打赏
  • 举报
回复
File f = chooser.getSelectedFile();
if(f==null){return;}
FilePath = f.getAbsolutePath();
我这样改了,还是不对啊,大哥再帮看看
a_nuo 2008-05-13
  • 打赏
  • 举报
回复
if(f==null){
return;
}
shuiyihan 2008-05-13
  • 打赏
  • 举报
回复
大哥说下具体怎么改,我改了好象还是不对
a_nuo 2008-05-12
  • 打赏
  • 举报
回复
if(f==null){
//加上你的处理代码就可以了
}
a_nuo 2008-05-12
  • 打赏
  • 举报
回复
就是这里
File f = chooser.getSelectedFile();
getSelectedFile();
此方法如果返回null
那么你就会出现空指针异常了
shuiyihan 2008-05-12
  • 打赏
  • 举报
回复
private void openFile() {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));

chooser.setFileFilter(new
javax.swing.filechooser.FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml");
}
public String getDescription() { return "XML files"; }
});
int r = chooser.showOpenDialog(this);
if (r != JFileChooser.APPROVE_OPTION) return;
File f = chooser.getSelectedFile();
FilePath = f.getAbsolutePath();
try {
byte[] bytes = new byte[(int) f.length()];
new FileInputStream(f).read(bytes);
jTextPane1.setText(new String(bytes));
doc = builder.parse(f);
} catch (IOException e) {
JOptionPane.showMessageDialog(this, e);
} catch (SAXException e) {
JOptionPane.showMessageDialog(this, e);
}
}

不知道是不是这段代码有错误,高手帮忙看看
a_nuo 2008-05-12
  • 打赏
  • 举报
回复
写出相关的处理代码
a_nuo 2008-05-12
  • 打赏
  • 举报
回复
判断文件是否选中
即返回的File对象是否为空
shuiyihan 2008-05-12
  • 打赏
  • 举报
回复
189行是 doc = builder.parse(f);
要怎样修改呢
shuiyihan 2008-05-12
  • 打赏
  • 举报
回复
要怎么修改呢?
吐司vivi 2008-05-12
  • 打赏
  • 举报
回复
空指针异常 查看你得源代码189行 不都写出来了吗
shuiyihan 2008-05-12
  • 打赏
  • 举报
回复
出现错误提示如下:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at XRSystem.GUI.StoreXMLFrame.openFile(StoreXMLFrame.java:189)
at XRSystem.GUI.StoreXMLFrame.jButton1ActionPerformed(StoreXMLFrame.java:144)
at XRSystem.GUI.StoreXMLFrame.access$000(StoreXMLFrame.java:29)
at XRSystem.GUI.StoreXMLFrame$1.actionPerformed(StoreXMLFrame.java:58)
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:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

哪位高手能指导下要怎么修改?
shuiyihan 2008-05-12
  • 打赏
  • 举报
回复
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new StoreXMLFrame().setVisible(true);
}
});
}
/*
private String GetFileURL() {
openFile();
return FilePath;
}
*/
private void openFile() {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));

chooser.setFileFilter(new
javax.swing.filechooser.FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml");
}
public String getDescription() { return "XML files"; }
});
int r = chooser.showOpenDialog(this);
if (r != JFileChooser.APPROVE_OPTION) return;
File f = chooser.getSelectedFile();
FilePath = f.getAbsolutePath();
/*
try{
URL FileURL = new URL("file://"+FilePath);
}catch(Exception e) {
JOptionPane.showMessageDialog(this, e);
}
*/
try {
byte[] bytes = new byte[(int) f.length()];
new FileInputStream(f).read(bytes);
jTextPane1.setText(new String(bytes));
doc = builder.parse(f);
} catch (IOException e) {
JOptionPane.showMessageDialog(this, e);
} catch (SAXException e) {
JOptionPane.showMessageDialog(this, e);
}
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextPane jTextPane1;
private Document doc;
private DocumentBuilder builder;
private String FilePath;
private URL FileURL;
private StartProcess ThisXRSystem = new StartProcess();
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧