Android Activity ClassNotFoundException - tried everything

前端 未结 15 2135
有刺的猬
有刺的猬 2020-11-22 12:02

I\'ve just refactored an app into a framework library and an application, but now when I try and start the app in the emulator I get the following error stack trace:

相关标签:
15条回答
  • 2020-11-22 12:41

    I had this problem with a project I was working on, though my case was different. If anyone out there still can't find the solution to their problem, try checking this:

    In Eclipse:

    Project properties -> Java Build Path -> Source tab
    

    Inside you'll find a list with all the source folders to be compiled and put into the generated apk each time to build your project (and /gen). Tipically:

    >MyProject/gen
    >MyProject/src
    

    What you'll want to be sure of is that inside each of your source folders (exclude /gen, so only /src in this case) the item Output folder is poiting to the default output folder, which is MyProject/bin/classes. Do this by selecting Output folder and clicking Remove from the right set of buttons (this will make it point to the default folder).

    If you can't see the subitem Output folder, check "Allow output folders for source folders" right below the list

    0 讨论(0)
  • 2020-11-22 12:44

    If you followed all the hints (checked the private Libraries etc.) and still have the bug. Check your manifest for this Line of code in the application-tag

        android:hasCode="false" 
    

    Remove it and be happy. (I was finally) :)

    0 讨论(0)
  • 2020-11-22 12:45

    I was getting these type of error and i have tried everything but didn't get the solution. then i figured out if you are using library as aar file then you have to add all dependencies of your aar library to your app gradle.build file. if someone didn't figure out solution then try this!

    0 讨论(0)
  • 2020-11-22 12:46

    I was getting the same issue. But then i checked the current structure of the application.I found that older application structure(i don't know the time it is changed by android framework developers) has a folder name "lib" which is now "libs". I migrate my all jar files into "libs" and the error is gone. I hope this may help to someone :)

    0 讨论(0)
  • 2020-11-22 12:48

    I've just refactored an app into a framework library and an application.

    I'm not entirely sure what you are trying to say here, but the fact that you used the word "refactored" here leads me to believe that you are misunderstanding the concept of a library project.


    What library projects are:

    A library project is a development project that contains shared source code and resources. Other Android projects can reference the library project and include its compiled sources in their .apk files at compile time.

    What library projects are not:

    A library project differs from a standard Android project in that you cannot compile it directly to a single .apk file and run it on an Android device. You can't use an Android projects as a library project, and then have another Android project extend the library project. It doesn't work that way.


    That said, I would investigate the structure of your library project and insure that you've set it up correctly. It's OK to use your library to store shared code/resources, but if your library is attempting to behave as if it were a separate .apk within the library project itself, then you've probably done something wrong. I believe a ClassNotFoundException would be thrown if this were the case. To fix the problem, I'd just build the library project from scratch, rather than attempting to convert the Android project to a library project. That'll prevent you from running into tiny, annoying bugs.

    Feel free to post more code if you are still having trouble. You should also elaborate a bit more on the structure (and purpose) of your library project... why you decided to use one, how you created it, etc.

    0 讨论(0)
  • 2020-11-22 12:48

    I had the same problem and wasted most of a day trying all sorts of things. The app ran find when deployed from one pc but not on this one pc. In the end it ended up being a missing java nature! Strange how it showed me java build paths, order/export and all that but yet didn't have a java nature. :( Hope this saves someone else a lot of time

    0 讨论(0)
提交回复
热议问题