Ad

How To Solve FTP Get Excel File Crash?

- 1 answer

I try to get excel file through FTP server. I checked my app has connected to server. And pop out the toast that "xls linked" then app crash immediately. I had tried if the problem of file type is ASCII or binary. But it not the matter. The inputstream is not null. But I cannot sure if I get data from excel or not. How can I solve it?

FTPClient ftpClient = new FTPClient();
        try{
            Mac = "D123";
            ftpClient.connect("Url", port);
            ftpClient.login(user, pwd);

            ftpClient.setFileType(FTPClient.ASCII_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            InputStream inStream = ftpClient.retrieveFileStream("emimapping.xls");


            if(inStream != null){
                Toast.makeText(homepage.this, "xls linked", Toast.LENGTH_SHORT).show();
            }else Toast.makeText(homepage.this, "xls not link", Toast.LENGTH_SHORT).show();

            Workbook wb = Workbook.getWorkbook(inStream);
            if(wb != null){
                Toast.makeText(homepage.this, "workbook success", Toast.LENGTH_SHORT).show();
            }else Toast.makeText(homepage.this, "workbook is null", Toast.LENGTH_SHORT).show();
            Sheet s = wb.getSheet(0);
            int row = s.getRows();
            int col = s.getColumns();

            for(int i = 0; i < row + 1; i++){
                for(int c = 0; c < col + 1; c++){
                    Cell z = s.getCell(c, i);
                    String content = z.getContents();
                    if(content == Mac){
                        String factory;
                        String line;
                        String station;
                        String custom;
                        factory = s.getCell(c + 1, i ).getContents();
                        line = s.getCell(c + 2, i).getContents();
                        station = s.getCell(c + 3, i).getContents();
                        custom = s.getCell(c + 4, i).getContents();

                        showsite.setText(factory + line + station + custom);

                        cookieManager.setCookie(Url, "eMIBoxPlantCode=" + "KS3;");
                        cookieManager.setCookie(Url, "eMIBoxLineName=" + "I2FA31ASSYA_MFG;" );
                        cookieManager.setCookie(Url, "eMIBoxSeq=" + "2");
                        cookieManager.setCookie(Url, "eMIBoxCustNo=" + "A31");
                        cookieSyncManager.sync();
                        cookieManager.setAcceptThirdPartyCookies(webview, true);
                        String cookie = cookieManager.getCookie(Url);
                        showsite.setText(cookie);
                        webview.loadUrl(Url);
                        setDesktopMode(webview, true);
                    }
                }
            }
            wb.close();
            ftpClient.disconnect();
        }
        catch (Exception e){e.printStackTrace();} 
Ad

Answer

I have got the point that I should change content == Mac into Objects.equals(content, Mac) and it will work.

Ad
source: stackoverflow.com
Ad