ClassNotFoundException when using library projects - java

I have a problem when trying to reuse a project class and resources, I always get a ClassNotFoundException. I dont know what I'm doing wrong.
The easier steps for reproduce my problem is create this two projects:
MyLibrary project:
Creating a example launcher activity ("Activity1") and in properties/Android
section mark as librayy
MyProject project:
It is just an empty project (no classes), in Java Build Path\Projects tag add the
project "MyLibrary" and declare in the manifest that it MAIN & LAUNCHER activity
is "Activity1"
Press play and there you have the ClassNotFoundException.
My target is inherit a whole project for making a free version from a paid version and keeping the common code in a single place for keep the maintain easy
Thanks

Related

Eclipse asking for module named after the old project name

I'm trying to make my project modular on Eclipse, but I'm running into an issue. I have added the module-info.java file through right-clicking on the project > Configure > Create module-info.java. However, when I run, I get the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module serenitea-pot-manager not found
I believe this might be caused by having renamed the project to sereniteaPotManager at some point. Initially, the project name was serenitea-pot-manager, which is the name of the module being asked for. I did the renaming through right-clicking on the project > Refactor > Rename..., which should have updated all instances.
I have been searching for a while, but still haven't found a way to fix this. Is there anything else that I need to update on Eclipse for it to change to the correct module name?
Note: The module name included in module-info.java is indeed sereniteaPotManager.
I had the same problem. I will summarize my experience then my solution.
I did a rename of the module, and Eclipse kept wanting to use the old module name. Cleans, restarts, etc., did not help. A search of the project properties, the run configuration, and all files in the workspace, did not turn up an instance of the original module name. Editing the module name so that it matched the original one did work. It is as if Eclipse tucks away the initial module name in some hidden place and keeps wanting to use it.
I was able to solve the problem by deleting all Run configurations that existed and then creating a new project and new Run configuration.
I am using JavaFX, and a somewhat peculiar side-effect of this is that the normally-required run configuration argument (below) was not needed in this new run configuration. I wonder if Eclipse is tucking that away in some hidden place, also?
In Java, serenitea-pot-manager is an invalid module name since a module name must not contain hypens (-).
Therefore, In module-info.java, Eclipse shows Syntax error on token "-". So make sure, before running your application, no compile errors are shown in the Problems view.
Rename your module to serenitea_pot_manager, delete the existing launch configuration (in Run > Run Configurations...) and try again:
module serenitea_pot_manager {
// ...
}
https://stackoverflow.com/users/17416717/stevevzzz[Steves] solution worked for me while I got stuck with the same problem.
... but I did not create a new project. I only was able to solve the problem by deleting all Run Configurations that existed and then I created a new Run Configuration.
I noticed the same behaviour. After changing the module name of my project, I got the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module ... not found
It looks like eclipse holds on to the original module name that is used when first running the application using the Run Configuration. To work around this issue, I deleted and recreated the run configuration. Then it works again.

must declare a named package eclipse because this compilation unit is associated to the named module

I just downloaded eclipse for Java Yesterday but when I was trying to get make my first program, I kept on getting this error:
must declare a named package eclipse because this compilation unit is associated to the named module x.
How do I fix this?
Just delete module-info.java at your Project Explorer tab.
The "delete module-info.java at your Project Explorer tab" answer is the easiest and most straightforward answer, but
for those who would want a little more understanding or control of what's happening, the following alternate methods may be desirable;
make an ever so slightly more realistic application; com.YourCompany.etc
or just com.HelloWorld (Project name: com.HelloWorld and class name: HelloWorld)
or
when creating the java project; when in the Create Java Project dialog, don't choose Finish but Next, and deselect Create module-info.java file
Reason of the error: Package name left blank while creating a class. This make use of default package. Thus causes this error.
Quick fix:
Create a package eg. helloWorld inside the src folder.
Move helloWorld.java file in that package. Just drag and drop on
the package. Error should disappear.
Explanation:
My Eclipse version: 2020-09 (4.17.0)
My Java version: Java 15, 2020-09-15
Latest version of Eclipse required java11 or above. The module feature is introduced in java9 and onward. It was proposed in 2005 for Java7 but later suspended. Java is object oriented based. And module is the moduler approach which can be seen in language like C. It was harder to implement it, due to which it took long time for the release. Source: Understanding Java 9 Modules
When you create a new project in Eclipse then by default module feature is selected. And in Eclipse-2020-09-R, a pop-up appears which ask for creation of module-info.java file. If you select don't create then module-info.java will not create and your project will free from this issue.
Best practice is while crating project, after giving project name. Click on next button instead of finish. On next page at the bottom it ask for creation of module-info.java file. Select or deselect as per need.
If selected: (by default) click on finish button and give name for module. Now while creating a class don't forget to give package name. Whenever you create a class just give package name. Any name, just don't left it blank.
If deselect: No issue

How To Upload Android Library For Private Use Only?

I have an Android app but require to create two Different copies of it with different package names. The reason for wanting two package names is that I want to upload them to two different Stores which requires the developer to provide a different package name.
To simplify the update process and fixing the issues I thought of dividing my code to different libraries.
I have now created an android library and now want to upload it so that I can simply use the library in my projects by simply adding the line compile com.adc.aaa...
But I do not want those library to be accessible to other developers either directly of maybe through google Search. Is it possible to achieve this?
These are few links which I have visited regarding this matter
1) https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
2) https://mayojava.github.io/android/library/creating-and-distributing-your-own-android-library/
Can anyone please help.
Suposing your module in android studio is called "library" you can simply add the module to your app project locally without the need to upload it to bitray.
You can add a local module as a depedency to your project using AS or manually:
1) Using AS:
Go to File -> Project structure. Click on the app module and then depedencies, click on the plus sign and then choose 3 - Module Dependency. If you library is in the same folder as your app it'll show up there. Just select it and it will be added as a depedency like the other compile dependencies.
2) Manually
In your settings.gradle file add:
include ':app', ':library'
In your app leve build.gradle:
implementation project(':library')
If you library module is somewhere else you can inport it to your project using:
File -> New-> Import Module

Can't find string resources from another project

I have an Android project let's call it SimpleProject in that project I get strings in this way getString(R.string.error) I keep all my strings in the projects /res/values/strings.xml. Besides SimpleProject is not a library project. Now I add my SimpleProject src folder as a linked resource to another project lets call it TestProject and then I try to build my TestProject Eclipse give me error that he can't find R.string.error. What can I do to solve this problem ?
EDITED:
I think about following issue
If I change all my applications packages to the same for example com.android.victor in that case all R-s will be same com.android.victor.R and if I add one project to another it will not bring to that that R will not be found. Am I right ? and what problems can appear in this case ?
I think you need to change the order,
1.go to Java Build Path
2.go to Order and Export and move the SimpleProject reference to be above the TestProject folders

JumpNote: main type is not specified

I'm doing my 1st steps in Android/GoogleApp, and I'm trying to explore the Jumpnote example:
http://code.google.com/p/jumpnote/
I was able to import the Android and Appengine projects to eclipse, but encountered the following issue when trying to run the Jumpnote-web part (android runs well).
When running the web part there is an error Main type is not specified which AFAIK implied that this project is missing a main function.
Is that indeed the case for jumpnote example and I need to manually add it, or am I missing something else?
Go to run Configuration
select JumpNoteWeb run configuration
You see in the main tab your project name and below it says main class
In the main class, put "com.google.gwt.dev.DevMode"
it should now run
*When I had this problem I also need to make sure that I put the src.shared folder into my project and had to change my build order so the app engine sdk, gwt sdk, and jre would build first

Categories