Could not find class 'de.lessvoid.nifty.ClipboardAWT', referenced from method de.lessvoid.nifty.Nift

I posted about this on another post, but since that post was too big I guess no one ever noticed it.

Anyways, I’m using nifty on android to create a menu.

But I keep getting this error upon starting:

Could not find class ‘de.lessvoid.nifty.ClipboardAWT’, referenced from method de.lessvoid.nifty.Nifty.initializeClipboard



This is how I set it up:

I run this method:

[java] private void setupNifty() {

niftyDisplay = new NiftyJmeDisplay(app.getAsset(),app.getInput(), app.getAudio(), app.getGuiViewPort());

nifty = niftyDisplay.getNifty();

nifty.fromXml(“menus/in_game.xml”, “end”);

nifty.addControls();

}

[/java]

The xml is here:

[xml]<?xml version=“1.0” encoding=“UTF-8”?>

<nifty>

<screen id=“win” controller=“start.MainClass”>

<layer id=“layer” backgroundColor="#00000000" childLayout=“center”>

<panel id=“panel4” height=“50%” width=“25%” align=“left”

valign=“top” childLayout=“vertical”>

<image filename=“textures/success.png”/>

</panel>

<effect>

<onStartScreen name=“move” timeType=“exp” factor=“3.5”

direction=“left” mode=“in” length=“300” inherit=“true” />

<onEndScreen name=“move” timeType=“exp” factor=“3.5”

direction=“left” mode=“out” length=“300” inherit=“true” />

</effect>

</layer>

</screen>



<screen id=“ingame” controller=“start.MainClass”>

<layer id=“layer” backgroundColor="#00000000" childLayout=“center”>

<panel id=“panel4” height=“50%” width=“25%” align=“left”

valign=“top” childLayout=“vertical”>

<image filename=“textures/button.png” imageMode=“resize:6,20,6,6,6,20,6,20,6,20,6,6” />

</panel>

<effect>

<onStartScreen name=“move” timeType=“exp” factor=“3.5”

direction=“left” mode=“in” length=“300” inherit=“true” />

<onEndScreen name=“move” timeType=“exp” factor=“3.5”

direction=“left” mode=“out” length=“300” inherit=“true” />

</effect>

</layer>

</screen>



<screen id=“end”></screen>

</nifty>[/xml]

And then I do this:

[java]nifty.gotoScreen(“ingame”);

cam.setLocation(blablahblah);[/java]



And thats when the game crash and complains that the camera is null.

I’m using the latest svn btw.



All help is appriciated :slight_smile:

I got it too. I didn’t look into it because this is not breaking, nifty works fine even when this error pops out.



I guess nifty has direct AWT references and they are not available on android.



Anyway…I think that if your nifty screens does not work, this is not what’s causing the issue.

1 Like

Problem is, if I dont run setupNifty() then this line will not cause an error:

Log.d(“shit”, MainGame.getCam().toString());

But if I do run the nifty, this line will give nullpointexception.



I import:

-eventbus

jme3-android

jme3-core

jme3-niftygui

jme3-plugins

nifty-default-controls

nifty-style-black

nifty

xmlpull-xpp3



Is it some jar I forget to import?

You are on the wrong track, its something else. If cam is null maybe you do something wrong in the initialization, your app is probably not started yet.

1 Like

The only difference between the one with nifty and the one without is that I run the following code:

[java]private void setupNifty() {

niftyDisplay = new NiftyJmeDisplay(app.getAsset(),app.getInput(), app.getAudio(), app.getGuiViewPort());

nifty = niftyDisplay.getNifty();

nifty.fromXml("menus/in_game.xml", "end");

nifty.addControls();

}[/java]

upon starting the game.



I changed the code at the error line.

I added System.out.println(app.getCam()); before the actual error line.

The results is an error at the app.getCam().setLocation line a´nd in the output it has printed null.

When I removed setupNifty() from running, then it worked perfectly fine.



So nifty do set my camera to null somehow…

post your entire initialization code.

1 Like

:facepalm: what you say is cam is null, even when you replace the code with a println… so cam is null, no need to blame nifty that it needs the cam :roll:

1 Like

Okej so I included only the methods relevant to the initiation.

Otherwise I would have to include almoste the whole project.

[java]public class MainClass extends MainGame implements ScreenController{

@Override

public void initiationFinished(){

ContactManager.setup();



PhysicManager.createSystem("epic_stuff");



if (MainClass.goal != null && MainClass.base != null){

System.out.println("Stargate lookat base");

MainClass.goal.lookAt(MainClass.base.getPosition());

}



CamManager.intro(); <–THIS ONE LEADS TO THE NULLPOINTER

}

}[/java]

This is the first class to be created.

It extends this one:

[java]

public class MainGame extends SimpleApplication{

public static MainGame app;

public static PhysicBody follow = null;

public static Vector3f prev = null;

public final static boolean lighting = false;

public final static boolean particles = false;

private static final float darkness = 0.3f;

private NiftyJmeDisplay niftyDisplay;

private Nifty nifty;





public MainGame(){

app = this;

this.showSettings = false;

}



@Override

public void simpleUpdate(float tpf){

PhysicManager.update(tpf);

updateCamera();

}



private void updateCamera() {

if (follow != null){

if (prev != null){

cam.setLocation(cam.getLocation().add(follow.getPosition().subtract(prev)));

prev = follow.getPosition();

} else {

prev = follow.getPosition();

}

}

}



public void initiationFinished(){



}







@Override

public void simpleInitApp() {



System.out.println("Init game");

Logger.getLogger("").setLevel(Level.SEVERE);



IndexManager.init();

setupDisplay();



initiationFinished();

setupCamera();

setupNifty();

}



public void setMenu(String name){

nifty.gotoScreen(name);

}



private void setupNifty() {

niftyDisplay = new NiftyJmeDisplay(app.getAsset(),app.getInput(), app.getAudio(), app.getGuiViewPort());

nifty = niftyDisplay.getNifty();

nifty.fromXml("menus/in_game.xml", "end");



nifty.addControls();

}



private void setupCamera() {

this.mouseInput.setCursorVisible(true);

flyCam.setDragToRotate(true);

flyCam.setMoveSpeed(100);

flyCam.setRotationSpeed(10);





cam.setFrustumFar(2000);

}



}[/java]



The MainClass runs initiationFinished and then run CamManager.intro(),

here is the cammanager:

[java]public class CamManager {



public static void intro(Vector3f start, Vector3f center, Base base) {

Node temp = new Node();

temp.setLocalTranslation(center);



MainGame.getCam().setLocation(start);

MainGame.getCam().lookAt(center,Vector3f.UNIT_Y);

MainGame.getFlyCam().setEnabled(false);

new SimpleWait(2);

}





public static void introDone() {

MainClass.removeSuccess();

if (!MainClass.base.cameraView){

Vector3f dist = MainClass.base.getPosition().subtract(MainClass.goal.getPosition()).normalize();

System.out.println(MainGame.getCam()); <–THIS ONE PRINTS NULL!

MainGame.getCam().setLocation(MainClass.base.getShipPosition().add(dist.mult(10)).add(new Vector3f(0,2,0))); <–THIS ONE GIVES NULLPOINTER

MainGame.getCam().lookAt(MainClass.base.getShipPosition(), Vector3f.UNIT_Y);

MainGame.getFlyCam().setEnabled(false);

MainClass.base.cameraView = true;

}

}

}[/java]



Notice how the MainGame.getCam() is not null when method is called. But 2 seconds later, when called by the SimpleWait instance, it will produce an error:

[java]public class SimpleWait extends AbstractAppState {

private float time;



/**

  • Will wait given amount of seconds then fire the introDone() method in CamManager.
  • @param time amount of time to wait.

    */

    public SimpleWait(float time) {

    this.time = time;

    MainGame.getState().attach(this);

    }



    @Override

    public void update(float tpf) {

    time -= tpf;



    if (time < 0) {

    MainGame.getState().detach(this);

    CamManager.introDone();

    }

    }

    }[/java]



    Should I maybe pause the game upon loading and resume when the game has finished loading?

    If so, how would I know when the game has actually loaded?

how and when do you instantiate your MainGame or your MainClass?

does the MainClass constructor calls its super?

On a side note you should really look into the “Singleton pattern” on google, because having a class keeping a static reference on itself in a public constructor is an open door to insanity…and could be the very reason of your problem…

1 Like

I run the application like this:

[java] /** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

thais = this;

app = new MainClass();

super.onCreate(savedInstanceState);



updateWindowSize();

// Set the application class to run

appClass = “andrew.planetdash.start.MainClass”;

// appClass = “jme3test.android.SimpleTexturedTest”;

eglConfigType = ConfigType.FASTEST; // Default

// Edit 22.06.2011: added a switch to get the highest (best) egl config

// available on this device

// Its usually RGBA8888

// eglConfigType = ConfigType.BEST;

// Exit Dialog title & message

exitDialogTitle = “Exit?”;

exitDialogMessage = “Do you wish to exit?”;

// Edit: 25.06.2011: Enable verbose logging

eglConfigVerboseLogging = true;

// Edit: 30.06.2011: Choose screen orientation

screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

// Edit 12.07.2011: Invert the MouseEvents X (default = true)

mouseEventsInvertX = true;

// Edit 05.07.2011: Invert the MouseEvents Y (default = true)

mouseEventsInvertY = true;

}

[/java]



I didn’t have a constructor in MainClass, so I think it did call the super contructor everytime.

Anyhow, I added super() to the contructor of MainClass and it did no difference.

As for your side note: Where do you meen I use bad static refference?



Thanks for helping :slight_smile:

I opened the nifty jar, located the clipboardAWT that’s been causing problems.

I decompiled it and found this method:

[java] private void initializeClipboard()

{

try

{

Class.forName(“java.awt.datatransfer.Clipboard”);

clipboard = new ClipboardAWT();

}

catch(ClassNotFoundException e)

{

log.info(“unable to access class ‘java.awt.datatransfer.Clipboard’. clipboard will be disabled.”);

clipboard = new ClipboardNull();

}

catch(Throwable e)

{

log.info(“unable to access class ‘java.awt.datatransfer.Clipboard’. clipboard will be disabled.”);

clipboard = new ClipboardNull();

}

}[/java]



Could you add a

e.printStackTrace();

to the Throwable thing?

It might explain more about this error.



I couldn’t manage to compile it again because all the imports were missing etc, but I figured you have access to them right?

MainGame has a static reference to itself, but this reference is set in a public constructor, so if you instantiate the class several times, the static reference change resetting its entire context…

Usually you set the constructor to protected and let the class manage its own instantiation in a static getInstance method. This way you are sure to have one and only one instance of this class

[java]

public class MainGame extends SimpleApplication{

public static MainGame app;



public MainGame(){

app = this;

this.showSettings = false;

}

}

[/java]

I think it really is your issue. Does your Activity extends the AndroidHarness?

If it does your onCreate method messes everything

[java]

public void onCreate(Bundle savedInstanceState) {

thais = this; // WTF seriously? static reference again?

app = new MainClass(); // first instantiation and initialization of your stuff

super.onCreate(savedInstanceState); // AndroidHarness onCreate instantiate again your app -> 2 instances 2 static references = hell of a mess



}

[/java]



Why do you hijack the AndroidHarness’ onCreate mehtod? (yeah I said hijack not override)



your MainActivity should look like this, period!

[java]

public class MainActivity extends AndroidHarness{



public MainActivity(){

// Set the application class to run

appClass = “andrew.planetdash.start.MainClass”;

// Try ConfigType.FASTEST; or ConfigType.LEGACY if you have problems

eglConfigType = ConfigType.FASTEST;

// Exit Dialog title & message

exitDialogTitle = “Exit?”;

exitDialogMessage = “Press Yes”;

// Enable verbose logging

eglConfigVerboseLogging = true;

// Choose screen orientation

screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

// Invert the MouseEvents X (default = true)

mouseEventsInvertX = true;

// Invert the MouseEvents Y (default = true)

mouseEventsInvertY = true;

}



}

[/java]

@Addez said:
I opened the nifty jar, located the clipboardAWT that's been causing problems.
I decompiled it and found this method:
[java] private void initializeClipboard()
{
try
{
Class.forName(&quot;java.awt.datatransfer.Clipboard&quot;);
clipboard = new ClipboardAWT();
}
catch(ClassNotFoundException e)
{
log.info(&quot;unable to access class 'java.awt.datatransfer.Clipboard'. clipboard will be disabled.&quot;);
clipboard = new ClipboardNull();
}
catch(Throwable e)
{
log.info(&quot;unable to access class 'java.awt.datatransfer.Clipboard'. clipboard will be disabled.&quot;);
clipboard = new ClipboardNull();
}
}[/java]

Could you add a
e.printStackTrace();
to the Throwable thing?
It might explain more about this error.

I couldn't manage to compile it again because all the imports were missing etc, but I figured you have access to them right?

OMFG....
You know that Nifty is not JME right? It's another project...
You also know that Nifty is open source .... no need to decompile it, just fetch the sources....
Don't waste your time with this, it's not your issue, there is no AWT clipboard on Android....so what? it's an info log and there is a fallback.

TROLOLOL!

I wounder how I was able to run so long having 2 apps running simuntaniusly working at one app and not interfering.

Anyways, the problem with the camera remained. I wasn’t completly done checking all errors, but before I manage to do so I accidently broke my mobile screen.

Now I can’t debug the game no more :frowning:



Sucks…

I had had my phone for a year, but it was the best phone I’v ever had.

RIP Desire Z.

…I’m really inclined to think you are cursed…