Deployment problem

Hi, Everyone

I’m already finish my project. It’s about shooting game.

The problem is when I run the jar file from dist folder, it’s will be crashed.

Can you tell me, how to solve this problem?

Thank You ^ ^

Your comment is very helpful, thanks ^ ^

Now I can solved this problem. The errors is about “interface” instead of “Interface” T_T.

But the remaining error is.

When I run application. It’s can not read the text file that I stored in assets/MatDefs folder.

The errors message is “MatDefs/game.lpw (The system cannot find the path specified)”

How to use the class path that you told me, Thank You.

[java]

public int loadLV() {

int level = 0;

String value;

try {

BufferedReader br = new BufferedReader(new FileReader(“assets/MatDefs/game.lpw”));

value = br.readLine();

br.close();



if ( value.trim().equals(“101”) ) {

level = 1;

} else if ( value.trim().equals(“102”) ) {

level = 2;

} else if ( value.trim().equals(“103”) ) {

level = 3;

}



System.out.println("Loaded Level "+level);

} catch ( Exception e ) {

System.out.println(e.getMessage());

}



return level;

}

[/java]

I’m trying to use the class path but It’s still error “null”

[java]BufferedReader br = new BufferedReader(new FileReader(this.getAssetManager().loadAsset(“MatDefs/game.lpw”).toString()));[/java]

No, that won’t work. loadAsset() doesn’t return a location… it returns the asset.



The preferred way is to register your own loader.

http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/AssetManager.html#registerLoader(java.lang.Class,%20java.lang.String...)



But as a hack, you can use:

http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/AssetManager.html#locateAsset(com.jme3.asset.AssetKey)



To get an AssetInfo and from that you can get an InputStream.

1 Like

Thank You Very Much.



I used the zip file method and register to asset manager.



[java]

assetManager.registerLocator(“game.zip”, ZipLocator.class.getName());

[/java]



And read the file by

[java]

BufferedReader br = new BufferedReader(new FileReader(“game.lpw”));

[/java]



It’s work for me, but How about this method?

The first code has nothing to do with the second code. If the second works then it’s because game.lpw exists in the current working directory.



Ignore the zip thing because it’s messing you up.



If you want to read a custom formatted file and want it to work like assets then you have exactly TWO approaches you could take:

  1. register your OWN loader (not locator) to read your format and return your kind of object.
  2. manually get the input stream using locateAsset() and manually read from that stream.



    The first is the JME preferred way but more slightly more complicated than I’m willing to post an example of here.



    The second is something like:

    [java]

    AssetKey myKey = new AssetKey( “pathUnderAssets/game.lpw” );

    AssetInfo info = assetManager.locateAsset(myKey);

    BufferedReader br = new BufferedReader( new InputStreamReader(info.openStream()) );

    [/java]



    I’m typing that from memory and I’ve never actually done that myself as when I had a custom file to read I just wrote my own loader. So there may be issues but that’s the basic idea.
1 Like

Ok Thank You for your suggestion for the better method to me.

Now, I’m change the that code to be the following.

[java]

public int loadLV() {

int level = 0;

String value;

try {

AssetKey myKey = new AssetKey(“MatDefs/game.lpw”);

AssetInfo info = assetManager.locateAsset(myKey);

BufferedReader br = new BufferedReader(new InputStreamReader(info.openStream()));

value = br.readLine();

br.close();

if ( value.trim().equals(“XQZEND”) ) {

level = 1;

} else if ( value.trim().equals(“QXZEDN”) ) {

level = 2;

} else if ( value.trim().equals(“NXEZDQ”) ) {

level = 3;

} else {

level = 1;

}

System.out.println("Loaded Level "+level);

} catch ( Exception e ) {

System.out.println(e.getMessage());

}

return level;

}

[/java]

It’s work, Thank You Guy.

But when I try to do the same method to coding a save level method.

[java]

public void saveLV(int level) {

String levelSTR = "";

if ( level < 0 || level > 3 ) level = 1;

if ( level == 1 ) {

levelSTR = "XQZEND";

} else if ( level == 2 ) {

levelSTR = "QXZEDN";

} else if ( level == 3 ) {

levelSTR = "NXEZDQ";

}

try {

AssetKey myKey = new AssetKey("MatDefs/game.lpw");

AssetInfo info = assetManager.locateAsset(myKey);

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(info.openStream()));

out.write(levelSTR);

out.close();



} catch ( Exception e ){

System.out.println(e.getMessage());

}

}

[/java]



The errors is the following.

error: no suitable constructor found for OutputStreamWriter(InputStream)

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(info.openStream()));

constructor OutputStreamWriter.OutputStreamWriter(OutputStream,CharsetEncoder) is not applicable

(actual and formal argument lists differ in length)

constructor OutputStreamWriter.OutputStreamWriter(OutputStream,Charset) is not applicable

(actual and formal argument lists differ in length)

constructor OutputStreamWriter.OutputStreamWriter(OutputStream) is not applicable

(actual argument InputStream cannot be converted to OutputStream by method invocation conversion)

constructor OutputStreamWriter.OutputStreamWriter(OutputStream,String) is not applicable

(actual and formal argument lists differ in length)

If this is for save games then don’t use the asset manager at all. Save games won’t be bundled inside your assets.jar so there is no reason to do that. Just use regular file operations.

Posting the error message would probably more helpful than posting your code (and not even in code tags)… From what it looks like you have some case errors (e.g. you write “interface/” instead of “Interface/”) when you load assets. Depending on your OS these might work in the IDE as the filesystem might be case insensitive but the class path of the distribution surely isn’t.



Edit: Err, also you use some FileReader directly there, very ugly and not how its supposed to be used. Remember the app later uses the class path for loading things, so load your files via the asset manager or class path.

1 Like