java在JFrame中调用整数和双精度。JTextField()。setText();
我刚刚用MVC学习了ORM。我上课
public bookController {
private static final Connection Connection = null;
JFramebookstore frameBookstore;
Bookimpl bookimpl;
List<book> listbook;
// and i just add a function to show a books that choose from JTableBooks
public void showfield(int row) {
frameBookstore.JtextBookid().setText(listbook().get(row).getBookId().toString());
frameBookstore.JtextSellingprice().setText(listbook().get(row).getsellprice().toString());
}
}
调用getBookid()和getbooksellprice()时出错
这是我的构造函数类
public class book {
private int bookid;
private double booksellprice;
public final int getBookid() {
return bookid;
}
public final void setBookid(int bookid) {
this.bookid = bookid;
}
public final double getBooksellprice() {
return booksellprice;
}
public final void setBooksellprice(int booksellprice) {
this.booksellprice= bookselprice;
}
public book(int bookid, double booksellprice){
super();
this.bookid = bookid;
this.booksellprice = booksellprice;
}
@Override
public String toString() {
return "book [bookid=" + bookid + ", booksellprice=" +booksellprice+"]
}
}
我读过tutorial String但仍然无法解决我自己的问题
这是我的bookTable模型扩展AbstractTableModel
public class bookTableModel extends AbstractTableModel {
list<book> books;
public bookTableModel(List<book> books) {
this.books = books;
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return books.size();
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return 2;
}
public String getColumnName(int column) {
switch (column) {
case 0:
return "bookid";
case 1:
return "booksellprice";
default :
return null;
}
}
@Override
public Object getValueAt(int row, int column) {
switch (column) {
case 0:
return books.get(row).getbookid();
case 1:
return books.get(row).getbooksellprice();
default:
return null;
}
}
}
}
这是我的bookDAO类实现bookimpl
'@Override
public class BookDAO implements bookimpl {
private final String select = "SELECT * FROM DSCM.BookData ";
public List<book> getByAll() t{
List<book> books = null;
try {
books = new ArrayList<book>();
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(select);
while (result.next()) {
book b = new book();
b.setbookid(result.getInt("bookid"));
b.setbookid(result.getDouble("booksellprice"));
books.add(book);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return books;
}
}'
这是我的bookimpl课程
public interface bookimpl {
public void insertbook(Book b) throws Dascomerror;
public void updatebook(book b) throws Dascomerror;
public void deletebook(int bookid) throws Dascomerror;
public List<book> getByAll() throws Dascomerror;
'
错误是这样说的
java.lang.NullPointerException
at com.dascom.dao.bookDAO.getByAll(bookDAO.java:138)
at com.dascom.controller.bookController.<init>(bookController.java:38)
at com.dascom.view.JFramebook.<init>(JFramebook.java:136)
# 1 楼答案
你似乎对变量和函数感到困惑。访问变量时不需要
()
您不能取消对
int
和double
的引用,我的意思是.toString()
对于int
,double
之类的基元类型不可用跟着
String.valueOf()
这些函数名在
getBookId()
和getBookid()
中是不同的,看起来像是打字错误getsellprice()
和getBooksellprice()