30

I'm working on a libGDX project and I have a class called CheerVArachnids that has another inline class which is an event listener. When I run this project on the desktop it works fine. BUT when I run on my Android device, it can't find that inline class and I get the following error:

Could not find class 'com.bbj.cva.CheerVArachnids$PlaceUnitListener', referenced from method com.bbj.cva.CheerVArachnids.<init>

Here are the important parts of my class:

package com.bbj.cva;

public class CheerVArachnids implements ApplicationListener {

    class PlaceUnitListener implements EventSubscriber<PlaceUnitEvent> {

        @Override
        public void onEvent(PlaceUnitEvent event) 
        {   
            //
        }
    }

    public CheerVArachnids() {

        EventBus.subscribe(PlaceUnitEvent.class, new PlaceUnitListener());
        EventBus.subscribe(RemoveScreenObjectEvent.class,
                new RemoveScreenObjectListener());
    }
}

Any ideas why on Android, at runtime it can't find that inline class?

b-ryce
  • 5,752
  • 7
  • 49
  • 79
  • What's the rest of the exception message? I suspect its actually a problem with the superclass of PlaceUnitListener (and then CodeNoob's answer will apply). What is an "EventSubscriber<>"? – P.T. Feb 08 '13 at 16:20

3 Answers3

46

Since some ADT-Version you have to set which libraries / projects should be exported too.

Project-Propiertes -> Java Build Path -> Order and Export -> Check your Sources and other Libraries you are using.

Do these Export-Settings for your Core- and Android-Project.

Then it should work fine on Android.

CodeNoob
  • 984
  • 8
  • 8
  • That would make sense if it was a external library, but this is a class that is defined right inline. So there is no external project dependencies. See how the PlaceUnitListener is declared above the constructor. – b-ryce Feb 08 '13 at 15:35
  • 1
    I had these errors very often, and the message is often wrong. Here it was that, it couldnt find the Interface/Class which should be implemented, I kinda cant it explain right, BUT, where do you get EventSubscriber from? This is from an external library right? – CodeNoob Feb 08 '13 at 16:55
  • If they are in the maven dependencies....one would expect them to be in the build path..sigh. Thanks @CodeNoob – Shehaaz Apr 18 '13 at 16:06
  • 4
    As @umbyslipknot mentioned, this only worked for me when I moved the jar to the top of order & export list. Good advice tks. – justinkoh Oct 10 '13 at 03:36
12

In my case, everything worked fine until I installed the new updates for the SDK and Eclipse.

I got an error: "Could not find class..."

I found solution in another stackoverflow site.

I have a similar problem when using external jar (in my case openCSV). The reason I had a problem was due to a change in ADT 17 (or above). What I needed to do to resolve the problem was In Eclipse go to Properties -> Java build path -> Order and export. Mark my jar. Move jar to top of the list. The solution was found in the following page which reference to a very good article.

Community
  • 1
  • 1
syp_dino
  • 395
  • 3
  • 10
0

First you should: import XXX(Class).java, If you added external library jar file import them to the LIB folder. After that: Right Click to your Project -> Properties -> Java Build Path -> Order and Export(tab) -> select All -> press OK -> Clean your Project.

Hope this solve this issue