Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 16:11

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Java]Was ist hier falsch?

Discussion on [Java]Was ist hier falsch? within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
Regen.'s Avatar
 
elite*gold: 0
Join Date: Dec 2010
Posts: 509
Received Thanks: 41
[Java]Was ist hier falsch?

hey,

bin noch nicht so die Leuchte in Java .

kann mir jemand sagen was an diesem Script ausschnitt falsch ist bzw. es Korrigieren?

Code:
for (int i = 0; i < urlList.length; i++) {
            if (skip[i] != 0) {
                percentage = (initialPercentage + fileSizes[i] * 45 / totalSizeDownload);
            }
            else
            {
                try
                {
                    md5s.remove(getFileName(urlList[i]));
                    md5s.store(new FileOutputStream(versionFile), "md5 hashes for downloaded files");
                } catch (Exception e) {
                    e.printStackTrace();
                }

                int unsuccessfulAttempts = 0;
                int maxUnsuccessfulAttempts = 3;
                boolean downloadFile = true;

                while (downloadFile) {
                    downloadFile = false;

                    URLConnection urlconnection = urlList[i].openConnection();

                    String etag = "";

                    if ((urlconnection instanceof HttpURLConnection)) {
                        urlconnection.setRequestProperty("Cache-Control", "no-cache");

                        urlconnection.connect();

                        etag = urlconnection.getHeaderField("ETag");
                        etag = etag.substring(1, etag.length() - 1);
                    }

                    String currentFile = getFileName(urlList[i]);
                    InputStream inputstream = getJarInputStream(currentFile, urlconnection);
                    FileOutputStream fos = new FileOutputStream(path + currentFile);

                    long downloadStartTime = System.currentTimeMillis();
                    int downloadedAmount = 0;
                    int fileSize = 0;
                    String downloadSpeedMessage = "";

                    MessageDigest m = MessageDigest.getInstance("MD5");
                    int bufferSize;
                    while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1)
                    {
                        int bufferSize;
                        fos.write(buffer, 0, bufferSize);
                        m.update(buffer, 0, bufferSize);
                        currentSizeDownload += bufferSize;
                        fileSize += bufferSize;
                        percentage = (initialPercentage + currentSizeDownload * 45 / totalSizeDownload);
                        subtaskMessage = ("Retrieving: " + currentFile + " " + currentSizeDownload * 100 / totalSizeDownload + "%");

                        downloadedAmount += bufferSize;
                        long timeLapse = System.currentTimeMillis() - downloadStartTime;

                        if (timeLapse >= 1000L) {
                            float downloadSpeed = downloadedAmount / (float)timeLapse;
                            downloadSpeed = (int)(downloadSpeed * 100.0F) / 100.0F;
                            downloadSpeedMessage = " @ " + downloadSpeed + " KB/sec";
                            downloadedAmount = 0;
                            downloadStartTime += 1000L;
                        }

                        subtaskMessage += downloadSpeedMessage;
                    }

                    inputstream.close();
                    fos.close();
                    String md5 = new BigInteger(1, m.digest()).toString(16);
                    while (md5.length() < 32) {
                        md5 = "0" + md5;
                    }
                    boolean md5Matches = true;
                    if (etag != null) {
                        md5Matches = md5.equals(etag);
                    }

                    if ((urlconnection instanceof HttpURLConnection)) {
                        if ((md5Matches) && ((fileSize == fileSizes[i]) || (fileSizes[i] <= 0)))
                        {
                            try {
                                md5s.setProperty(getFileName(urlList[i]), etag);
                                md5s.store(new FileOutputStream(versionFile), "md5 hashes for downloaded files");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            unsuccessfulAttempts++;
                            if (unsuccessfulAttempts < maxUnsuccessfulAttempts) {
                                downloadFile = true;
                                currentSizeDownload -= fileSize;
                            } else {
                                throw new Exception("failed to download " + currentFile);
                            }
                        }
                    }
                }
            }
        }
IntelliJ zeigt mir den Fehler in Zeile 2 an. Das wäre dann das hier:
Code:
if (skip[i] != 0) {
Hier ist nochmal ein Bild von intelliJ:


gruß
Regen.
Regen. is offline  
Old 06/29/2012, 15:26   #2
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
kein java experte, aber der fehlermeldung entnehme ich, dass "skip" ein array von booleans ist, und es in java nicht erlaubt ist einen bool mit einem int zu vergleichen.

folgende möglichkeiten:

0 auf ungleichheit mit 0 prüfen:
Code:
if (skip[i] != (0 != 0))
false benutzen:
Code:
if (skip[i] != false)
unnötigen mist lassen:
Code:
if (skip[i])
Dr. Coxxy is offline  
Thanks
1 User
Old 06/29/2012, 23:38   #3


 
manniL's Avatar
 
elite*gold: 294
The Black Market: 193/0/0
Join Date: Feb 2008
Posts: 6,734
Received Thanks: 1,315
Quote:
Originally Posted by Dr. Coxxy View Post
kein java experte, aber der fehlermeldung entnehme ich, dass "skip" ein array von booleans ist, und es in java nicht erlaubt ist einen bool mit einem int zu vergleichen.

folgende möglichkeiten:

0 auf ungleichheit mit 0 prüfen:
Code:
if (skip[i] != (0 != 0))
false benutzen:
Code:
if (skip[i] != false)
unnötigen mist lassen:
Code:
if (skip[i])
Genau so sieht es aus.

Da wir keine näheren Infos zu deiner skip() Methode haben können wir nur den oben genannten Rat geben.
manniL is offline  
Reply


Similar Threads Similar Threads
Was ist hier falsch ????
09/14/2010 - AutoIt - 6 Replies
dieses kleine script soll nichts weiter als einen zeitbalken überwachen. der balken ist erst braun und färbt sich allmählich von links nach rechts rot. nun will ich einen pixel am ende des balkens überwachen, und sobald er sich umfärbt die nächsten schritte abarbeiten. For $i=1 to 2000 sleep (2000) MouseClick("left",405,379,1, sleep (2000)) $Pixel = 0x572A11 While $Pixel = 0x572A11 $Pixel = PixelGetColor (747,700)
was is hier falsch ?!
07/01/2010 - AutoIt - 8 Replies
ohh ?! hier kommt immer eine fehler meldung aber ich weis nicht was das heißt ? hier is der script xD $input3=GuiCtrlCreateInput("829, 39",65,97,65,20) $input4=GuiCtrlCreateInput("674, 332",155,96,70,20) $input5=GuiCtrlCreateInput("0xF9F5F8",1 13,134,61,20) $PixelSearch = PixelSearch (GUICtrlRead ($input3),GUICtrlRead ($input4), GUICtrlRead ($input5), 0 )
Java: Was mache ich Falsch?
12/29/2009 - General Coding - 4 Replies
Ich weiß nicht ob das hier rein gehört sry <SCRIPT language=JavaScript> var start = "http://static.************/sites/default/fil es/daily/post/"; var ende = "-bannerImage.jpg" SimpleDateFormat df = new SimpleDateFormat( "yyyyMMdd" ); expdate = new Date(date); curdate = new Date(); var datum = System.out.println( "Date = " + df.format( dt ) ); document.write("<img src="start + datum + ende">");
war falsch hier
11/21/2006 - Private Server - 0 Replies
-.- sry war falsch hier



All times are GMT +1. The time now is 16:11.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.