Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help fixing error!

kitt1233kitt1233 Posts: 8Member
I am working on my game and I am having some problems and errors while compiling, well here is my cachedownloader.java:

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.swing.JFrame;

public class CacheDownloader {

private static final int BUFFER = 1024;

/*
* Only things you need to change
*/
private static final int VERSION = 1;
private static String cacheLink = "www.allstarscape.org/cache562.rar";
private static String cacheName = "AllStarScape";

private static String fileToExtract = getCacheDir() + "/"
+ getArchivedName();

private static void drawLoadingText(int amount, String text, client client) {
Class112.method1668(amount, text);
}

private static String getCacheDir() {
return System.getProperty("user.home");
}

private static String getCacheLink() {
return cacheLink;
}

private static int getCacheVersion() {
return VERSION;
}

public static void downloadCache(client client) {
try {
File location = new File(getCacheDir() + "/" + cacheName + "/");
File version = new File(getCacheDir() + "/cache" + cacheName
+ getCacheVersion() + ".dat");

if (!location.exists()) {
downloadFile(getCacheLink(), getArchivedName(), false, client);
unZip();
BufferedWriter versionFile = new BufferedWriter(new FileWriter(
getCacheDir() + "/cache" + cacheName
+ getCacheVersion() + ".dat"));
versionFile.close();
} else {
if (!version.exists()) {
downloadFile(getCacheLink(), getArchivedName(), false,
client);

unZip();

BufferedWriter versionFile = new BufferedWriter(
new FileWriter(getCacheDir() + "/cache" + cacheName
+ getCacheVersion() + ".dat"));
versionFile.close();
} else {
}
}
} catch (Exception e) {

}
}

private static void downloadFile(String adress, String localFileName,
boolean song, client client) {
OutputStream out = null;
URLConnection conn;
InputStream in = null;
try {
URL url = new URL(adress);
out = new BufferedOutputStream(new FileOutputStream(getCacheDir()
+ "/" + localFileName));
conn = url.openConnection();
in = conn.getInputStream();
byte[] data = new byte[BUFFER];
int numRead;
long numWritten = 0;
int length = conn.getContentLength();
while ((numRead = in.read(data)) != -1) {
out.write(data, 0, numRead);
numWritten += numRead;
int percentage = (int) (((double) numWritten / (double) length) * 100D);
drawLoadingText(percentage, (song ? "Song" : "Cache")
+ " Downloaded: " + percentage + "%", client);
}
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}

private static String getArchivedName() {
int lastSlashIndex = getCacheLink().lastIndexOf('/');
if (lastSlashIndex >= 0 && lastSlashIndex < getCacheLink().length() - 1) {
return getCacheLink().substring(lastSlashIndex + 1);
} else {
}
return "";
}

private static void unZip() {
try {
InputStream in = new BufferedInputStream(new FileInputStream(
fileToExtract));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry e;

while ((e = zin.getNextEntry()) != null) {

if (e.isDirectory()) {
(new File(getCacheDir() + "/" + e.getName())).mkdir();
} else {

if (e.getName().equals(fileToExtract)) {
unzip(zin, fileToExtract);
break;
}
unzip(zin, getCacheDir() + "/" + e.getName());
}
}
zin.close();

} catch (Exception e) {
e.printStackTrace();
}
}

private static void unzip(ZipInputStream zin, String s) throws IOException {
FileOutputStream out = new FileOutputStream(s);
byte[] b = new byte[BUFFER];
int len = 0;
while ((len = zin.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
}
}

and here are my errors:

srcCacheDownloader.java:33: cannot find symbol
symbol : method method1668(int,java.lang.String)
location: class Class112
Class112.method1668(amount, text);
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
Press any key to continue . . .

Please help me and update the file, thankyou guyz :D

Comments

  • krishbalodakrishbaloda Posts: 45Member
    Java could not find the the class and method

    Class112.method1668(amount, text);

    you have used in your code.

    you need to declare the

    class Class112
    {
    public int method1668(amount, text)
    {

    // write the code for operation you want to perform
    }
    }
  • kitt1233kitt1233 Posts: 8Member
    Now i got these errors :(

    srcCacheDownloader.java:35: expected
    public int method1668(amount, text)
    ^
    srcCacheDownloader.java:35: expected
    public int method1668(amount, text)
    ^
    2 errors
    Press any key to continue . . .

    lol i need help my file looks like that :

    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;

    import javax.swing.JFrame;

    public class CacheDownloader {

    private static final int BUFFER = 1024;

    /*
    * Only things you need to change
    */
    private static final int VERSION = 1;
    private static String cacheLink = "www.allstarscape.org/cache562.rar";
    private static String cacheName = "AllStarScape";

    private static String fileToExtract = getCacheDir() + "/"
    + getArchivedName();

    private static void drawLoadingText(int amount, String text, client client);
    class Class112
    {
    public int method1668(amount, text)
    {

    // write the code for operation you want to perform
    }
    }

    private static String getCacheDir() {
    return System.getProperty("user.home");
    }

    private static String getCacheLink() {
    return cacheLink;
    }

    private static int getCacheVersion() {
    return VERSION;
    }

    public static void downloadCache(client client) {
    try {
    File location = new File(getCacheDir() + "/" + cacheName + "/");
    File version = new File(getCacheDir() + "/cache" + cacheName
    + getCacheVersion() + ".dat");

    if (!location.exists()) {
    downloadFile(getCacheLink(), getArchivedName(), false, client);
    unZip();
    BufferedWriter versionFile = new BufferedWriter(new FileWriter(
    getCacheDir() + "/cache" + cacheName
    + getCacheVersion() + ".dat"));
    versionFile.close();
    } else {
    if (!version.exists()) {
    downloadFile(getCacheLink(), getArchivedName(), false,
    client);

    unZip();

    BufferedWriter versionFile = new BufferedWriter(
    new FileWriter(getCacheDir() + "/cache" + cacheName
    + getCacheVersion() + ".dat"));
    versionFile.close();
    } else {
    }
    }
    } catch (Exception e) {

    }
    }

    private static void downloadFile(String adress, String localFileName,
    boolean song, client client) {
    OutputStream out = null;
    URLConnection conn;
    InputStream in = null;
    try {
    URL url = new URL(adress);
    out = new BufferedOutputStream(new FileOutputStream(getCacheDir()
    + "/" + localFileName));
    conn = url.openConnection();
    in = conn.getInputStream();
    byte[] data = new byte[BUFFER];
    int numRead;
    long numWritten = 0;
    int length = conn.getContentLength();
    while ((numRead = in.read(data)) != -1) {
    out.write(data, 0, numRead);
    numWritten += numRead;
    int percentage = (int) (((double) numWritten / (double) length) * 100D);
    drawLoadingText(percentage, (song ? "Song" : "Cache")
    + " Downloaded: " + percentage + "%", client);
    }
    } catch (Exception exception) {
    exception.printStackTrace();
    } finally {
    try {
    if (in != null) {
    in.close();
    }
    if (out != null) {
    out.close();
    }
    } catch (IOException ioe) {
    }
    }
    }

    private static String getArchivedName() {
    int lastSlashIndex = getCacheLink().lastIndexOf('/');
    if (lastSlashIndex >= 0 && lastSlashIndex < getCacheLink().length() - 1) {
    return getCacheLink().substring(lastSlashIndex + 1);
    } else {
    }
    return "";
    }

    private static void unZip() {
    try {
    InputStream in = new BufferedInputStream(new FileInputStream(
    fileToExtract));
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry e;

    while ((e = zin.getNextEntry()) != null) {

    if (e.isDirectory()) {
    (new File(getCacheDir() + "/" + e.getName())).mkdir();
    } else {

    if (e.getName().equals(fileToExtract)) {
    unzip(zin, fileToExtract);
    break;
    }
    unzip(zin, getCacheDir() + "/" + e.getName());
    }
    }
    zin.close();

    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    private static void unzip(ZipInputStream zin, String s) throws IOException {
    FileOutputStream out = new FileOutputStream(s);
    byte[] b = new byte[BUFFER];
    int len = 0;
    while ((len = zin.read(b)) != -1) {
    out.write(b, 0, len);
    }
    out.close();
    }
    }
  • kitt1233kitt1233 Posts: 8Member
    This post has been deleted.
  • krishbalodakrishbaloda Posts: 45Member
    You need to specify the Data type of both of these parameters

    like

    public int method1668(int amount, String text)
    {
    //body
    }

    and one thing more to tell you that you will need to write the code according your need in the method body. coz i can't understand what you want from this method to do.
  • kitt1233kitt1233 Posts: 8Member
    Ok so my thing looks like this now :

    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;

    import javax.swing.JFrame;

    public class CacheDownloader {

    private static final int BUFFER = 1024;

    /*
    * Only things you need to change
    */
    private static final int VERSION = 1;
    private static String cacheLink = "www.allstarscape.org/cache562.rar";
    private static String cacheName = "AllStarScape";

    private static String fileToExtract = getCacheDir() + "/"
    + getArchivedName();

    private static void drawLoadingText(int amount, String text, client client);
    class Class112
    {
    public int method1668(int amount, String text)
    {
    //body
    }


    private static String getCacheDir() {
    return System.getProperty("user.home");
    }

    private static String getCacheLink() {
    return cacheLink;
    }

    private static int getCacheVersion() {
    return VERSION;
    }

    public static void downloadCache(client client) {
    try {
    File location = new File(getCacheDir() + "/" + cacheName + "/");
    File version = new File(getCacheDir() + "/cache" + cacheName
    + getCacheVersion() + ".dat");

    if (!location.exists()) {
    downloadFile(getCacheLink(), getArchivedName(), false, client);
    unZip();
    BufferedWriter versionFile = new BufferedWriter(new FileWriter(
    getCacheDir() + "/cache" + cacheName
    + getCacheVersion() + ".dat"));
    versionFile.close();
    } else {
    if (!version.exists()) {
    downloadFile(getCacheLink(), getArchivedName(), false,
    client);

    unZip();

    BufferedWriter versionFile = new BufferedWriter(
    new FileWriter(getCacheDir() + "/cache" + cacheName
    + getCacheVersion() + ".dat"));
    versionFile.close();
    } else {
    }
    }
    } catch (Exception e) {

    }
    }

    private static void downloadFile(String adress, String localFileName,
    boolean song, client client) {
    OutputStream out = null;
    URLConnection conn;
    InputStream in = null;
    try {
    URL url = new URL(adress);
    out = new BufferedOutputStream(new FileOutputStream(getCacheDir()
    + "/" + localFileName));
    conn = url.openConnection();
    in = conn.getInputStream();
    byte[] data = new byte[BUFFER];
    int numRead;
    long numWritten = 0;
    int length = conn.getContentLength();
    while ((numRead = in.read(data)) != -1) {
    out.write(data, 0, numRead);
    numWritten += numRead;
    int percentage = (int) (((double) numWritten / (double) length) * 100D);
    drawLoadingText(percentage, (song ? "Song" : "Cache")
    + " Downloaded: " + percentage + "%", client);
    }
    } catch (Exception exception) {
    exception.printStackTrace();
    } finally {
    try {
    if (in != null) {
    in.close();
    }
    if (out != null) {
    out.close();
    }
    } catch (IOException ioe) {
    }
    }
    }

    private static String getArchivedName() {
    int lastSlashIndex = getCacheLink().lastIndexOf('/');
    if (lastSlashIndex >= 0 && lastSlashIndex < getCacheLink().length() - 1) {
    return getCacheLink().substring(lastSlashIndex + 1);
    } else {
    }
    return "";
    }

    private static void unZip() {
    try {
    InputStream in = new BufferedInputStream(new FileInputStream(
    fileToExtract));
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry e;

    while ((e = zin.getNextEntry()) != null) {

    if (e.isDirectory()) {
    (new File(getCacheDir() + "/" + e.getName())).mkdir();
    } else {

    if (e.getName().equals(fileToExtract)) {
    unzip(zin, fileToExtract);
    break;
    }
    unzip(zin, getCacheDir() + "/" + e.getName());
    }
    }
    zin.close();

    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    private static void unzip(ZipInputStream zin, String s) throws IOException {
    FileOutputStream out = new FileOutputStream(s);
    byte[] b = new byte[BUFFER];
    int len = 0;
    while ((len = zin.read(b)) != -1) {
    out.write(b, 0, len);
    }
    out.close();
    }
    }

    But Im still getting one more error which means its gtting better :

    srcCacheDownloader.java:167: reached end of file while parsing
    }?
    ^
    1 error
    Press any key to continue . . .

    Your the best, Thankyou for your help!
  • kitt1233kitt1233 Posts: 8Member
    It is supposed to download cache to the c: and extarct for a client to work (which opens a game)
  • krishbalodakrishbaloda Posts: 45Member
    Dear Friend,

    I wish if i could help you further!!!

    now the error message seems like that code is working but the file it is reading has no meaningful information.

    or it may be due to u have not written any code in the class112's method.

    read the documentation carefully and implement accordingly.

    Wish u very Happy new year!!
Sign In or Register to comment.