Eclipse error: NoClassDefFoundError: java/lang/ref/FinalReference - android

I've installed Eclipse for android and that works okay. When I try to start a java-file I got the following error: Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/ref/FinalReference
After some research I know it was something with buildpass but after trying I didn't got it to work. I removed it all (Eclipse, Java, Android) and reinstall everything but with the same disapointing result. Could somebody explain to me what to do because what I tried from the internet didn't work for me.

Find Running configurations -> java application
In the new configuration's Classpath tab, find "Android Library" under Bootstrap Entries and remove it.
Still in the Classpath tab, select Bootstrap Entries and click the Advanced button.
Choose Add Library and click OK.
Select JRE System Library and click Next.
Select Workspace Default JRE and click Finish.
Based on http://www.frickingnutz.com/files/android_pdf/FAQs.pdf

I have been frustrated by this error for several days, by comparing with my colleagues Eclipse preferences with mine, the problem was fixed by changing the Java compliance level from 1.7 to 1.6.
This will also change the generated .class files and source compatibility to 1.6.

If you tried running a specific java class, then every time you click the run button it will default to whatever you tried to run last.
Click the drop down beside the run button and choose specifically what you want to run.

Go to "run configuirations" under the "run" menu. Select the delete run menu. Do a clean and then you should be back and running again.

I was trying to use all the answers above but it doesn´t work.
This error happened when I wrote 1 method that returned a String [][] ( don't know why yet) but the error doesn't disappear when I disable (/* */) the method.
Finally I did 2 things:
Created a new Android Project and copy the files. rebuild the Activity.java and the manifest.xml.
It worked until I activate the method then the same error all over again:
VM java/lang/NoClassDefFoundError: java/lang/ref/FinalReference
and then
Error occurred during initialization of VM and no matter what I do, it didn´t work until I create another Android Project.
So the 2nd thing I did was :
Run-> Run Configurations->Java Application and click on New_Configuration then I clicked on the red X above (Delete selected launch configuration) and it worked ( not the method but the program worked when I /* */ it.)

Related

Android Studio cant find the project properly

This problem happened like "out of the blue". When I tried to run the application at some point it came up with
configuration is still incorrect. do you want to edit it again
This message kept popping up, which I thought was a bit weird. So I endend up restarting Android Studio, but when it had loaded up again, all of the structure with folders etc. in the left side of the screen, were gone. Only a message saying "Nothing to show" is there now.
Also all of the files that were open before I restarted is still open, but has little "red J's" in the tap where the file name is.
The last edit to my project was that I changed the minimumSdkVersion of the gradle file, from 21 to 10.
Obviously changing this back, had no effect.
EDIT:
When I try to deploy the project anyways it gives me this error in the console:
Error running main: Module is not found
So I have really no idea on how to fix this or what is wrong, even though I have tried to research it.
I really hope someone can help me out or have an idea on what may be wrong.
Any help will be greatly appreciated.
If you build and deploy Android app from IDE/Studio to watch directly , you most likely will see Build Configuration screen and if you will clik "Run" you will get
"Build Configuration is still incorrect, do you want to edit it again?"
To solve it just check "Do not launch Activity" in Activity section of a "Run/Debug Configurations" of project.
or try these
check for the tags they may be not closed.
check for the package name in manifest file
check for the edit configuration , Then, check the bottom section "Before launch: Gradle-aware Make"
click on that small triangle to hide it. An error message should appear. This message may show you the error cause.
or Go to File->Project Structure-> Project Settings -> Modules, Click on the green colored and add new module. select Application module and set the content root to your project module.
or try to update the gradle as when studio starts it looks for gradle and sometime if not found it download it, may be your gradle have crashed so update it or manually place it.

How to add new activity to existing project in Android Studio - "Project not ready"

What needs to be done to add a new activity to existing project that works and compiles but has "Project not ready" in the menu. Please see the picture.
Other than that all works, so I don't know what IDE means by "Project not ready"
This is a little bit over a year but i thought i would provide an answer for anyone (novice like me) who may encounter the same problem.
I had the exact same problem as depicted and denoted. It was fixed by
Cleaning the project (Build --> Clean Project)
Sync with Gradle ( Tools --> Android --> Sync project with Gradle files)
What I did to solve this was to open up specifically the Android project in a new Android studio instance (not from the flutter project, which has everything)
Note if you don't see the option to do this in your project -> flutter options
Then you can just open the folder containing the project, followed by opening up the Android project specifically from there.
Now you should get the options
(Not an exact answer) Observation:
I don't know exactly what happened, but it works now, all I could notice is that gradle had some error from unclean build likely I must have had some code changes resulting in invisible compilation errors. After good build menus available again.
Please post your "observation" if you don't know exact answer.
Thanks
If you want to add a Activity to an android application,
you have to Extend Activity from one of your classes like this:
public class SecondActivity extends Activity
And add that activity to your manifest.
<activity
android:name=".ActivitySecondClass"
android:label="#string/app_name2" >
</activity>
You have to give the project time to build first. Wait a minute or two before jumping in.
I had the same issue. I fixed it by clearing the cache. (File > Invalidate caches & Restart).

unable to instantiate application - ClassNotFoundException

EDIT: This problem has not already been resolved in the other suggested SO question
I had a fully working app on the market for over a year, with very few crash reports. Then recently I changed my app into a library, so that it could be included within multiple different "wrapper" projects. This was so that I could easily make different version - free, paid, non-google markets, with/without in-app purchasing etc etc.
The new "library+wrapper" app appeared to work fine. I could run it multiple times, without error. But then a day later (when presumably the OS had closed some or all of the app's activities) I tried to run it and it reported
Unable to instantiate application com.mycompany.mygamelibrary.MyGameApplicationClass: java.lang.ClassNotFoundException: com.mycompany.mygamelibrary.MyGameApplicationClass
The class it failed to find is the first class that runs when the program starts up, MyGameApplicationClass - which extends Application. This class is part of the library.
I suspect something goofy in one of the two manifest files.
The manifest of the wrapper project contains the lines...
<application android:icon="#drawable/mygame_icon"
android:screenOrientation="portrait" android:label="My Game Name"
android:name="com.mycompany.mygamelibrary.MyGameApplicationClass">
Any ideas what could have gone wrong?
EDIT: The library was referenced "the correct way" as defined by yorkw's answer to this SO question.
EDIT: I can not repeat the crash at the moment :-( I don't know what it is the OS does when the app is not used for a day or two.
There are two possibilities. Either you, like me, have a spelling error in your manifest file. Have a co-worker or friend read it to make sure the name is correct. Or you have not referenced the project correctly.
The official document describes how to properly link projects in its documentation.
Why it would first seem to work and later stop working is a bit of a mystery. However, I guess that the VM might still have had the necessary references ready to resolve the classes in the library just fine. A restart of the VM removed all those references and trying to resolve them was unsuccessful.
Update: Regarding the edits in the OP: As you confirm that you have correctly referenced the other project, you can check if the project is included in APK, just to be sure. You can rename and open an APK as any other archive (.rar works fine for me). Sometimes, it happened to me, the project is not correctly included in the APK. A cleaning of your workspace usually remedies the problem and so could a restart of your IDE depending on what you are using. To manually conduct a clean in Eclipse for example, use Project->Clean... or try Android Tools->Fix Project Properties by right-clicking on your project.
As you seem to also have fixed the problem by restarting your device, it could be that the libraries were linked incorrectly. A problem that I have never seen myself but as a very common quote says: "Have you tried turning it off and on again?".
For Android Studio:
Build --> Clean Project
Fixed issue.
Have you tried to make a new subclass of MyGameApplicationClass in your 'main' project and set it in the manifest as Application class?
I had a slew of bugs with Android Studio 3.0 Canary 4 and the way I fixed them was by editing the AndroidManifest.xml by adding in some jibberish to the application name. Then, I clicked build. Obviously, a whole mess of new error messages appeared. I changed the name back to what it should be, built the app, and it just ran.
Sometimes, I just don't know...
EDIT: Just ran into this issue on Android Studio 3.0 Canary 4 on my laptop when switching over. I again went through the same process of changing AndroidManifest.xml file to contain a typo, building, and changing back. That didn't work.
I then noticed that instant run was still enabled. Going into settings (by clicking command + , (comma key)) and typing "instant run", I was able to disable instant run, built the app, and the error of class not found went away.
Summary of Steps to Fix [FOR ME]
Invalidate cache / restart
Clean the project
Manually delete the build folder (need to be in project view for this one)
Make an intentionally errant edit to your AndroidManifest.xml file, build the app, observe the errors, remove the errant edit and build again
Disable instant run
Again, I don't mean to insinuate that this will fix everyone's error, but I have now used some combination of these steps on two different machines (MacOS Sierra) and it has been resolved for me. Hope it helps.
In my case, application id and package were mismatched. This should be same as presented in following images...
AndroidManifest.xml
app/build.gradle
In this case you can see, applicationId and package both are same that is com.mycompany.mygamelibrary
May be its a Build Path Configuration problem.I did the following to solve the issue.
1.Right click on your project and go to Java Build Path.
2.Click on Order and Export tab.
3.Check Android Private Libraries and other 3rd part libraries if you have added.
4.Press ok and clean the project.
I hope it will solve the issue.
Once I had the same error message, but maybe the cause isn't the same.
I did a code and worked for a while, then I wanted to improve it and got the same error and I couldn't run it.
I could fix the problem with
the correct Build Path order (as I can see you've already did this)
I check on the Order and Export tab the android-suppor-v4.jar
and the key was the Android SDK Managert->Upgrade everything and (next) Eclipse->Help->Check for updates.
After I upgraded to the latest android plugin and SDK my app compiled and ran again.
I hope this will help you!
I'm not very sure about this but it might be that your system's debug.keystore license validity has expired as it is valid for only 365 days. You just need to delete the debug.keystore from your computer. The debug.keystore will be generated automatically by Eclipse when you compile your Android App.
Same message seen ... this time it turned out to be different output folders for MyApp/gen and MyApp/src in the Build Path (caused by Maven integration).
Unchecking "Allow output folders for source folders" solved the problem.
I had this issue in an Android application that needed an Application class which was created in wrong path inside the Android Studio project. When I moved the class file to the correct package, it was fixed.
This all Process work for me to solve application class Exception.
Step 1: Open Run(window+R) Search -> Prefetch Remove all file (Some file not Delete)
Step 2: Open Run(window+R) Search -> %temp% Remove all file (Some File not Delete)
Step 3: Open Android Studio -> Build -> Clean Project
OR
Select File > Invalidate Caches / Restart > Invalidate and Restart from Android Studio toolbar.
OR
Close and reopen Android project.
OR
Restart System
I ran into this issue several times and both times it seemed to be caused by some instant run feature.
In my case, deleting the application from the device and then installing it from Android Studio again resolved the issue.
I ran into this problem today. The project runs well for over a year but today it reports this issue, and cannot debug on my testing device.
I fixed it by updating to latest gradle version. Hope this can solve your problem.

Eclipse opens wrong source file on exception

I have several Android projects in an Eclipse workspace:
a stand-alone application project with a class my.package.Foo
a library project with a different class my.package.Foo
two application projects that depend on the library project and contain no source code
The problem comes when working with one of the applications built on top of the library project. When it crashes (sadly, a frequent occurrence), I double-click on a line of the stack trace in the logcat to go to the relevant source. The problem is, if the line is for Foo.java, Eclipse always opens the source from the stand-alone project. The only way I can direct Eclipse to the right source is to close the stand-alone project, which is somewhat inconvenient.
Is there any way to get Eclipse to pay attention to which application actually crashed when it looks for the relevant source file? I assume that this is some sort of classpath problem (similar to that described in this post). However, I don't see anything in the Android run configuration properties for modifying the class path. Eclipse always seems to run through the workspace projects in alphabetical order by name and opens the first my/package/Foo.java it finds.
I'm using the latest Android ADT and SDK versions.
Per the link provided in the comment by #blessenm, this is an issue with logcat in Eclipse. We should see a fix in Release 20 of the SDK tools. As can be seen here, the patch that fixes it has been completed and is in line for final approval.
Meanwhile, the best thing to do is to change the logcat preferences (Window -> Preferences -> Android -> LogCat) so that the double-click action is "Go to Problem (method declaration)" instead of the default "Go to Problem (error line)". This isn't foolproof: it will at least open the file but if there are multiple methods with the same name, it will go to the first method, regardless of signature. (When the fix is incorporated, there will be no need for options for double-click action and it should disappear from the preferences.)

Eclipse not automatically switching run configurations

Everything was working fine yesterday. I start to work on my project today and Eclipse gives me a bunch of problems. First, it wouldn't let me debug saying "Cannot connect to vm". I don't exactly remember how I fixed that problem, but I did. I was able to debug once again. I just recently created a new project to test something separate from my main project and now Eclipse is giving me some more problems. This time it is saying "An internal error occurred during: "Launching New_configuration".
Path for project must have only one segment."
After some searching, I found that it is related to the debug configurations. In order to debug a project now I have to go to Run->Run Configurations and select the project I want to debug. Before, it would automatically do this for me. I would just select a java file from a project and it would debug the project that contained the file. Also, I can't find my new project in the list of Android Applications under Run->Run Configurations. I've tried creating a new one in the menu, but when specifying a source it can't find my project folder even though it is clearly open in Eclipse. Eclipse has been giving me massive headaches lately and I don't understand what could have caused this to happen. Eclipse was left open all night and the computer doesn't go into sleep mode (sorry for wasting power!).
Any ideas on how to get it to see my project and make it automatically debug the right project?
What is the usual case (detailed below as a Run or Debug configuration with no project name) wasn't the root cause:
In the comments, I suggested:
Did you try to import this existing project in a brand new workspace? (to see if this isn't related to some kind of workspace metadata corruption?)
To which the OP Atlos replied:
creating a new workspace seemed to have fixed it. Not sure what could have happened to my old workspace to cause a problem like this.
Should I ditch my old workspace and just import stuff into the new one?
It happens, and can be caused by some process blocking the update of metadata, rendering parts of the workspace unsound.
It is perfectly OK in that case to save/move that old workspace (for reference just in case) and to create a brand new one.
This blog post mentions:
It seems that this rather cryptic message means nothing more in my case than “please enter a name and project for your run configuration”.
I did have a “name”, but left the “Project” field empty. Entering a value in the ‘project’ (the “AndroBlip” you see next to ‘browse’) fixed it.
Sources seem to indicate that the same error is produced if you don’t enter a value in the ‘name’-field.
It actually references the similar SO question "Android: “Path for project must have only one segment”".
Note that you would see the same error for trying to have a project within another project (as detailed in this thread).

Categories

Resources