1

I’m posting this because it took me ages to fix and I could find no tips on-line.

I hope my question and answer helps a similarly afflicted person.

When launching, my app crashed and in the Eclipse LogCat it showed an AndroidRuntime Error saying it was:

Unable to instantiate activity - java.lang.ClassNotFoundException

Somehow , my main activity was not being uploaded to the android device and I could not work out why not.

I’m not sure if it is relevant but I am building the calendar-android-sample from google.

3
  • My answer is coming soon.. once I have earned enough reputation :-) Commented Apr 2, 2012 at 21:14
  • did you declare an activity element for you Activity in your manifest file ? Commented Apr 2, 2012 at 21:55
  • Thanks Nammari, yes I did declare my class in the manifest. Commented Apr 3, 2012 at 20:55

4 Answers 4

4

Answering my own question:

Somehow the source output folders in my eclipse build path were setup wrongly.

Looking in Project>Properties>Java Build Path>Source Tab :

The default output directory (bin/classes) had been overridden for the most important source folder(ie src/main/java). It was configured to use target/classes as the output folder (shown below):

enter image description here

So this was causing my source classes to be created under the target folder (although since they are not shown under package explorer I had to use navigator to spot them).

Anyhow, I removed the check from the box highlighted in red above. This caused all output folders to align to the default and my source classes were created under bin/classes (again I had to use navigator instead of package explorer to check they were there).

Then when I did a launch all my classes got downloaded to the android device and I had no runtime errors.

I hope this helps someone.

Regards, Peter

Sign up to request clarification or add additional context in comments.

1 Comment

Dude, you are my hero, I spent 6hrs in this while trying to run a fresh project generated from android quickstart archetype. I really appreciate this, I knew eclipse was the culprit here, cuz the APK ran fine when build in command line.
0

may be that the class is not supported by the API that have in your the emulator or device, so the class is not found

Comments

0

I just had the same issue with Android Studio (IntelliJ), my solution was:

  1. File > Project Structure
  2. Select "Project" under "Project Settings"
  3. Took the file path at the bottom of the screen under "Project compiler output" and nuked the contents

After that it worked fine

Comments

0

Android Studio

If using Android Studio refer to Stack Answer by Jagdeep Singh this solved the issue for me

Basicly: Just delete the below folders

  • myproject/gen
  • myproject/out

Then rebuild project

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.