Could not find class XXX referenced from method XXX.<YYY> - android

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?

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.

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.

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

Related

Trying to use code from another project by including it in my build path

I'm trying to figure out a way to share code across projets. this is what i did
created a project called sharecode and made the following class
package codelib.com;
public class cShape {
}
made a android project called testsharecode
whent to properties->java build path and clicked on projects at the top.
clicked add, and added sharecode
created a class to try include the cShape class from the sharecode project
package com.example.testsharecode;
import codelib.com
public class parent {
cShape test;
}
On my import i get a error saying
"only a type can be imported, cadelib resolves to a package"
on cShape i get a error saying the def does not exist.
How can project testsharecode use the code in projetc sharecode?
have you tried the following method :
right click on the distination projet, Build Path -> configure build path
chose project then select testsharecode
back in your distiation project now you should be able to use your public classes.
hope this helps

Importing Java Library JAR into eclipse

I'm currently trying to implement a browser with pipelining feature in it. The problem is in order to code the HTTP pipeline, i need the support of a library. I tried to import it to my workspace by using Project - > properties -> Java build path ->addJar. And I was able to add it successfully. But now my problem is, even though it is added to my workspace it doesnt let me run this code. It gives me errors as if I have not imported the library:
package com.test.download;
import java.util.Collections;
import org.factor45.*;
public class Example {
// Execute the request
HttpRequestFuture<String> future = client.execute("hotpotato.factor45.org", 80, request,
new BodyAsStringProcessor());
future.addListener(new HttpRequestFutureListener<String>() {
#Override
public void operationComplete(HttpRequestFuture<String> future) throws Exception {
System.out.println(future);
if (future.isSuccessfulResponse()) {
System.out.println(future.getProcessedResult());
}
client.terminate();
}
});
}
This is available in the same website which provided me the library for the above code. "Here" is the website for your reference. Also you can find the JAR file inside this website.
Please help me to figure out the problem. If you solve this you are a life saver! Thanks in advance!
Try this:
Properties >> Java Build Path >> Libraries >> Add External JARs... Then select the library

Unable to run Bitmap sample code for Android

I am trying to run the sample from :
http://developer.android.com/training/displaying-bitmaps/display-bitmap.html
However I encountered lots of errors like:
Description Resource Path Location Type
BuildConfig cannot be resolved to a variable ImageGridFragment.java /ImageGridActivity/src/com/example/android/bitmapfun/ui line 124 Java Problem
Description Resource Path Location Type
SuppressLint cannot be resolved to a type Utils.java /ImageGridActivity/src/com/example/android/bitmapfun/util line 99 Java Problem
I ran thru Google but could get nothing. Adjusted the android build target to 4.0.3 (15) but still no clue. Anyone ran this sample successfully?
Thanks.
Here is my solution:
1.Create a new class:
package com.example.android.bitmapfun;
public class BuildConfig {
public static final boolean DEBUG = true;
}
2.Comment the lines that contain "SuppressLint":
//import android.annotation.SuppressLint;
// #SuppressLint("NewApi")
Android developer tools r17 brings a feature to Eclipse where a class is auto built at build-time, called BuildConfig, which contains a constant that can be used by the app developer to sense whether the build is a dev build or a production build. This feature appears to be in the Eclipse integration support, so when using IntelliJ, this useful feature is not available
In gen folder with R.java there should be BuildConfig.java if your program compiled successfully.
/** Automatically generated file. DO NOT MODIFY */
package com.example.android.bitmapfun;
public final class BuildConfig {
public final static boolean DEBUG = true;
}
Clean your project and try to launch it again.
It worked for me.
For me also it is not running directly import to eclipse. Just i put comments which lines is showing errors then it is working fine for me. May be it is not a right answer but we can see the application functionality by running the code so i did like that.

Importing projects

I had many Android projects that were working fine in my old pc. now, when I tried to re import them, they are not running. Problem is that onClickListener is not working. Wherever there is onClick method, it throws an Error:
The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
My actual method is :
myBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//my code
}
});
What would be the problem?In every project wherever there is onClick method it shows the same.
Using my supehuman guessing powers I assume that you are using eclipse. Eclipse projects are not portable between machines as they contain absolute paths ( but that does not stop developers from checking them in into source control system ).
Your options are:
recreate eclipse project from sources
create maven build with android plugin and make it create you an fresh eclipse project
spring 150 bucks and buy you license for IntelliJ IDEA ( or just use free community edition which also has android plugins )
simply remove all #Override annotation above the onClick() methods
Goto project menu and clean the project.
Option 1: Simply remove all #Override
Option 2: In Eclipse -> Window -> Preferences -> Java -> Compiler, set "Compiler compliance level" to 1.6 or higher.

Problems importing an Android project into Eclipse

I reinstalled my computer and tried now to import my Android project into the workspace.
(File -> Import -> General -> Existing Project into Workspace)
But now I have got a strange error.
bNormal.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
gotoNextQuestion();
}
});
In the second line (#Override) eclipse always tells me there is an error:
/* Multiple markers at this line
- implements android.view.View.OnClickListener.onClick
- The method onClick(View) of type new View.OnClickListener(){} must override a superclass Method */
This happens everywhere, where #Override is used.
I already tried to Android-Tools -> Fix Project Settings and Project -> Clean.
I hope somebody can help me with this strange problem.
Thanks, Mark
It is because the language level is set to 5.0. Change it to 6, and all will work fine. Don't know where to set it eclipse, but in Idea it's File - Project Structure - Project Language level
It happens because OnClickListener is an interface and in 5th Java #Override can not be applied to a method implementation.
Your android SDK is probably not in the same path. Fix that in your eclipse settings.

Categories

Resources