ClassNotFoundException: previously working Android Project - java

I had a working android project but needed to start from scratch. I copied all my source files and layout files over. There are no compilation errors but when I try to run, I get the following error.
11-27 17:21:56.793: E/AndroidRuntime(1450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{projects.mobile.mapappproject/projects.mobile.mapappproject.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "projects.mobile.mapappproject.MainActivity" on path: /data/app/projects.mobile.mapappproject-1.apk
I am running eclipse juno and trying to run on Android 4.2. Thanks !

Rather than doing copy paste try following
1.Create an android application project
2.Delete the files which was created Eg.MainActivity and layout.
2.Right click on project name and click import ,then from File system.Go to your project directory to import the source from there
3.select that, then finish.
4.Clean and build then run

Try these
Add the Activity to AndroidManifest.xml
Is there a difference in your folder names ? For example projects.mobile.mapappproject-1 or projects.mobile.mapappproject !

I copied all my source files and layout files over.
It looks like you forgot to copy over the entries that existed in AndroidManifest.xml, however. Each Activity has an entry there and that entry is required for the framework to find and launch the UI.

I had the same problem, but I found out that a library reference path wasn't right. After I fixed that everything worked fine.
You can check this at Right-click on your project => Properties => Android -> (Library)

Just for the record in case I can help someone :
I had a project that somehow didnt work after importing it from git. I solved this by giving the name of the activity explicitly.
example:
before:
<activity android:name=".Main" [...] /> (relative)
after: <activity android:name="com.example.package.Main" [...] /> (absolute)
This may also occur if you change the manifest package and keep your relative reference (which I think is default).

In my case, following 2 steps fixed the problem
a. Setting compileSdkVersion, buildToolsVersion, targetSdkVersion to the same SDK version in build.gradle.
b. I was missing a dot in application class name in AndroidManifest.xml (Ex. android:name=".ui.ApplicationLoader")

Related

How to add and use MarkdownView android library

I am on Android Studio 1.5.1
falnatsheh/MarkdownView
In the project's readme at github its gives instructions for use. These don't cover actually adding the project .. and I am learning Android programming (in fact I am making an app to keep my notes, as a sort of second step after "hello world").
how do I add it to the project so that I can follow the instructions on the project's readme? My default attempt was to follow these instructions:
File -> New -> Import Module .. add as ":markdownview" in my case, add it to the app's build.gradle, and then that should be it according to the site.
But that doesn't work:
The project's readme starts by saying you should add "compile 'us.feras.mdv:markdownview:1.1.0'" to the dependencies file (I am assuming they mean the Module:app one)... which looks like another way to add ":markdownview" to me.. but I did that too (and that instead of the ":markdownview"). Still the symbol does not resolve.
how do I add it to the project so that I can follow the instructions on the project's readme?
Add the following to your app/build.gradle file:
dependencies {
compile 'us.feras.mdv:markdownview:1.1.0'
}
which looks like another way to add ":markdownview" to me
Not exactly, but close.
but I did that too (and that instead of the ":markdownview"). Still the symbol does not resolve.
As with everything else in Java, you need to add an import statement.
I just created a scrap project in Android Studio, accepting all defaults in the new-project wizard. I pasted the above snippet in app/build.gradle and let Android Studio sync with the project files. I then added a reference to MarkdownView in the Java file, and Android Studio picked up the import without issue.

Consuming aars from eclipse does not work

*THIS PART WAS MY ORIGINAL STARTING PROBLEM. PLEASE READ THE UPDATES
I have imported an android project in eclipse that apparently depends on rengwuxian.
Since I could not find the jar and did not know how else to do it, I followed the instructions in consuming-aars-eclipse and imported a second project with the artifacts from the aar as an android eclipse project as well.
Then in my original project that I got compilation errors for com.rengwuxian.materialedittext.MaterialEditText in my layout files I added this newly created from the aar project as a reference (Project->Properties->Build Path->Add Project)
The compilation errors got resolved! But in my layout files now everywhere that is defined the element com.rengwuxian.materialedittext.MaterialEditText I get errors in the resource definitions.
Eg.the following:
error: No resource identifier found for attribute 'baseColor' in
package 'com.test
The attibute it seems to complaint about is:
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/client"
android:layout_width="match_parent"
android:layout_height="wrap_content"
.....
android:textColor="#color/text_color"
app:baseColor="#color/text_color"
app:primaryColor="#color/text_color" />
---> app:baseColor="#color/text_color"
This #color/text_color is defined in my original application in the original application's package and apparently the classes in the aar imported project (com.rengwuxian.materialedittext.MaterialEditText) can not see/access these resources.
How can I fix this? Or is there another better way for my problem?
Note: I also tried adding a source link to the folder of my project's res/ folder but did not solve this.
Update:
I removed the reference to the project and add the classes.jar to the build path (this jar was inside the aar project). Same issue
UPDATE 2:
I found this that helps to import aars to eclipse aar-for-eclipse. I copy/pasted the code snippets (task copyJarDependencies etc) in the folder but I got an exception:
No such property: libDir for class: org.gradle.api.tasks.Copy_Decorated
So I added a def in the line `libDir = new File(project.projectDir, '/libs')
Then this worked but I got:
Could not find property 'compile' on configuration container
How can fix this? I am not sure what to declare or what is missing
Update 3:
I added apply plugin: 'java' and the compile attribute is ok now but I get:
configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
How can I fix this so that it works?
I am using this project ---> https://github.com/rengwuxian/MaterialEditText
And this post ---> http://www.nodeclipse.org/projects/gradle/android/aar-for-Eclipse
I've got a similar problem with gradle but on android studio. Solution for me was to use
configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each {moveJarIntoLibs(it)}
instead of:
configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
And remember not to apply java and android plugin in the same project, because it won't work (see gradle with --debug --stacktrace )

Error "No resource identifier found for attribute 'rectLayout'"

I was trying to create a new project for android wear in eclipse , but there is a problem in main layout i don't now how i can solve it , this is my main layout:
<android.support.wearable.view.WatchViewStub
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="#layout/rect"
app:roundLayout="#layout/round"
tools:context=".MyActivity"
tools:deviceIds="wear">
</android.support.wearable.view.WatchViewStub>
it is give me this error :
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'rectLayout' in package
'com.example.wear'
- error: No resource identifier found for attribute 'roundLayout' in package
'com.example.wear'
my project have two layouts "rect.xml" and "round.xml" and it is compile with 4.4W and target is 4.4W and also i have a copy of classes.jar in libs folder .
The code you've posted is fine. The problem here is that you have a copy of classes.jar in your /libs folder, but this is not a right way to properly use wearable-support-lib. This wearable-support-lib contains some resources that cannot be packaged inside a .jar file, so you need to import it as a "Library project" and attach it to your project just like other external libraries.
You need to go back to the wearable-1.0.0.aar file, located in relation to your sdk folder:
./extras/google/m2repository/com/google/android/support/wearable/1.0.0/wearable-1.0.0.aar
Unzip the whole wearable-1.0.0.aar file somwehere to your workspace. You will see that it looks almost like a standard android project.
Move classes.jar to /libs/classes.jar - inside this project, not to your own project.
Now you have to create new project from these files, with package name defined android.support.wearable.
Compile it with API 20 and check "Is Library" in project properties in Android tab.
Add reference to this library project from your project.
You can see more details about using wearable-support-lib in my other answer and in this great blog post (by Benjamin Cabé).
I just added the following code in the dependency section in my build.gradle of the module:
compile 'com.google.android.support:wearable:2.0.3'
compile 'com.google.android.gms:play-services-wearable:11.0.0'
What worked for me was changing this:
xmlns:app="http://schemas.android.com/apk/res-auto"
To:
xmlns:app="http://schemas.android.com/apk/com.mydomain.myapp"
Where com.mydomain.myapp is the package id of my app.
Presumably the res-auto functionality was not working in my project for some reason.
I got this problem too sometimes, in my case i solved it by rightclicking on the AppCompat map then click on refresh, do this with your projectfolder too.

Didn't find class on path: dexpathlist

Seriously, i don't know what to do to solve this problem.
My android project was working fine, until i needed to import a library with Maven. Since that, everything started to collapse.
What is happening: When i start my application, the following error appears on LogCat and android tells that my app stopped working. I've searched for this similar error here AND on the rest of the internet, but everything people did haven't worked for me.
Error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.buscaserra/com.buscaserra.main.ActivitySplash}: java.lang.ClassNotFoundException: Didn't find class "com.buscaserra.main.ActivitySplash" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.buscaserra-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.buscaserra-2, /vendor/lib, /system/lib]]
Manifest and packages:
Build Path:
Same problem here.
What worked for me was adding android-support-v4.jar as a lib and making sure it was checked on Project properties -> Build Path -> Order & export.
It was mentioned here
I had the same problem when I moved the project folder from a Linux machine to a Mac.
What I did was:
Close the project
Remove the .iml file
Import the project using the "Create new project using existing code"
I am using IntelliJ.
Cheers.
I did the following steps to resolve the issue on Android Studio.
open file ./app/build.gradle
reduce compileSdkVersion (e.g. 22 -> 21)
click 'sync project with gradle file'
change back to the original compileSdkVersion (e.g. 22)
click 'sync project with gradle file'
recompile and it should work.
I have spent way to many hours on this stupid issue but finally got it resolved:
When creating a new project -> package name is causing this stupid dex issue to appear, must not be able to find the main activity during run time with whatever deployment assemply setup. Android Studio doesn't like some of my commonly used package names, I'm completely baffled..I think this is a pretty big bug haha
Given the following new project parameters:
Name: NotificationApp,
packageName: com.stores.business.notificationapp,
saveLocation: /home/me/AndroidStudioProjects/NotificationApp
I would get the following error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.stores.business.notificationapp/com.stores.business.notificationapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.stores.business.notificationapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.stores.business.notificationapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.cvs.stores.myapplication-2/lib/arm64, /vendor/lib64, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
My Solution
I resolved it by changing the package name to:com.notificationapp, then File->invalidate caches/Restart..hope this helps someone else haha
Do you have any required projects on the build path? Can't tell from your screen shot but check your "Projects" tab. You may have inadvertently added a Project Library as a required project instead. Remove the project from the Projects tab and then project -> properties. Click Android, add the project as a library instead here...
Make sure that any compatibility lib jars that you're using in your main project (like android-support-v4.jar) are the same versions as those used in any of the projects that your main project references.
I had this same problem and what solved it was to copy and paste the android-support-v4.jar from another library project (that my main project was referencing) and pasting it into my main project's /libs folder.
I had the same issue.
Nothing had changed except Android studio and Gradle updated since I last compiled.
I took a look at the build options under Build>Edit Build Types and noticed that the one option that was different between my project that didn't run and the ones that did work was the Minify Enable option.
I set it to false and now everything works again.
I should understand the problem by just seeing "dex errors".But it took half day to fix the issue.
I fix this by following android developers page's instruction: https://developer.android.com/studio/build/multidex.html
First add this to my gradle.build:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Then I extend my Application class (or declare the application class in AndroidManifest.xml or override attachBaseContext() function) as instructed by the MultiDexApplication class document on the page. This have fixed my problem.

Android Screenshot Plugin Working in Cordova 2.0

I am currently developing an Android app using cordova 2.0. Obviously the plugins.xml has been depreciated and everything is now housed in config.xml. I was just wondering if anyone has managed to get the Phonegap Screenshot plugin working in Eclipse and Cordova 2.0 working on android.
Plugin can be found:
https://github.com/josemando/phonegap-plugins/tree/master/Android/Screenshot
I have added:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to my Android manifest xml. And made sure that:
<plugin name="Screenshot" value="org.apache.cordova.Screenshot"/>
is added to my config.xml (that now contains all plugin information from plugin.xml)
Screenshot.js is added to the directory:
assets/www/js/
However I am unsure where exactly to place the Screenshot.java file. The example has it in:
src / org / apache / cordova /
However as I did not have this directory I simply placed it in:
src/uk.co..appname1.appname2/
When I did this however it produced errors, the first one being:
The declared package "org.apache.cordova" does not match the expected package "uk.co.mysitename.appname1.appname2" Screenshot.java /Project Name/src/uk/co/mysitename/appname1/appname2line 8 Java Problem
This refers to this line in the Screenshot.js:
package org.apache.cordova;
The two suggested actions to fix this are to:
Move 'Screenshot.java' to package 'org.apache.cordova' (this directory doesn't exsist atm)
Or change package directory to 'uk.co.mysitename.appname1.appname2'
The second error says:
The method run() of type new Runnable(){} must override a superclass method
The suggested action for this being to "remove '#override' annotation"
I have tried to do every possible combination of these however I cannot seem to make progress and get it all to link up. Usually because it thinks that CordovaRef isn't referenced. I am unsure if the plugin even works on Cordova 2.0.0. I have some experience with Phonegap/Cordova but only in ios with Xcode and Objective C plugins. I am new to Java, Eclipse and Android. Any help or clarification on any of these matters would be greatly appreciated.
Answer resolved by:
Phonegap Screenshot plugin in Cordova 2.0.0
Answer/solution provided by Simon MacDonald

Categories

Resources