看一下你的程序片段:

創(chuàng)新互聯(lián)專(zhuān)注為客戶(hù)提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、潁州網(wǎng)絡(luò)推廣、小程序制作、潁州網(wǎng)絡(luò)營(yíng)銷(xiāo)、潁州企業(yè)策劃、潁州品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供潁州建站搭建服務(wù),24小時(shí)服務(wù)熱線:18980820575,官方網(wǎng)址:chinadenli.net
private class TFListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
String str = tfTxt.getText().trim();
taContent.setText(str);
tfTxt.setText("");
try {
System.out.println(s);
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
控制臺(tái)輸出的第一行 null 就是 System.out.println(s); 的結(jié)果。
而執(zhí)行下面這行:
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
后,一定報(bào)錯(cuò),因?yàn)轭?lèi) ChatClient 的屬性 Socket s 沒(méi)有初始化。
建議將類(lèi) ChatClient 的 main 方法修改成:
public static void main(String[] args) {
new ChatClient().launchFrame();
connect() ;
}
Exception2
finally
分析:
首先NullPointerException被catch(Exception e1)捕獲,打印Exception2,因?yàn)橛衒inally,最終還會(huì)執(zhí)行finally中的代碼。
注意:
IOException不是運(yùn)行期異常,方法顯示拋出,所以,你的run方法肯定要拋出IOException,否則編譯通不過(guò)。
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
public class TestJTable extends JFrame {
JTable table;
DefaultTableModel model;
VectorString v1 = new VectorString();//需要實(shí)例化,估計(jì)你那報(bào)空的應(yīng)該就是這里了
Connection conn;
Statement st;
ResultSet rs;
TestJTable() throws NullPointerException {
Container con = getContentPane();//布局panel
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;DatabaseName=Teststudent",
"sa", "");
st = conn.createStatement();
rs = st.executeQuery("select * from Sc");
ResultSetMetaData rsmd = rs.getMetaData();
int bb = rsmd.getColumnCount();
System.out.println(bb);
// rs.next();
for (int i = 0; i rsmd.getColumnCount(); i++) {
v1.addElement(rsmd.getColumnName(i + 1));
}
model = new DefaultTableModel(null, v1);
table = new JTable(model);
getInfo();
JScrollPane jp1 = new JScrollPane(table);
con.add(jp1);
setSize(500, 400);
setVisible(true);
rs.close();
st.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
void getInfo() {
model.setRowCount(0);
try {
// rs.beforeFirst();
VectorString v2;
while (rs.next()) {
v2 = new VectorString();//需要在這里進(jìn)行實(shí)例化,否則只能得到同一個(gè)vector
for (int i = 1; i = v1.size(); i++) {
v2.addElement(rs.getString(i));
}
//v2填充完畢之后再放入model中,否則會(huì)得到column * row行數(shù)據(jù),并且只有一列
model.addRow(v2);
}
} catch (Exception e) {
e.printStackTrace();
}
model.fireTableStructureChanged();
}
public static void main(String[] args) {
new TestJTable();
}
}
給你改了幾個(gè)地方,已經(jīng)加上注釋了,程序運(yùn)行正常
我看了你的程序,幫你改完了,主要改了getMax函數(shù),你看看吧。
完整的程序如下:
public class dd {
public static void main(String[] args) {
OperaNode op = new OperaNode();
op.addToHead(1);
op.addToHead(2);
op.addToHead(3);
op.addToHead(5);
op.printAll();
op.getMax();
}
}
class Node {
public int data;
public Node next;
public Node(){}
public Node(int i) {
data=i;
next=null;
}
public Node(int i, Node n) {
data = i;
next = n;
}
}
//鏈表類(lèi)
class OperaNode {
public int max;
public Node head, tail;
public OperaNode() {
head = tail = null;
}
// 判斷鏈表是否為空
public boolean isEntry() {
if (head == null) {
return true;
} else {
return false;
}
}
// 在鏈表的頭部添加數(shù)據(jù)
public void addToHead(int l) {
head = new Node(l, head);
if (tail == null) {
tail = head;
}
}
public void printAll() {
Node temp;
for (temp = head; temp != null ; temp = temp.next) {
System.out.println(temp.data);
}
}
public void getMax(){
Node temp =null;
Node tmp =head;
for (temp = head; temp != null ; temp = temp.next){
if(tmp.datatemp.data){
tmp.data=temp.data;
}
//head = head.next;
}
System.out.println(tmp.data);
}
}
運(yùn)行結(jié)果:
5
3
2
1
5
當(dāng)前標(biāo)題:java空指針異常輸出代碼,java對(duì)象數(shù)組空指針異常
當(dāng)前網(wǎng)址:http://chinadenli.net/article12/dsehsdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、網(wǎng)站改版、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)