0
所以我从数据库中提取信息并将它们放入我的GUI中的字段/框中。JTextArea没有设置,抛出错误
houseText和addressText都是文本字段,它们设置正常,但oInfo是JTextArea,当我尝试设置它时会导致错误。我也尝试使用'追加',但它没有改变任何东西。任何解决方案
infoHolder = dBStatement.executeQuery("SELECT * FROM House");
infoHolder.next();
hName = infoHolder.getString("Name");
hAddress = infoHolder.getString("Address");
numRooms = infoHolder.getInt("numRooms");
Type = infoHolder.getString("Type");
charge = infoHolder.getString("roomCharge");
Access = infoHolder.getString("dAccess");
Info = infoHolder.getString("oInfo");
// the below print prints all the details to prove that the database has been read correctly.
System.out.println(hName + " " + hAddress + " " + numRooms + " " + Type + " " + charge + " " + Access + " " + Info);
houseText.setText(" " + hName);
addressText.setText(" " + hAddress);
//roomNumber.setSelectedItem(numRooms);
//roomType.setSelectedItem(" " + Type);
//chargeRoom.setSelectedItem(" " + charge);
//access.setSelectedItem(" " + Access);
oInfo.setText(Info);
堆栈跟踪:为了完整起见,和其他一些次要的信息
java.lang.NullPointerException at FinalBAndB.initialiseDatabase(FinalBAndB.java:124)
at FinalBAndB$1.run(FinalBAndB.java:274)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
你得到了什么错误,你从哪里调用这段代码?它是一个事件处理程序,一些其他线程? – npinti 2015-02-06 13:30:11
@npinti我打电话从我的公共静态无效的主要代码。上面的代码在它自己的方法里面,名为initialiseDatabase(); textfields设置完美,但textarea(oinfo)是问题。我在打印堆栈跟踪的方法上有一个异常处理程序,但它没有任何启发性。 infoHolder是一个结果集。 – user3822332 2015-02-06 13:34:16
什么不启发乔可能会启发杰克。堆栈跟踪不是FYEO。 – laune 2015-02-06 13:53:21