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.
I have been following the instructions for integrating the facebook SDK into my apps. I have succeeded in getting all the given sample apps to compile and run except for "helloFacebookSample". For this I get a compilation error:
Project 'HelloFacebookSample' is missing required Java project 'facebook'
My understanding of projects/libraries/build paths etc is a little hazy, but I can not work out why this should fail where all the others succeeded.
Here's a screen grab of my properties window for HelloFacebookSample:
I can confirm that the directory:
c:\android stuff\facebook\facebook-android-sdk-3.0\facebook\bin
contains a file facebooksdk.jar
Any ideas?
EDIT: Thrashing around some more, I just clicked on the "projects" tab that you see in the screen grab above, and saw that it says "facebook (missing)". I'm a bit confused because I thought that projects may need to rely on libraries rather than other projects... but still I have no idea how to resolve the problem. I don't seem to have a project called simply "facebook"...
Edit: thrashing around some more, I just experimentally deleted the "facebook (missing)" from the java build path and then did an "add" of "FacebookSDK"... I thought this was cluttching at straws, but to my surprise it worked!!! HelloFacebookSample compiled and ran!!! - I have no idea what's going on though and would still like an explanation.
The previous version of the Android Facebook SDK referred to the project as 'facebook'. It looks like this sample was not updated to delete the old reference, and add the new one to 'FacebookSDK'. You took the corrective steps to resolve this yourself already by modifying the Java Build Path of the project.
The problem will easily be removed by simply going to the properties of your project and right clicking it, then go to project tab, select the project which prompts missing and remove it.
Now click on project->build project->clean
Now run your project and it will surely do fine
If you read:
http://developer.android.com/tools/testing/testing_android.html#TestProjectPaths
It will tell you to create your tests inside your project at the same level as src. What it doesn't tell you is how to do it.
I checked out a post on here about this (http://stackoverflow.com/questions/5395216/creating-an-android-junit-test-project-in-eclipse) and found that it no longer seems to work on newer versions of Eclipse (Indigo for example).
So, how can you set up the project as they suggest so that the test directory is inside of the original project?
Note that if you do as the link suggests and uncheck the use default location, then Eclipse will prevent you from going forward as it gripes that you overlap the location of an existing project. If you try to add a sub-directory manually to place your project, then you can go on but you will get an error later saying "An internal error occurred while refreshing workspace" and no test project gets created.
Surely there is a way to do this isn't there or should I just disregard the suggested package structure and go with what Eclipse seems to want to do?
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.)
Basically, I need help importing downloaded source or creating a project from sample source programs. I'm looking for step by step instructions for both if anyone can point me there or post the steps.
I'm very new to Android/Eclipse. I have the environments installed and have successfully written a very minor app that works on the emulator and my real Droid X. I cannot, however, get any of the Android samples into a project without errors. I've tried importing, creating from existing source, and etcetera and it's all a mess with errors everywhere.
I have, however, successfully created a new empty project, then brought the components into the project one at a time typing or pasting in code for every file. I'd hover over and import Android and other components as needed. The WiktionarySimple, for example, ran with only a couple of changes and several warnings that I left alone. (I had to add 'formatted="false" in the statements below...)
<string name="template_user_agent" formatted="false">"%s/%s (Linux; Android)"</string>
<string name="template_wotd_title" formatted="false">"Wiktionary:Word of the day/%s %s"</string>
But there has to be an easier way to import! I've done the intuitive and I've followed instructions that I've found, but to no avail. Can anyone give me a complete list as to how to import or create a project from existing source or from source I've downloaded from the web?
Step #1: Start a new Android project
Step #2: In the first page of the Android project wizard, choose the "Create project from existing source" radio button, then click the Browse button and find the directory containing the project
Step #3: Tweak settings to suit, then press Finish
Step #4: If needed (not sure if it is anymore), right-click over the project name, and choose Build Path > Configure Build Path from the context menu, and make sure the Android entry in the checklist is checked
Its quite possible that you are not importing these projects incorrectly and that you are simply running into common problems that occur when importing projects.
For instance your problem involving adding formatted="false" is quite common and due to a change in the strictness of aapt, which is explained in this question. It is likely that the sample project was created before the change and has not been updated since.
That error involving the formatted="false" can also cause many more errors, since any xml after that error is often not parsed and thus any resources declared after it are not known. So the error No resource found that matches the given name (at 'hint' with value '#string/search_hint') and others like it are often due to the formatted="false" error. I would suggest fixing all the % sign errors with the formatted="false" then letting it rebuild and see how many errors are left.
As for the String types not allowed (at 'layout_width' with value 'match_parent') a quick search on stackoverflow says that its caused because FILL_PARENT was replaced with MATCH_PARENT in Android 2.2. So you need to set your sdk for the project to be Android 2.2 or higher. Here is the link to that question as well.
This happened to me in importing the wiktionary sample and i found the solution.
Import the project through existing code
Right click project and choose properties
In 'Android' Tab the default choice is the minimum API. Changed it to the latest(highest API)
Click ok.
Clean and build your project and errors will be gone
(probably optional)
6. Change the target and Minimum SDK in the Android Manifest