首页 新闻 会员 周边

本人自己做了个获取网页内容的小工具,但是程序运行时总是报错,无法运行求大神指点。

0
悬赏园豆:15 [已关闭问题] 关闭于 2016-02-24 22:02
 1 import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStream;
 4 import java.io.InputStreamReader;
 5 import java.net.HttpURLConnection;
 6 import java.net.URL;
 7 
 8 import javax.swing.JFrame;
 9 import javax.swing.JLabel;
10 import javax.swing.JTextField;
11 
12 public class PassWord
13 {
14     static String str;
15     public void CapturePWD() throws Exception
16     {
17         String strURL = "http://www.ishadowsocks.com";
18 
19         URL url = new URL(strURL);
20 
21         HttpURLConnection httpCoonn = (HttpURLConnection) url.openConnection();
22 
23         InputStreamReader input = new InputStreamReader(httpCoonn.getInputStream(), "utf-8");
24 
25         BufferedReader bufReader = new BufferedReader(input);
26 
27         String line = "";
28         StringBuilder contentBuf = new StringBuilder();
29 
30         while ((line = bufReader.readLine()) != null)
31         {
32             contentBuf.append(line);
33         }
34         String buf = contentBuf.toString();
35 
36         int beginIx = buf.indexOf("A密码");
37         int endIx = buf.indexOf("加密方式:aes-256-cfb");
38 
39         str = buf.substring(beginIx, endIx - 29);
40     }
41 
42     public static void main(String[] args) throws IOException
43     {
44         try
45         {
46             new PassWord().CapturePWD();
47         } catch (Exception e)
48         {
49             // TODO Auto-generated catch block
50             e.printStackTrace();
51         }
52         interFace iF = new interFace();
53         iF.setVisible(true);
54         
55     }
56 
57 }
58 
59 class interFace extends JFrame
60 {     String str = new PassWord().str;
61     private JLabel jLabel;
62     private JTextField jTextField;
63     public interFace()
64     {
65         super();
66         this.setSize(300, 200);
67         this.getContentPane().setLayout(null);
68 //        this.add(getJLabel(),null);
69         
70         jTextField = new javax.swing.JTextField();
71         jTextField.setBounds(96, 49, 160, 20);
72         jTextField.setText(new PassWord().str); 
73         this.add(jTextField);
74         
75     }
76 //    private javax.swing.JLabel getJLabel() { 
77 //          if(jLabel == null) { 
78 //             jLabel = new javax.swing.JLabel(); 
79 //             jLabel.setBounds(96, 49, 160, 20); 
80 //             jLabel.setText(str); 
81 //          } 
82 //          return jLabel; 
83 //       } 
84 }

但是eclipse里面运行没有问题啊!求解,运行时会有这样的提示。。

KicasTec的主页 KicasTec | 初学一级 | 园豆:187
提问于:2016-02-18 15:28
< >
分享
所有回答(2)
0

不知道

浮话 | 园豆:202 (菜鸟二级) | 2016-02-18 15:45

坐等。= =

支持(0) 反对(0) KicasTec | 园豆:187 (初学一级) | 2016-02-18 16:14
0

你用什么程序运行的,我用Eclipse运行没错啊

望曦九练 | 园豆:378 (菜鸟二级) | 2016-02-19 16:00

OSX ,Eclipse JavaEE啊。。。所以很奇怪。。。

支持(0) 反对(0) KicasTec | 园豆:187 (初学一级) | 2016-02-19 21:30

你没有报错么?

支持(0) 反对(0) KicasTec | 园豆:187 (初学一级) | 2016-02-19 21:32

@KicasTec:我用Eclipse运行没报错

支持(0) 反对(0) 望曦九练 | 园豆:378 (菜鸟二级) | 2016-02-20 09:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册