static 使用另一个私类对象也必须声明static

测试正确的:

public static final String getViaHttpsConnection(String url){
        String respBody = ""; // return empty string on bad things       
        getViaHttpsConnectionThread urlThread = new getViaHttpsConnectionThread(143, url);
        urlThread.start();
        respBody = urlThread.getRespBody();
        return respBody;
    }   
    
    //新开线程处理联网
    private static class getViaHttpsConnectionThread extends Thread {
        getViaHttpsConnectionThread(long minPrime, String url) {
            this.minPrime = minPrime;
            this.url = url;
        }

        public void run(){
            int rc = 0;
            
            try {
                System.out.println("debug>UTIL open url:" + url + ";");
                c= (HttpConnection) Connector.open(url + ";deviceside=false;ConnectionTimeout=30000", Connector.READ, true);
                c.setRequestMethod(HttpConnection.GET);
                c.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
                c.setRequestProperty("Cache-Control", "no-store");
                c.setRequestProperty("Connection", "close"); // not sure this is a good idea, but HTTP/1.0 might be less error-prone, some clients have trouble with chunked responses
                System.out.println("debug>UTIL -- connection open;");
                
                // Getting the response code will open the connection,
                // send the request, and read the HTTP response headers.
                // The headers are stored until requested.
                rc = c.getResponseCode();
                System.out.println("debug>UTIL -- got response code" + rc + ";");
                
                // Get the length and process the data
                int len = c.getHeaderFieldInt("Content-Length", 0);

                System.out.println("debug>content-length="+len + ";");
                
                byte[] data = Util.readFromHTTPConnection(c);
                respBody=new String(data);
            } catch (Exception e) {
                respBody = "";//防止上级调用出错,清空
                System.out.println("tip>urlthread error:" + e);
            } finally {
                if (c != null){
                    try {
                        c.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
            
            if (rc != HttpConnection.HTTP_OK) {
                try {
                    throw new OAuthServiceProviderException("tip>HTTP STATU: " + rc, rc, respBody);
                } catch (OAuthServiceProviderException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        
        public String getRespBody(){
            return this.respBody;
        }
        
        private String url = "";
        private long minPrime = 0;
        private HttpConnection c = null;
        private String respBody = "";
    }

 

----------

private static class getViaHttpsConnectionThread extends Thread {

去掉static改成

private class getViaHttpsConnectionThread extends Thread {

 

此句

new getViaHttpsConnectionThread(143, url);

提示出错:

No enclosing instance of type Util is accessible. Must qualify the allocation with an enclosing instance of type Util (e.g. x.new A() where x is an
 instance of Util).

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值