TOO EASY QUESTION ALERT: Modifying camera externally

I apologize in advance if this question is silly, i’m a very beginner in java and especially with graphics.



So I have a class called mainAnimation.java where all the animation is happening. I want to be able to access the camera from an external class and modify its location.



I wrote this:



[java]

private static mainAnimation myApp;

private static AssetManager assetManager;



public static void main(String args[]){



// location of the trace file

String url = “blablabla.trc”;



// create instance of Jme3Cinematics

mainAnimation myApp = new mainAnimation(url);





assetManager = myApp.getAssetManager();





// Play button

myApp.start();



System.out.println(“TTTTTTEESSTTTTTTT”);

// Setup second view - upper right



myApp.cam2.setViewPort(0f, 0f, 0f, 0f);

myApp.cam2.setLocation(new Vector3f(100000000, 100000000f, 100000000));

myApp.cam2.lookAt(new Vector3f(1000000000, 1000000000, 0), new Vector3f(0, 0, 0));

myApp.view2 = myApp.getRenderManager().createMainView(“Bottom Left”, myApp.cam2);

myApp.view2.setBackgroundColor(ColorRGBA.Green);

myApp.view2.setClearFlags(true, true, true);

myApp.view2.attachScene(myApp.getRootNode());



}

[/java]



however this doesn’t work… although the application does start, no changes occur and in the log I found:



[java]

TTTTTTEESSTTTTTTT

Exception in thread “main” java.lang.NullPointerException

at com.kiva.sim.model.DriveTypeChallenge.ViewPortTest.main(ViewPortTest.java:39)

Feb 14, 2012 5:49:39 PM com.jme3.system.lwjgl.LwjglAbstractDisplay run[/java]



why am I getting a null pointer exception???

Do not try to put application logic inside a main() method, thats not really a good idea. However, you provided not enough information in order to really help you. Since you did not post the whole class, it’s hard to tell which line is line 39 here and what might cause the error.

thats really the whole class think of it like main that extends SimpleApplication and has all the animation code in it. And then an external function that creates an instance of main and wants to change the behavior. myApp itself is null when I debug so for line 39 here it was the cam2 being null , in other words any function I try to use from the main such as



[java] System.out.println("TTTTTEEEEESSSSSTTTTT SPEEED ISSS"+ myApp.getAnimationSpeed());[/java]



will be null. I want to understand why…

The code doesent make sense, I can only recommend to read something about Object-Oriented Programming Concepts

Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials > Learning the Java Language)

and to play arround with the JMonkey tutorials

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3#tutorials_for_beginners

@nightwolf911 said:
thats really the whole class

I don't think so. There is no imports, no package declaration and no class declaration. This will never compile that way.
myApp itself is null when I debug so for line 39 here it was the cam2 being null ,

If myApp is null, then you will of course get a null pointer exception when you try to access myApp.cam2 since myApp is null.

ok there you go how about this example, why myApp is null



[java]

public class ViewPortTest {





private static mainAnimation myApp;

private static AssetManager assetManager;





public void ViewPortTest()

{

// location of the trace file

String url = "yadaydayda\animation.trc";



// create instance of Jme3Cinematics

myApp = new mainAnimation (url);



// load assets

myApp.getAssetManager();



}



public static void main(String args[]){



// Play button

myApp.start();





}







}

[/java]

  1. you need to learn java before using jme.

    2)

    myApp.cam2

    myApp.view2

    did you copy paste variables ?


  2. private static mainAnimation myApp;

    mainAnimation myApp =

    wrong scope