A journey through Java

Created class that was a copy and past of the Application States tutorial code for Initializing Familiar Class Fields along with the extension of the SimpleApplication class, I thought it would work fine, however, I keep getting errors on the “super.initialize(stateManager, app);” line. Is there an import I’m missing, or something I’m doing wrong?



Error:









Code:



[java]public class Character extends SimpleApplication {





private SimpleApplication app;

private Node rootNode;

private AssetManager assetManager;

private AppStateManager stateManager;

private InputManager inputManager;

private ViewPort viewPort;

private BulletAppState bullet;



@Override

public void simpleInitApp() {





}



public void initialize(AppStateManager stateManager, Application app) {

super.initialize(stateManager, app);

this.app = (SimpleApplication) app; // can cast Application to something more specific

this.rootNode = this.app.getRootNode();

this.assetManager = this.app.getAssetManager();

this.stateManager = this.app.getStateManager();

this.inputManager = this.app.getInputManager();

this.viewPort = this.app.getViewPort();

this.bullet = this.stateManager.getState(BulletAppState.class);

}

}

[/java]



P.S, is there some way to add spoilers, have a lot of code without spoilers clutters things up.



Thanks

thats because you don’t have an appstate, but more to the point, I have no idea why your doing this inside SimpleApplication when it is the source of all that data in the first place. Your seting the same data to itself

1 Like

Opps…have I been reading the tutorials incorrectly?



A bit of a follow up question, I’ve removed the AppStates section and am left with just the Simple Application bit. However, I now have an error that says, (look below). How can I fix this? (Sorry if this is another really stupid mistake again, and sorry for the original question.)



SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.material.Material.(Material.java:116)

at com.Character.simpleInitApp(Character.java:28)

at com.Main.simpleInitApp(Main.java:21)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:228)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)

at java.lang.Thread.run(Thread.java:680)



[java]

public class Character extends SimpleApplication {

//This is not the Main Class but is called by the Main Class.

//Main Class does not misbehave when doing this.



private String name;

private String job;

private String ranks;



@Override

public void simpleInitApp() {

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry geom = new Geometry(“Box”, b);

Material mat = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Gray); //Why couldn’t it be spelled Grey? :frowning:

geom.setMaterial(mat);

rootNode.attachChild(geom);

}

}

[/java]

@rangerplus10 said:
[java]
public class Character extends SimpleApplication {
//This is not the Main Class but is called by the Main Class.
//Main Class does not misbehave when doing this.
[/java]


How many applications do you want in your application? You have a fundamental misunderstanding with object oriented programming and an application, I think.

Probably, character is not an application. Probably, you want to pass it an application or the things from application that it needs.
2 Likes

I think you are correct, I don’t understand what an application is. I’m trying to figure out how to create a geometry from the Character class, however, I cannot do that within Character with or without the SimpleApplication. Is what I’m meant to be doing (the code below) or am I meant to be doing something else, or should I be rereading the tutorials?





[java]MainClass{



public void createNewGeom(arguments){



rootNode.attachChild(child)

}

}[/java]





[java]Character{

MainClass. createNewGeom(arguments);



}[/java]



Thanks

your character class needs a reference to the SimpleApplication object, it can obtain it in a number of ways, a search of the forums will yield a few results, but this is more a Java related issue not jME, so i suggest learning some more java constructs first.



In any event one way to achieve it is like so:



[java]MainClass extends SimpleApplication {



simpleInitApp () {

Character character = new Character (this);

}

}

[/java]

[java]

Character {

Character (SimpleApplication app) {

app.getRootNode().attachChild (child);

}

}[/java]

1 Like

For what it’s worth: Learning programming basics while also learning to write a game is a bit like learning to tie your shoes while also learning to roller skate. You can do it, but there will be a lot of bruising and both things will easily take twice as long.

2 Likes

I’ve learnt the basics of Java and OO, but, I don’t think I understand JMonkey though the tutorials are very good. I think that I’d better reread the them. :slight_smile:



Edit: I think, based off of Wezrule, I’d better also learn java better. :slight_smile:



I’ll be comming back to JME soon!

@rangerplus10 said:
I've learnt the basics of Java and OO


I really mean this with all due respect as a helpful bit of advice and not a recrimination of your abilities. We all had to start somewhere.

However, it's clear from your posting that you do not yet understand the basics of Java and OO. Something as basic as variable scope and passing references from one class instance to another is still yet to be learned. Keep at it and you'll get there... but you still aren't quite up to the "basics" yet, really.

Edit: didn't see your edit. Good luck with your learning. :)
2 Likes

Thanks to both of you, I’ll be back to JME soon.



P.S. I did not take offense to your learn the basics statement, I know that abilities are not up to par. :slight_smile:

1 Like

Final post:



The Oracle, Java tutorials are actually pretty good provided you have a very basic (my level :)) of understanding.

2 Likes

Well, after 4 days of dividing my time re-learning Java and working on a school code project, I’ve finally finished reading the Java tutorials. I remember reading several days ago a post describing how someone should go about learning Java up to a JME level. Stupidly, I did not bookmark it. I spend about 40 min searching for it, (I dug up some very interesting history in the process) but was unable to find it. The post suggested that the learner should write a game, that I think was either pacman or astroids, rewrite it, and then, the post made several other great suggestions. Could someone help me dig it up or point me in the right direction to look for it?



Thanks,

Ranger

Similar advice has been made several times. The most recent thread I’m aware of is this one:

http://hub.jmonkeyengine.org/groups/general/forum/topic/totally-new-to-everything/

1 Like
@zarch said:
Similar advice has been made several times. The most recent thread I'm aware of is this one:
http://hub.jmonkeyengine.org/groups/general/forum/topic/totally-new-to-everything/

Thank you Zarch, that was exactly what I was looking for!

PS, pspeed, I was pretty arrogant earlier on, I now relise, after actually fully (almost, generics are still a bit fuzzy) learning java, how much I didn't know. Sorry for that.

EDIT:
Shoot! There are many other "paths" I'd better start reading.
1 Like

Don’t take this the wrong way, it’s good that you are keen to learn and are realising when your knowledge is lacking…however don’t expect to have “fully” learnt any programming language in 4 days. There is a reason job adverts measure language experience in years :slight_smile:



There are all sorts of concepts and libraries out there that you are going to need to find, learn how to use, learn what they do and why, etc.



It’s not just the syntax of the language and even language concepts like generics (worth understanding btw, they are very powerful) but things like the standard java libraries and then the 3rd party libraries.



For example any Java programmer that doesn’t know java.collections (don’t need to know every class but at the vary least needs to know what the various collections types are and when you would and wouldn’t use each one) and java.util.concurrant (don’t need to know in as much detail but need to know what is in it and where to go to find the tools when you need them) is essentially useless for any respectable scope project.



And that’s just two packages from the main java libraries…we’ve not even mentioned loads of others some of which are more situational than others but all of which are very powerful.

1 Like

P.S. I can’t recommend this book enough: http://www.amazon.co.uk/Effective-Java-Edition-Joshua-Bloch/dp/0321356683/ref=sr_1_1?ie=UTF8&qid=1351440161&sr=8-1



It is not a beginners book, you need to know Java first, but once you do know Java it is a huge hand up towards going from competent programmer to good programmer. Expert level you need to achieve on your own :slight_smile:

Yh I recommend that book also (zarch also got me reading it :)), although still not fully read it yet.

@zarch said:
Don't take this the wrong way, it's good that you are keen to learn and are realising when your knowledge is lacking...however don't expect to have "fully" learnt any programming language in 4 days. There is a reason job adverts measure language experience in years :)

There are all sorts of concepts and libraries out there that you are going to need to find, learn how to use, learn what they do and why, etc.

It's not just the syntax of the language and even language concepts like generics (worth understanding btw, they are very powerful) but things like the standard java libraries and then the 3rd party libraries.

For example any Java programmer that doesn't know java.collections (don't need to know every class but at the vary least needs to know what the various collections types are and when you would and wouldn't use each one) and java.util.concurrant (don't need to know in as much detail but need to know what is in it and where to go to find the tools when you need them) is essentially useless for any respectable scope project.

And that's just two packages from the main java libraries...we've not even mentioned loads of others some of which are more situational than others but all of which are very powerful.

Alright, I'll edit my statement to say, "I've learnt the bear bones of Java.":) I'll definitely read the book you guys suggested. Thanks.

Good luck!



Just be aware that it’s not a “learn java” book. You need to know Java pretty well first :slight_smile:

1 Like
@zarch said:
Good luck!

Just be aware that it's not a "learn java" book. You need to know Java pretty well first :)

I just found that out...when I had to use Google to understand sections of the first chapter. :) I'll get some practice with what I've learned then I'll start that book again.