Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need help fixing error! Posted by kitt1233 on 28 Dec 2010 at 1:11 PM
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:

src\CacheDownloader.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
Report
Re: Need help fixing error! Posted by krishbaloda on 30 Dec 2010 at 5:43 AM
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
}
}
Report
Re: Need help fixing error! Posted by kitt1233 on 30 Dec 2010 at 1:37 PM
Now i got these errors :(

src\CacheDownloader.java:35: <identifier> expected
public int method1668(amount, text)
^
src\CacheDownloader.java:35: <identifier> 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();
}
}
Report
This post has been deleted. Posted by kitt1233 on 30 Dec 2010 at 1:38 PM
This post has been deleted.
Report
Re: Need help fixing error! Posted by krishbaloda on 30 Dec 2010 at 10:14 PM
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.
Report
Re: Need help fixing error! Posted by kitt1233 on 31 Dec 2010 at 2:14 AM
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 :

src\CacheDownloader.java:167: reached end of file while parsing
}→
^
1 error
Press any key to continue . . .

Your the best, Thankyou for your help!
Report
Re: Need help fixing error! Posted by kitt1233 on 31 Dec 2010 at 2:17 AM
It is supposed to download cache to the c:\ and extarct for a client to work (which opens a game)
Report
Re: Need help fixing error! Posted by krishbaloda on 1 Jan 2011 at 5:16 AM
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!!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.