I am trying to build a tiny sample application with ActionBarSherlock 4.1 using Eclipse Indigo and ADT r20.
I created a new Android project with a blank activity, copied actionbarsherlock.jar to libs and referenced it in the build path.
The app builds successfully, but upon starting on either the emulator (using 2.2) or the device (using 4.0.4), it crashes with the error:
java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable
at com.actionbarsherlock.view.MenuInflater$MenuState.readItem(MenuInflater.java:328)
...
I am not using proguard.
I have tried cleaning the ActionBarSherlock project, copying the new jar into my sample project's libs, and then cleaning my sample project.
My MainActivity.java is quite simple:
package com.example.lrn;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import android.os.Bundle;
public class MainActivity extends SherlockActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
The menu has but a single item:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_settings"
android:title="#string/menu_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom" />
</menu>
And the AndroidManifest.xml is also just about as Eclipse created it:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lrn"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
At this point I really have no idea what I may have missed.
I resolved this issue myself by adding ActionBarSherlock to my Eclipse project in a different way.
Instead of copying actionbarsherlock.jar into libs and adding it to the build path, I added it as a referenced project in the Android section of the project properties.
The app now builds and runs correctly on both the emulator and the device.
If you get:
ActionBarSherlock: java.lang.NoClassDefFoundError:
com.actionbarsherlock.R$styleable
exception, then you can fix that by adding Sherlock theme in your manifest file.
android:theme="#style/Theme.Sherlock.Light.DarkActionBar"
There's a problem with the latest ADT 21.1 that can cause this error to surface, even if everything else seems correct. You can fix it by downgrading to ADT 21 and the tools r21. Here's a bug report with some more detail:
https://code.google.com/p/android/issues/detail?id=42686
Please let your project's package name and the 3rd party lib package name as the same.
e.g.
if the 3rd party lib package name is com.actionbarsherlock
and your project's package name is com.yourproject
it is of course, you will get java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable error.
To use the 3rd party lib and not use reference like Michael Hampton's answer,
you should follow the steps:
rename the package name of com.actionbarsherlock to com.yourproject( I assume
that the package name of your project is com.yourproject.
Click right button of the mouse on your project -> Android Tools-> Rename Application Package)
copy com.actionbarsherlock/bin/xxx.jar to com.yourproject/libs
copy or merge the resource from xxx.jar in the com.actionbarsherlock's res, such as values, anim, drawable and etc.
I have encountered the same problem, and use the method above thought by myself successfully.
If there's more problem, please ask more. I hope all guys could settle the same problem.
make sure ActionBarSherlock project \gen folder has R.java file
Related
I am using ADT 23.0.2.
I just imported the google-play library to my workspace and added the reference to it in my project.
Now nowhere in my project the resource ids can be recognized because there is no R file.
(Anywhere I have R.id.blah I get the error "R cannot be resolved to a variable);
It's just gone. What am I supposed to do?
I exactly followed the steps by developers.google.com. It's nothing complicated but I don't know why this happened.
(I have all layout files in place and no import for android.R are in my class files.)
Before adding the
Tools I use:
Here are screenshots from my app properties:
My manifest
<permission
android:name="com.appname.appname4.MAPS_RECEIVE"
android:protectionLevel="signature">
</permission>
<uses-permission android:name="com.appname.appname4.MAPS_RECEIVE"/>
<activity
android:name="com.appname.appname4.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.appname.appname4.SearchResultListActivity"
android:label="#string/title_activity_search_result_list"
android:parentActivityName="com.appname.appname4.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.appname.appname4.MainActivity" />
</activity>
<activity
android:name="com.appname.appname4.ContactInfoActivity"
android:label="#string/title_activity_property_detail"
android:parentActivityName="com.appname.appname4.SearchResultListActivity"
>
</manifest>
I had similar issues when I first started Android programming. Here are some fixes that worked for me in the past.
1. Fix/Check all xml(layout) files.
Many times a R file not being generated is due to an issue with your layout file or Android Manifest file. Follow this link and work your way down the page checking permissions and the general layout format.
2. Project/Clean.
go to Project->Clean.
Also make sure you have selected the option to build project automatically.(Without this option check marked R file is never generated automatically).
3. Fix Project Properties.
Right click on your project in Package explorer then choose fix project properties.
Repeat Step 1 after this.
4. Builders.
Go to Project->Properties then Builders. Select the appropriate boxes.
Repeat Step 1, and Clean and rebuild project.
5. Appcom7 and Google Play services error.
Sometimes to fix errors associated with installing these two reference libraries. I copy there folders into a generic library folder on my hard(where I keep most of my eclipse reference libraries), after this I delete them from the Package explorer and from the "default" directory where they were installed. I Fix project properties again and clean/rebuild. This should get you back to your non-reference library version of the package. Then I manually add them as Projects to my eclipse IDE and finally follow this to add them as references to my project. Then fix project properties,clean and rebuild.
6. Reference Question.
Finally, referring to this StackOverflow page has helped me countless times. And one way or another fixed my issue.
Good Luck.
I am running Eclipse 4.2.2 Juno on Windows 64-bit for development on Android SDK 17 with ADT. Just today, I cleaned a working project, only to find that the R.java file would no longer generate.
This problem has a very divergent list of possible causes. User Gray, in response to the thread located here, listed a set of articles, all addressing different possible causes.
He says:
Dont worry. First you may clean the project, then run the project. If
this does not work then follow the following links:
And then proceeds to list articles pertaining to different causes of this problem, the links to which I am unable to include, but can be found in the question linked to above.
Gray's comment is a good summary of the most common causes to this problem, including resource file naming convention, the erroneous "import Android.R" statement, XML errors, corruption requiring cleaning and rebuilding, and checking the Android SDK in Project -> Properties -> Java Build Path / Libraries.
The problem is, my R.java still doesn't generate! The only remaining possibility within Gray's list seems to be that either my main.xml or AndroidManifest.xml is broken, so I have included them to make sure I didn't miss any errors.
My main layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.bostonwalker.sseng.SSSurfaceView
android:id="#+id/ssview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
And my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bostonwalker.enginedev"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
As a beginner Android programmer, this is beyond my capability to debug. Can someone please find an explanation?
First check if there are any errors in your resource file's. R.java will not be generated if that's the case. Check if you have updated your adt to rev 22. If so follow the below
Right click on your project goto properties. Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.
Also goto android sdk manager and check that you have the android sdk build tools installed. This many not be necessary but make sure you have android build tools installed.
Check the link below
Eclipse error: R cannot be resolved to a variable
Whenever your generated R class isn't generated, it indicates that there's a problem with generating it due to some parsing issue from the XML resources. Check the error console in your IDE to figure out what's specifically wrong.
Common problems are:
An unescaped character in your strings.xml, for instance you're instead of you\'re
Missing layout_width or layout_height tags in layout resources
Missing namespace declarations
Variable names that aren't supported by Java, for instance due to capitalization or use of spaces, hyphens or other unsupported characters
Any other kind of syntax error in XML
In addition to what Reghunandan said, I just had the same issue after updating to SDK 22 with Eclipse Indigo Win x64. Turns out that when updating the SDK Manager uninstalled the old Build Tools and never installed the updated ones so I had to run it through again to get them reinstalled. Doing this fixed my issue and all the build errors disappeared.
Note: I had to restart Eclipse before the errors disappeared, even though I wasn't prompted to.
I faced a similar issue and found that I imported com.google.android.gms which had a reference to google-play-services.jar. So once I added the path of google-play-services.jar in my apps libraries, R.Java is generated.
I'm working with an Android project I've Imported from someone else. I've got all the dependencies sorted, there are no errors in the project, but when I try and launch it, I get:
04-08 16:49:41.761: E/AndroidRuntime(19254): FATAL EXCEPTION: main
04-08 16:49:41.761: E/AndroidRuntime(19254): java.lang.RuntimeException: Unable to
instantiate activity ComponentInfo{com.me.app/com.me.app.ui.ActivityDashboard}:
java.lang.ClassNotFoundException: Didn't find class
"com.me.app.ui.ActivityDashboard"
on path: /data/app/com.me.app-1.apk
My Manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar">
<activity
android:name=".ui.ActivityDashboard"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
This seems to be a common problem, I've read all the other questions I've found and done the following, all to no avail:
ADT and the SDK are fully updated
I'm building against Android 2.3.3 (SDK 10)
This is selected under Android Build Target, and the Library is in the Java Build Path
All the classpaths in the Manifest are correct, I've double checked them all.
All Activities are in the Manifest, with the correct Intents.
and the Library is in the Java Build Path
That is incorrect. Please back out this change, then move the JAR into your project's libs/ directory.
While adding a JAR manually to your build path will satisfy the compiler at compile time, it will not add the contents of the JAR to the APK file at runtime, resulting in ClassNotFoundExceptions and the like.
Note that I am referring to third-party JARs, such as the first four entries in your screenshot. None of those appear to be in libs/, and all need to be.
The sole exceptions for the all-JARs-must-be-in-libs/ rule are:
Android's own platform JAR, attached to your project via selecting the build target (reason: this JAR's contents specifically does not need to be included in your APK)
Android library projects, which have their own libs/ directories for any third-party JARs that they reference
Your core error is that com.me.app.ui.ActivityDashboard is not found, suggesting that this is from one of your four JARs that are not in libs/.
I have been looking for this on stack overflow for the past two hours and have tried a lot of things but nothing worked.
I have installed eclipse juno just this morning and i am getting this error R cannot be resolved to a variable in any project that I create. Also, I cannot see any files under the gen folder, even after I build the project. I have tried clean project, installed ia32 libs for my 64 bit system running ubuntu, tried changing folder positions, rebooting system but nothing worked.
The generated code is:
package tanvi.alarm;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
/>
</RelativeLayout>
manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tanvi.alarm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Check if you have this line
import android.R;
and if, remove it and clean and build project again.
Same thing is solved here. Check my answer.
I had the same problem as you but in Windows, and I found a solution to it.
You have to check your SDK's folder permissions. I moved my SDK folder, which is located in my second HDD, to a new folder and it all worked perfectly.
After upgrading to Juno, I had this problem. It was fixed by using the Android SDK Manager to install Android SDK Build-tools.
I've just spent a day finding a fix for this problem.
In my case I started with Eclipse: Help->Check for Updates. These updated and I then opened the SDK manager and updated a few packages there too.
After that I had the 'R cannot be resolved error' for new projects and also the 'Could not find *.apk' in other projects
My solution was to Help->Check for Updates in Eclipse again and then open the SDK manager again and a small number of extra packages were available for an update. These updates were not available the first time I looked for updates.
I restarted Eclipse after the 2nd round of update and all was fine after that.
Hope this helps someone in the future.
If nothing above is resolved then check your /res folder where there might be an error in xml file. Due to this error R.Java file will not be updated due to which the above problem might occur. If have the error in xml file it must be probably in res-values-strings.xml. Try removing that error and also update your Androidmanifest.xml if any string values are used.
This will automatically resolve the issue.
I installed Juno myself yesterday and had to faff around in the beginning but everything seems to be working now. You didn;t say which SDK you've installed, but I'm assuming you are using the latest SDK (r20) as you seem to have dotted all the other Is. However, as r20 is the only version that currently works with Juno it would be best to check if you're unsure.
Unsurprisingly the code you supplied in the question works as is, so the problem isn't there. However, if there is an error in one of the XML files in that you have supplied, you'll need fix those before the R class can be generated.
Alternatively, if you previously had a 3.x version of Eclipse installed are you still using the same workspace for for running Juno? If so I suggest starting again in a fresh workspace and see if you have the same issues. Even using -clean on the old workspace won't cut it. If you want to keep using the old workspace directory, delete the .metadata directory within it and try again, though you will need to import any existing projects afterwards.
To be honest, I'd be surprised if it was a workspace clash as I'd expect you to have more problems that just an R cannot be resolved error, but I'm just trying to cover the bases.
I had to install this library on my ubuntu 12.04, sudo apt-get install ia32-libs (my system is 64 bit).
And on restart of eclipse, the files were generated.
If the problem persists, check if the Project -> Build Automatically is selected. Once selected, the project should run fine.
I just used Android SDK Manager to update Android SDK Tools to revision 17, and Android Compatiblity to revision 7. Now, the program I've been running for ages crashes on startup.
Narrowing down the issue, I have created a new blank project, added android-support-v4.jar to the build path, and changed Activity to FragmentActivity and that's all. Now it crashes.
The error message is:
java.lang.ClassNotFoundException: com.example.test.TestActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.test-2.apk]
The code is:
package com.example.test;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class TestActivity extends FragmentActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Everything else, including the manifest, is unchanged from the defaults. Any help is much appreciated!
Edit: Manifest included below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TestActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Turns out it's a problem with Android SDK Tools r17. I had previously been using the method given in the tutorial at:
http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/
However, this no longer works. Instead, all I needed to do was right-click on my project in Eclipse and choose Android Tools-->Add Support Library...
Doing this means it is no longer necessary to go to Java Build Path and click "Add External JARs..."
Many thanks to eMich for this solution from: Jar-file issue with ADT r17
I had the same issue and none of the answers I found in stackoverflow solved my problem. After hours of several (many) trial-and-error, I solved my problem by configuring build path of my project. In Eclipse, right click the project > Build Path > Configure Build Path..., in Order and Export tab, check Android Private Libraries, click OK. After that, clean up the project and try running again.
I solved this problem by comparing my project with other (newly created) project that could run as expected. I compared each configurations and AndroidManifest.xml of them.
Hope this helps you too :)
UPDATE Other solution: using ANT
I found another way to solve this problem: using ANT. My friend faced the same issue, but fixing the build path didn't solve his problem. I don't know whether it was because we use the different IDE version, different ADT version, or different operating system (I use GNU/Linux). And then, I suggested him to use ANT rather than the IDE's one.
First, setup the project (create build.xml) by executing android update project -p <project-dir> -n <project-name> for each project (including library projects). And then, from the main project's directory, execute ant debug to build, ant installd to install, and run the application.
The strange thing was, once he succeeded with this way, he even can compile by using IDE again, without ANT at all.
I assume that fragment activity is listed in the manifest properly? Here's my main FragmentActivity class in the Manifest:
<activity android:name=".Polling" android:label="#string/app_name"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
select your project in Package Explorer > Right Click it > Android Tools > Fix PRoject Properties
and also
Try Project > Clean
Then rerun.
I got the
java.lang.NoClassDefFoundError: com.android.example.SupportFragment
at com.android.example.SupportFragmentActivity.onCreate()
on PopupMenu
SupportFragment extends SherlockFragment implements PopupMenu.OnMenuItemClickListener
...
#Override
public boolean onMenuItemClick(android.view.MenuItem item) {
return onOptionsItemSelected(item);
}
when trying to make a api 17 app compatible with api 8, the only indication was the logcat error above, so check that all your imported classes are supported if you get this error.
Same issue got solved by Doing Build path->Configure Build path->order and export->Check Add private libraries->ok.
Then clean up the project.
Done a big problem solved.
I also got the same issue, and resolved it by the below way.
If because of some reason you have UNCHECKED to the private libraries from build path, so just add Androidv-4 jar in build path and enable(check) it in "Order and Export" tab
Remove anything lib about v7 or v4. Move your Android project, Alt+Enter, click android, look is lib: make sure there is nothing about v7 or v4 lib
add v4 lib
clean project
run again
if you remove v7, will be error with styles... you may look this