0%

图书管理系统项目中遇见的问题

2017年7月7日 下午6:05

字符串数组转字符串

错误1

1
string = strings.toString();

错误2

1
2
3
4
string = null;
for(int j = 0;j < strings.length;j++){
string += strings[j];
}

输出:
null112155
正确

1
2
3
4
string = "";
for(int j = 0;j < strings.length;j++){
string += strings[j]+"\t";
}

反射只能执行方法,但是得不到对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//获取PriorityFactory对应的Class对象
Class cla=PriorityFactory.class;
//创建PriorityFactory对象
PriorityFactory pf=new PriorityFactory();
//得到method方法
Method met1;
try {
met1 = cla.getMethod(method,null);
//调用method,得到对象
System.out.println(met1.invoke(pf,null));

} catch (Exception e) {
e.printStackTrace();
}

java.lang.classnotfoundexception 反射

错的

1
2
3
4
5
6
7
8

public String[][] getInt(){
String[][] strings = new String[3][1];
strings[0][0] = "query";
strings[1][0] = "buyBook";
strings[2][0] = "findBookById";
return strings;
}
  1. 接口中属性下不来
  2. char[] a转字符串,toString是错的
  3. String.split(”\.”); java分割字符串
1
2
String[] strings = transferString(list);
System.out.println("aaa"+strings);
1
2
3
DefaultTableModel tableModel = (DefaultTableModel) table
.getModel();
tableModel.setRowCount(0);// 清除原有行

解决方案:java - org.jdesktop.swingbinding.JTableBinding$BindingTableModel cannot be cast to javax.swing.table.DefaultTableModel - Stack Overflow

1
2
3
4
5
6
// 将变化的值赋给第9列
//对一个cell同时读写会造成循环
// table_2.setValueAt(string, row, 8);
@Override
public void tableChanged(TableModelEvent e) {
不能更改cell的值

Java中普通代码块,构造代码块,静态代码块区别及代码示例 - sophine - 博客园
Demo2_Student.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package delete;
class Student {
static {
System.out.println("Student 静态代码块");
}

{
System.out.println("Student 构造代码块");
}
public Student() {
System.out.println("Student 构造方法");
}

}

Student.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package delete;
class Demo2_Student {

static {
System.out.println("Demo2_Student静态代码块");
}

public static void main(String[] args) {
System.out.println("我是main方法");

Student s1 = new Student();
Student s2 = new Student();

}
}

输出:
Demo2_Student静态代码块
我是main方法
Student 静态代码块
Student 构造代码块
Student 构造方法
Student 构造代码块
Student 构造方法