Fixed: R cannot be resolved to a variable

I encountered this problem when I was making a new project on my eclipse workspace. I got a red underline on “R” in this part of my code

setContentView(R.layout.main);

So here’s what I did to fix this issue. Go to Project Properties > Java Build Path > Tick Android Version Checkbox

rcannotberesoved
Then if your workspace does not build automatically…

Properties again > Build Project

buildproj
After that, all went back to normal. :)
Thanks for reading this Fixed: R cannot be resolved to a variable!

Android Fix: Eclipse is loading framework information and the layout library from the SDK folder. main.xml will refresh automatically once the process is finished.

After doing some android coding, I’m supposedly doing some improvement on its user interface. But when I viewed the graphic layout of my main.xml, the black screen did not show up, instead, a message prompted me:

Eclipse is loading framework information and the layout library from the SDK folder. main.xml will refresh automatically once the process is finished.

Android Fix: Eclipse is loading framework information and the layout library from the SDK folder. main.xml will refresh automatically once the process is finished.

Oh no!

I searched google but none of the solutions worked for me. Then I decided to reinstall the Android SDK. I removed it from my control panel and run the android-sdk installer I have (installer_r10-windows.exe). And that solves my problem. I hope this helps someone. :)

Android Hello World App Tutorial – Your Step by Step Guide

I had a previous post “Getting Started with Google Android Development“ where we installed our development environment. Please refer to that first if you’re not yet done with it. In this post, we are going to do a program that will simply put a “Hello Android!” text on the screen of our android device. This is just a simple “Hello World!” program – just an Android version. Haha!

Home>Android Android Hello World App Tutorial – Your Step by Step Guide

Hello there! :)

Step 1: We have to Install at least one Android platform for it is required to run an android application. To do that, we have to follow the simple steps on this link: Installing an Android platform

Step 2: From eclipse, select File > New > Project (Not Java Project). New project wizard will pop up. On the list, select Android Folder > Android Project > Next

Step 3: You are now in the New Android Project Dialog Box. Supply the following:

  1. Project Name: HelloAndroid.
  2.           This is the name of the directory that will contain the project files

  3. Application Name: Hello Android App
  4.           This is the name that will appear on the Android device

  5. Package Name: com.example.helloandroid
  6.           This is the package namespace that you want all your source code to reside under. It must be unique across all packages installed on the Android system

  7. Create Activity: HelloAndroid
  8.           This is the name for the class stub that will be generated by the plugin

  9. Min SDK Version: 4
  10.           This value specifies the minimum API Level required by your application. Since I am using Android 1.6 platform for now, we’ll enter “4″.

Step 4: Click Finish

You may now browse HelloAndroid.java and see the code by double clicking it.

helloandroid

Step 5: Browse the code. Inside HelloWorld.java file is the auto generated code:

package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Change that to these codes. The highlighted codes were added. tv.setText(“Hello, Android”); Displays the text to the application’s UI.

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}

Step 6: Run the application.

To run the application, for now, we will export it as .apk file. APK file is used for distributing and installing bundled components onto the Android operating system.

exportandroid

After clicking export, an export dialog box will appear, we have to choose Android Folder > Export Android Application > Next > Project: HelloAndroid > Next Button

We are now in the Keystore selection dialog, since this is our first application we have to select Create new keystore radio button. For now, we will supply the following information in the form

Location: C:JM_FILESJAVAKEYSHelloAndroidKey
Password: asdfasdf
Confirm: asdfasdf

Then Click the Next Button to proceed with the Key Creation. We’re gonna supply the following information:

Alias: HelloAndroidAlias
Password: asdfasdf
Confirm: asdfasdf
Validity: 25
First and Last Name: Your Name
Organizational Unit: IT
Organization: IT Org
City or Locality: Antipolo
State or Province: Rizal
Country Code (XX): 18700

Then Click the Next Button

For the destination of APK file, we’ll have: C:JM_FILESJAVAAPKHelloAndroid.apk

Hit the Finish Button

We will now copy the HelloAndroid.apk file to our Android device > Click to install.

You should see “Hello Android!” text when you run the application so you know that our exercise works!

If you’re gonna proceed with total android applications development, you must use the Android Debug Bridge. It will save you a lot of time in debugging. To use that, I got the following useful resources:

http://developer.android.com/guide/developing/tools/adb.html
http://www.youtube.com/watch?v=BKW9xUPJMEM
http://www.androidtablets.net/forum/android-tablet-hacking/426-resource-how-use-adb-android-debug-bridge.html

Other resources:
http://developer.android.com/resources/tutorials/hello-world.html
http://simple.wikipedia.org/wiki/Hello_world_program
That’s it! I hope I helped you with your first android application. :)