Eclipse Android SDK: Can't access layouts after adding 2nd activity - java

I'm very new to Android and Java developing. So far, everything worked pretty well. But i keep failing adding a 2nd activity and accessing its layout elements.
I used the manifest.xml wizard and file->new->other->android activity. This works well, adds a new java file and layout. Starting the activity works also pretty well.
My problem is that i can't access any elements of the new layout. When i try to create a button via "findViewById(R.id.?)" it shows elements that don't exist on the layout, but the elements on my layout are not shown. It seems that a layout from a previous project is used.
Additionaly the eclipse editor shows a warnining in a line above:
setContentView(R.layout.activity_secondactivity);
"activity_secondactivity cannot be resolved or is not a field".
This warning is not there until i type "R.id." and even if i delete it, it won't disappear.
In all tutorials on the web and youtube it seems to work so fine, i was trying different things for two days and can't figure it out. I would be very happy if anyone could help me out :)

Make sure you imported the right "R" (yourpackage.R) and not android.R. For example, if your package name is com.my.package, then you have to import com.my.package.R. And try clean your project (Project->Clean).

Related

Component.CENTER not working for Tablelayout (specifically using CODENAMEONE)

I've been struggling with this problem for awhile and can't seem to find an answer. In the demo code on the codename one website, to center an object, the code used is
horizontalAlign(Component.CENTER),
however, when I try to use this in IntelliJ, Component.CENTER isn't even an option. There IS something called CENTER_ALIGNMENT, but when I input that, I get an error message saying "float" cannot be input into a requirement of "int". Does anyone know what the code is to center objects in tablelayout in codenameone? I have already checked and updated all my software.
You need to import the class Component from Codename One specifically using the statement:
import com.codename1.ui.Component;
If this doesn't work it means the current project isn't a Codename One project so make sure you created a Codename One project using the new project wizard.

Android Studio, creating any new activity now defaults to nothing and does not create a content.xml

I am a noob to Android Studio, I started a project and everything was going fine. Any time I created a new activity I would have a default screen with a toolbar at the top and an email icon.
Later, and I have no idea what caused this change, any time I created a new activity everything would be completely empty (see image below) with any type of new screen that I would create. Not only that, but Android Studio no longer would create the default content.xml, but only the activity.xml which everything would be edited in.
This would not be a problem normally, I just edited everything in the activity.xml for any new screen that I would make. This works fine for any test phone (avd). However, when I try it on a real phone none of the new screens work and causes the app to crash. I fear this may be because it doesn't follow the earlier default layout of having both content.xml and activity.xml. I tried to create the content.xml for any of the new screens, but I got a rendering error.
My question basically asks is there anything I can do apart from starting over?
How do I change back to the default for creating new activities?
Is there an easy way to copy code in case I need to start over?
(I'VE TRIED BOTH NEW BLANK AND NEW EMPTY, BOTH DON'T WORK YET WORKED EARLIER)
Image

Why is there a loading spinner in my action bar and how do I remove it?

Basically I'm pretty new to android development but so far I've been able to fix every issue/bug I've had except this one (I've seen way worse, but for some reason this little bug takes all my time..).
Just for contact, I'm doing an application that loads local and external xml file and displays the content, fetch xml files from a server and save them locally, etc.
The issue I'm running into is the following; on older android phones (on 4.4 there is no issue, on 4.0 there is) when the application loads, I have a loading spinner icon in my action bar while the only place I use one is in another layout that is not referenced in my main activity. I figured maybe it's because I didn't initiate my menu correctly or something, but everything seems fine (and works on newer versions). I have a searchview that is working fine, a settings menu that is also fine, but for some reason there is always a spinning icon next to those elements.
I can edit this and add my layout/code if needed.
Thanks!
maybe put setProgressBarIndeterminateVisibility(false) in Activitys onCreate (check docs)

Eclipse .XML files not showing ANY text

The past couple of days I've been having problems with Eclipse, such as appcompact_v7 making a new compact after each problem. Then App_compact wouldn't transfer the .jar files over automatically. NOW I'm having another problem, which is everytime I start a new Android Application Project the textView that says "Hello World!" is "invisible". It says it's on the layout, but it's not visible. Next problem i'm having is that anytime I add a button, TextView, or anything that has text, it's not visible, no matter what color I use with the text. 1. What is causing eclipse to do this? 2. What can I do to resolve these problems?
We're working on a final project for the class and this determines whether or not i pass the class, so i'm FREAKING out. Here is what my project looks like and what its showing :
Please change the theme on top it AppTheme by default. Try using any Holo.Light themes and see if it makes any difference.
I had this problem on last week.
Solution: update your Android SDK and check updates in Eclipse. If it's not work try backup projects and reinstall Android SDK.
Recommend: check locations of files in Android SDK. Google replace SDK files to another location. If it's true, replace files back.
P.S. I have got very bad English. Write comment if it's work. :)

Official tutorial codes appearing red wave line in Eclipse not allowing me to compile

I am a beginner in Android programming. I was going through the official tutorial on Android developer site. When I copied the codes for the Grid View tutorial to Eclipse, many red wave underlines appeared which are not allowing me to compile. Every time I click the run button, it says "Your project contains error(s), please fix them before running your application."
I am using a WIN7 and followed every single step that is necessary for setting up the envrionment. I had no problem at with previous tutorials such as Hello Android, Linear Layout, Relative Layout, and Table View.
Does anyone have the same experience and have a solution for this? I have tried to clean and re-build the project, which doesn't help.
It would probably be helpful to provide a link to the gridview tutorial you speak of. I'll assume you meant this one: http://developer.android.com/resources/tutorials/views/hello-gridview.html
First things first: Did you download the sample art? Did you put it in res/drawable?
What errors were you getting?
Are you certain you are working in an Android project and not a standard Java project?

Categories

Resources