Problem with linking to other project in Android Eclipse environment - java

I am developing an Android application as an Eclipse project that uses classes from another Eclipse Android project I already have. When I originally imported it (New Project > Android Project > From Existing Source), it had a bunch of errors, but when I did Project > Properties > Java Build Path and went to the projects tab and added the other project, the errors went away. Unfortunately, when I ran the application, I got the following error in DDMS:
java.lang.NoClassDefFoundError: [package name].Config
[stack trace]
Is there something I'm supposed to add to the manifest telling it to look at the other package? If so, where would that be added?
Thanks in advance

Found the answer. It turns out that if I add the compiled class files into a JAR file using Eclipse's export command and then link to external jars in the Java Build Path, it works without having to change the Android Manifest at all.

Try using the File -> Import...
Then go to "Existing projects into Workspace" and choose the root directory of the project.
The one where are the src,res... folders

Your second project should be a library. Open project properties, select the Android tab and check "is library".
In your main project, open its properties, select Android tab also and click on Add in the library section and add your second project.

Related

IntelliJ IDEA is not recognizing my java files as runnable and instead wants to run the class files. Any ideas of how to fix?

Anytime I try to run a java file by clicking run, it instead tries to run the class file and thus gives a no main method error.
When I try to right click on a java file and run that, it doesn't recogize it as a file that is runable.
I am still able to run programs from the command prompt but I would prefer to be able to run them in IntelliJ.
This occurred after trying to create a Class path when using JSon Libraries.
Edit:
Normally it shows java files with this icon:
But instead it's showing this icon for java files:
I think the change in icon might have something to do with it.
Edit 2:
the exact error I get is "C:\Program Files (x86)\Java\jdk1.8.0_181\bin\java.exe"...bunch of other program file locations
Error: Could not find or load main class sample.Main
Process finished with exit code 1
I had the same problem and found out that my src wasn't marked as Sources Root. To change this:
right-mouse click on your src
navigate to "Mark Directory As"
choose "Sources Root"
It will now recognize your files correctly and your main classes will be able to run again
IntelliJ not recognizing my .java-files
Problem solved
I had a similar problem.It wouldn't pick up ModlServer in any project. (Not just limited to the one I had open).
I had to file -> Manage IDE Settings -> Restore Default Settings
Note: I lost all my live templates, fonts, etc so just a heads up.
I restarted my computer and that somehow fixed it.
My issue was that I have multiple modules for my project and the module I was working on (where java files were not recognized) was not included in the main pom. I just added that module in the main (project) pom and it worked.
Right click on the project and click 'Add framework support' all directories and classes should now be the right type.
I've fixed this at Intelij2023 by using JDK17 as the JDK the IDE uses to import java source files.
Mind this JDK version does not need to be the same you use to build your project.
Go to: Settings > Build, Executio, Deployment> Build Tools > Maven > Importer
Set the JDK For Importer to zulu-17
I'm using zulu-17 as JDK for imports and coretto-8 to build the project (having JDK version 8 seems to be preventing intelij to properly recognize the project structure)
If you are using Maven or Gradle, try to re-import the project and see if that helps. Could be that your IDEA project has some incorrect settings in it set by mistake, so this way those would be removed.

Importing Android project into eclipse gives me two project

I am importing the following project : ActionBarCompat-Basic from the Android Developers website into Eclipse.
by doing so: File -> Import => Android existing project.
However, in my package explorer, it creates me two projects :
1) The first project is named MainActivity
2) The second project is named tests.
Also, the two projects both have errors
Is that normal ? If yes, how can I solve the errors issue ?
Note, because you do not say wich project you are importing, this a blind answer.
You get two project simply because in the downloaded folder are two project.
To resolve errors first of all try to do a clean Project=>Clean... and select the projects you want to clean.
Unfortunately errors are common when you import project coming from around the web.
You should right click those projects, open Properties and check the Android tab, check if you are missing some library and try to figure out wich library is (or are).
Check Android 4.4.2 as build target.
Open the Java Build Path tab and open the Source tab, check if the gen and src folders are there, if not, add them.
If error are still there open the files marked with the error icon and try to figure out wich library they miss.
Check the Eclipse error Log.
I hope this help.

How to add Android X.X in Project -> Properties -> Java BuildPath

I think the title is very clear. Sometimes I have some build errors, and in the Libraries tab of Java Build Path, I add/remove libraries, etc ... but when I delete the Android X.X "folder", I can't bring it back. What I do is to delete the project from the Workspace and Import it again as Existing Android Project.
Is there a way to add it directly without deleting-importing a project?
How does eclipse generate it? for what purpose? Why if missing eclipse doesn't show errors before building?
Please help me understand all these!
Yes you can do that without removing the project and importing it back.
Right Click your Project-> Java Build Path->Add Library->Android Classpath Container->Choose your Project->Ok
You will your Android X.X back.
Hope it helps.
When you delete your project click on the check box which says Delete projects content on disk and then import your project and to add library go to properties->java build path->order and export and check your library

Import source java project in Android project

Is it possible to import an existing Java project which is in my workspace, in an Android project which is also in my workspace? The Java project doesn't use stuff that is incompatible with Android. I could do it using a .JAR, but since I'm modifying the Java project a lot, I would like to import the whole source code and change it once in a while. Is it possible? Thanks
This is somewhat of a hack, but worked for my project:
Add both Android project and plain Java project to workspace
Go to properties for Android project -> Java Build Path -> Source
Click Link Source, in "Folder name", make sure to select the root directory of the plain Java project's src tree
Use a descriptive name for "Linked folder location", like "java_project_src".
Press Finish and compile
This setup will compile the plain-java code as Dalvik bytecode. In my case, I had pure java code with very limited dependencies, but wanted to share the pure java code with non-Android projects, instead of separately maintaining these files in every project.
I think you are talking about referencing other projects into the current project, if this is the case then you can do this by Right click on project, properties->Project Reference.
You can link another projects to your current project. Right click on your main project, choose Build Path -> Configure Build Path... In the dialog choose the Projects tab, then click Add.. button. Now choose the project you want to link and click OK. You'll now be able to use this project's sources inside your main project. Hope this helps.

How do I reference adk resource in a different Android project?

I am developing a study project using the mosembro (mobile semantic browser) project inside my Android project. I am using Eclipse and I created my project, downloaded / imported mosembro and included in my project's build path.
So now my code needs to refer to a resource in the mosembro's project. I want to do something like this:
String commonJS = getScript(R.raw.common);
In this snippet, I want to load a javascript file from mosembro's project: res -> raw -> common.js so I need the java syntax to get "R" (precompiled resource-class) of Mosembro from my HelloGoogle project.
What is the syntax to replace the R-class of this with the included project's R-class.
Is that clear?
I found the answer and it is very simple. You can add projects to your project through the Java Build Path.
Right click on the project you are working on
Select Build Path -> Configure Build Path ...
Then pick the Projects tab
Finally, press the Add... button and select the project that you want to include.
This keeps everything in code-sync if you make changes rather than cut-n'-paste.

Categories

Resources