御姐乱太郎 2017-11-08 07:10 采纳率: 0%
浏览 920

我android studio导入别人demo,直接run成功后为什么打开代码还会有import错误

我android studio导入别人demo,直接run成功后为什么打开代码还会有import错误,关键不理会错误直接run还是能成功╮( ̄▽ ̄")╭图片说明

  • 写回答

1条回答

  • sinat_36820379 2017-11-08 07:18
    关注

    package com.hand.demo;

    import java.io.BufferedReader;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.Base64;
    import java.util.List;
    import java.util.Map;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.zip.GZIPInputStream;

    public class ItemQuery {
    private static String reportServiceUrl = "https://efcw.bi.ap4.oraclecloud.com/xmlpserver/services/v2/ReportService";
    private static String uid = "tn.webservice";
    private static String pwd = "Welcome123";

    public static String httpPost(String destUrl, String postData, String authStr, String soapAction) throws Exception {
        String response = "";
    
        URL url = new URL(destUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        if (conn == null) {
            return null;
        }
        conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
        conn.setRequestProperty("SOAPAction", soapAction);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setUseCaches(false);
        conn.setFollowRedirects(true);
        conn.setAllowUserInteraction(false);
        conn.setRequestMethod("POST");
    
        System.out.println("==================Service request headers: ================ ");
        Map<String, List<String>> requestHeaders = conn.getRequestProperties();
        for (String k : requestHeaders.keySet()) {
            System.out.println(k + ":" + requestHeaders.get(k));
        }
    
        byte[] authBytes = authStr.getBytes("UTF-8");
        String auth = new String(Base64.getEncoder().encode(authBytes));
        conn.setRequestProperty("Authorization", "Basic " + auth);
    
        System.out.println("==================Service request body: ================ ");
        System.out.println(postData);
    
        OutputStream out = conn.getOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
        writer.write(postData);
        writer.close();
        out.close();
    
        System.out.println("==================Service response: ================ ");
        System.out.println(
                "connection status: " + conn.getResponseCode() + "; connection response: " + conn.getResponseMessage());
    
        System.out.println("==================Service response headers: ================ ");
        for (int i = 0;; i++) {
            String mine = conn.getHeaderField(i);
            if (mine == null)
                break;
            System.out.println(conn.getHeaderFieldKey(i) + ":" + mine);
        }
    
        int respCode = conn.getResponseCode();
        if (respCode != 200) {
            InputStream ei = conn.getErrorStream();
    
            response = readGzipStr(ei);
            ei.close();
    
            return response;
        }
    
        InputStream in = conn.getInputStream();
        InputStreamReader iReader = new InputStreamReader(in);
        BufferedReader bReader = new BufferedReader(iReader);
    
        String line;
    
        System.out.println("==================Service response: ================ ");
    
        while ((line = bReader.readLine()) != null) {
            response += line;
        }
        iReader.close();
        bReader.close();
        in.close();
        conn.disconnect();
    
        return response;
    }
    
    public static String readGzipStr(InputStream in) {
        String str = "";
        GZIPInputStream gunzip = null;
        try {
            gunzip = new GZIPInputStream(in);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            byte[] buffer = new byte[1024];
            int offset = -1;
            while ((offset = gunzip.read(buffer)) != -1) {
                out.write(buffer, 0, offset);
            }
    
            str = out.toString();
    
            out.flush();
            out.close();
    
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (gunzip != null) {
                try {
                    gunzip.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    
        return str.toString();
    }
    
    public static String queryItemData() {
        String payTemplate = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v2=\"http://xmlns.oracle.com/oxp/service/v2\">"
                + "    <soapenv:Header/>" 
                + "    <soapenv:Body>" + "        <v2:runReport>"
                + "            <v2:reportRequest>"
                + "                <v2:attributeCalendar>Gregorian</v2:attributeCalendar>"
                + "                <v2:attributeFormat>xml</v2:attributeFormat>"
                + "                <v2:attributeLocale>en_US</v2:attributeLocale>"
                + "                <v2:attributeUILocale>en_US</v2:attributeUILocale>"
                + "                <v2:attributeTimezone>China/Hong_Kong</v2:attributeTimezone>"
                + "                <v2:parameterNameValues>" 
                + "                    <v2:listOfParamNameValues>"
                + "                        <v2:item>" 
                + "                            <v2:dataType>String</v2:dataType>"
                + "                            <v2:name>P_LIMIT</v2:name>"
                + "                            <v2:values>" 
                + "                                <v2:item>10</v2:item>"
                + "                            </v2:values>" 
                + "                        </v2:item>"
                + "                        <v2:item>" 
                + "                            <v2:dataType>String</v2:dataType>"
                + "                            <v2:name>P_PAGE</v2:name>"
                + "                            <v2:values>" 
                + "                                <v2:item>1</v2:item>"
                + "                            </v2:values>" 
                + "                        </v2:item>"
                + "                    </v2:listOfParamNameValues>" 
                + "                </v2:parameterNameValues>"
                + "                <v2:reportAbsolutePath>/Custom/Procurement/Custom Interface/XXTN_INT_RPT_ITEMS_EBS.xdo</v2:reportAbsolutePath>"
                + "            </v2:reportRequest>" 
                + "            <v2:userID>%s</v2:userID>"
                + "            <v2:password>%s</v2:password>" 
                + "        </v2:runReport>" 
                + "    </soapenv:Body>"
                + "</soapenv:Envelope>";
        String requestPayload = String.format(payTemplate, uid, pwd);
        String response = "";
        String soapAction = "http://xmlns.oracle.com/xmlpserver/services/v2/ReportService";
    
        try {
    
            response = httpPost(reportServiceUrl, String.format(requestPayload), uid + ":" + pwd,
                    soapAction);
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    
        Pattern p = Pattern.compile("reportBytes>(.*)<\\/reportBytes>");
        Matcher m = p.matcher(response);
        while (m.find()) {
            response = m.group(1);
            response = new String(Base64.getDecoder().decode(response));
        }
    
        return response;
    }
    
    public static void main(String[] args){
        String result = queryItemData();
        System.out.println(result);
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛