上传文件时出现NullPointerException

上传文件时,出现以下错误: Struts Problem Report Struts has detected an unhandled exception: Messages: File: java/io/File.java Line number: 317 Stacktraces java.lang.NullPointerException java.io.File.(File.java:317) example.uploadFile.execute(uploadFile.java:36) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav‌​a:43) java.lang.reflect.Method.invoke(Method.java:483) 的index.jsp Upload your file uploadFile.java package example; import java.io.File; import org.apache.commons.io.FileUtils; import java.io.IOException; import com.opensymphony.xwork2.ActionSupport; public class uploadFile extends ActionSupport { private File myFile; private String myFileContentType; private String myFileFileName; […]

SAX解析和特殊字符

我想使用SAX解析器从xml文件解析一些数据。 我的xml如下: Pies & past Fruits 为了解析这些数据,我扩展了DefaultHandler。 解析后的输出是: cat 1 = Pies cat 2 = & cat 3 = past cat 4 = Fruits 为什么会发生这种情况而不是: cat 1 = Pies & past cat 2 = Fruits

无法检索使用存储过程选择的值

我正在努力寻找记录。 这让我选择使用存储过程在我的数据库中查找现有记录。 当我试图搜索现有数据时,它没有给我我想要的价值。 当我点击搜索按钮时,它不会将值打印到文本字段。 码 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { String searchSection = Section_SearchSection_Textfield.getText(); String searchSection_Name = Section_SectionName_TextField.getText(); int sectionID = 0; if (searchSection.isEmpty()) { JOptionPane.showMessageDialog(null, “Please fill up this fields”); } else try (Connection myConn = DBUtil.connect()) { try (CallableStatement myFirstCs = myConn.prepareCall(“{call getSECTION_NAME(?,?)}”)) { myFirstCs.setInt(1, sectionID);// I set the ID for Primary Key […]

Java内存中究竟是什么null

如果我声明一些字符串变量 String str = null; 是否为变量str分配了内存? 如果已分配,将分配多少字节? 如果没有分配,JVM如何知道有一些名为str变量被声明? 如果已分配并且内存中null值,那么二进制中的null表示究竟是什么?

spring singleton bean字段未填充

我需要一个服务(单身适合)与一些内部字段,如一个挂起的线程列表(是的一切都被编写为线程安全)问题是,如果我@autowire这个bean,字段似乎是空的。 调试我看到代理正确绑定到实例(字段CGLIB$CALLBACK_X正确链接到填充的bean),填充字段,但它提供的字段为空。 以下代码行概括了我正在谈论的内容。 @Service public class myService{ @Autowired private Monitor monitor; public List getSomething(){ return monitor.getList(); } } @Service public class myStatefulService{ //This field will be populated for sure by someone before getSomething() is called private List list; public synchronized List getSomething(){ return this.list; } //Called by other services that self inject this bean public […]

BigDecimal来自Double不正确的值?

我试图从字符串中创建一个BigDecimal。 不要问我为什么,我只是需要它! 这是我的代码: Double theDouble = new Double(“.3”); System.out.println(“The Double: ” + theDouble.toString()); BigDecimal theBigDecimal = new BigDecimal(theDouble); System.out.println(“The Big: ” + theBigDecimal.toString()); 这是我得到的输出? The Double: 0.3 The Big: 0.299999999999999988897769753748434595763683319091796875 有任何想法吗?

使用Swing Timer暂时隐藏通知

我正在使用Swing Timer来制作webNotification ,一种自定义JFrame ,会在特定时间出现。 我希望用户可以选择单击“隐藏”按钮来取消通知,并在一小时后返回。 我怎样才能做到这一点?

为什么不能将类定义为受保护的?

我知道这是一个愚蠢的问题,但我仍然怀疑需要清除。 我的问题是, 为什么我们不能将类定义为protected ? 我知道我们不能,但为什么呢? 应该有一些具体的原因。

绘制背景图像

我绘制的图像是我的背景图像,一切都很好但是当我试图在框架中添加一些JButton时,整个业务出错了我绘制的图片消失了,我看到了原始背景。 图片看起来像这样: public void paint(Graphics g){ g.drawImage(bg, 0, 0, null); } 我想我的问题是paint方法的问题,需要提一下我正在扩展JFrame类。 编辑:这里有一些图片来展示我的意思。 它首先绘制我的图像: 当我将鼠标移动到我应该绘制的按钮的位置时,这就是我得到的:

使用nextInt和nextLine()时出现问题

这不是让我把我的名字,但它的年龄是否正常。 我知道我可以改变陈述的顺序,但还有另一种方法吗? import java.util.Scanner; public class ScannerErr2 { public static void main(String [] args) { Scanner keyboard= new Scanner(System.in); String name; int age; System.out.print(“Enter your age : “); age= keyboard.nextInt(); System.out.print(“Enter your name: “); name= keyboard.nextLine(); System.out.println(“Age : “+age); System.out.println(“Name: “+name); } }