Error in MainAcitivity.java file & no style are loading - android

I am new to android. I am creating an android application, but there are many errors showing in MainActivity.java. Here is a screenshot
Another problem is that no style in showing in activity_main.xml. Here is the screenshot
Although I have added appcompact_v7 jar file like this
But it's not recognizing it in android option of project propertise
I have installed Support library in SDK manager. Please tell me how to solve this problem?

It is really hard to say what is wrong there. here are some things that you should try:
first of all, there are errors in your xml file (activity_xml). Please check if xml is properly formatted and you are using right tags. For debugging purpose, please make your acitivity_xml an empty FrameLayout and see if it works.
Include android 6.0 into your build path. Clean the project and try building again. Make sure your layouts are error free before doing that.
Your eclipse is unable to detect referenced library at given location. Please make sure referenced library is at same place and ERROR-FREE. If library has error, your project won't include it.
Please solve all problems one by one. First make an error free xml, then a Hello world Activity. Run it on device or emulator. Once done, try to solve library and import problem now.
Best Suggestion: Please migrate to Android Studio and gradle for better support and learning.

Related

Need to embed one android project into another android project

I have two android projects with me. I need to add the first project as a library to the other project.
Now, when I am trying to open the activity of library project from the other application on a button click, i am getting Android.content.ActivityNotFoundException at run time.
Can anyone suggest some pointer on this.
you need to check that you added the new activity to the manifest.xml file
if you are Using ADT(Android Developer Tool).
Thanks for the concern. This issue is resolved for me. Sorry for the late reply. I have created the second application as library project, which is included in first android project.
The point, which fixed the issue is: add the contents of the manifest.xml of library project in main project and the reference provided is the full path for the activity(including package name).

Adding google maps library to existing project creates confusing error

I am building an Android app that I want to open google maps with the click of a button. I want the app to find the current location of the user and give them directions to a predefined address. I started building the application before I realized there were special steps that you have to take to include this functionality. To add this feature to my project I followed the directions on these two sites:
https://developer.android.com/google/play-services/setup.html
https://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject
The problem is on the second site, when i added the library to my already existing project it caused all of my code that has findViewById(R.id.whatever) or setContentView(R.layout.whatever) to become errors. It is now telling me that i need to import the class R. If I do that it then gives me error messages on the names of all my xml files.
For example in my MainActivity it is telling me that i should change setContentView(R.layout.activity_main) to setContentView(R.layout.activity_list_item) and does this for all references to my xml files for the entire project.
I tried going back and removing the google play services library from the project and starting over but when I removed it the errors still persists. I also tried using the "fix project setup" option in Eclipse but it didn't fix the problem.
I'm wondering if anyone here has experienced this problem before? If so, how can I fix it? The application had no errors before I tried to include the google play services library. I am new to Android development so a lot of the information I have found has been either confusing to understand or doesn't seem to include enough details for me to figure it out. Thanks for your help!
Look at your imports, and check if you are importing the correct R.java from your application package, not from the android package.
Check also if your XMLs don't contain errors, otherwise R.java won't be generated.
In my case android-maps-library had to errors in two files (I have forgotten their names), I edited the two files removing errors my self. And finally I was able to used it quite nice.
i think you have correct yout Project build target, and this how:
right click on your project folder in the package explorer->propreties->Android
then porject build target and choose you Android target (Android x.xx)
but before that you need to remove import android.R;

Importing and using a library in android studio

I am using android studio to import this project called https://github.com/Pixate/pixate-freestyle-android. However when I import it into android studio the folder under samples, freestyleshowcase doesnt seem to build. The other 2 samples buld correctly. There is a red circle around the java file with a J (error) but there is no error in the file itself. COuld someone please help me out?
You are obviously missing some libraries but it is going to be hard for anyone to tell you which since we do not know the libraries the project needs.You can try Build-->Rebuild Project or Build-->Clean Peoject if it still doesn't work, close and open Android Studio.
If that doesn't work also then you have to go the hard way of identifying the libraries need by the project samples you imported and see if you have them.
When in doubt, you can try the Library Dependency option (using Maven) as demonstrated here:
https://www.youtube.com/watch?v=6BUcx9gGQ3o
That way, you won't have to manually edit the build.gradle file.

java.lang.NoClassDefFoundError with external jars in Android project

I've been searching the internet for two days now, and I feel like I've tried everything.
Please let me know if any code snippets might be helpful in finding a solution.
I've created an android application with the standard login activity. In the doInBackground()-method, I invoke a static method from another external class. Since this method will be invoked once the submit button is clicked, the error occurs during runtime. The class is included in my file, and there are no compilation errors. Whenever I tap/click on the Submit-button, I get a java.lang.NoClassDefFoundError referring to a class (in my external jar) that is used and properly included in my external file I refer to in the doInBackground()-method.
All my external libraries are in the 'libs'-folder. I've tried adding them to the build path manually instead and checking the boxes next to them in the 'order and export'-tab instead of the checkbox next to the 'Android Private Libraries' entry. I've tried putting the 'gen'-directory above the 'src'-directory, which didn't change anything either. Restarting eclipse, reimporting the project as a whole, playing around with the order of the external libraries in the build path, fixing project properties and cleaning the project over and over, nothing helped. I've checked this
http://javarevisited.blogspot.de/2011/06/noclassdeffounderror-exception-in.html
and tried every solution, but none of them worked for me. I ad a similar problem with a library before, and I could solve it by changing some build path settings and restarting Eclipse. However, this just doesn't work for me any more. I hope anybody has another solution or an idea, I have no clue what's wrong...
Thank you all in advance!
Yeehaw
Edit:
Despite creating a whole new project and adding my previous files to this new project, I still had the same problem in the new project. I think I figured out where this error came from: When I added my external library, I still had dependencies from the just added .jar to other jars. After adding those as well, the compiler said I needed the java.rmi.Remote class, which is in Java's JRE system library (rt.jar). Adding the whole jre library to my project made the compiler error disappear, the runtime error, however, still persisted.
After some more research I found out that my external library is probably not compatible with the android runtime environment, which means that the jar's .class-files don't have an equivalent .dex-representation which is neededfor the Dalvik virtualmachine on android powered devices. For many java jar's, especially those designed for use with the android platform, those problems don't occur.
Please correct me if I'm wrong, but this explanation seemed pretty plausible to me. Too bad, since this is the only way to currently access our database programmatically.
Make sure you've updated to the latest version of ADT Eclipse plugin and SDK Tools and also make sure "Android Dependencies" is checked in your project properties.

Unable to reference a Library project - Android

Well, I wanted to create a Library project from my existing sources so that it would help me re-use code for the paid app that I have in mind. When I saw the developer guide on how this was to be done, I thought it was very simple.
Just mark the project as a Library project and it should be converted to one.
But when I tried referencing one of the base classes in an application, the app force closes with the following exceptions
02-04 21:50:06.765: E/AndroidRuntime(699): java.lang.NoClassDefFoundError: in.my.package.name.R$layout
Let me give you some more info. I have referenced the Library project in the application and have also included the manifest entries with fully qualified activity names. I have a BaseActivity which has all the menu and re-usable code bits. The point where the above exception occurs is where I am trying to reference the layout file in this BaseActivity inside the library project.
setContentView(R.layout.apphome);
What is it that I am missing or doing wrongly?
PS: I am just noticing that When I right click on my application and go to the android tab, there is a red cross instead of a green tick in the place where the library project is referenced. But there are no visible errors on the console or in the code of the project.
Seems its a known issue.
Issue link here
Hope Google guys resolve this problem in their next SDK release.
So to be clear, the problem was that my libraries had custom styling capabilities and that was the problem.

Categories

Resources