R cannot be resolved

Last Updated:

  1. pramod.deore

    pramod.deore Member

    Hello everybody,
    I am trying to run my first program in android but I got error.

    I havae following code in my .java file

    package com.micro;

    import java.util.ArrayList;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.view.View.OnKeyListener;
    import android.widget.ArrayAdapter;
    import android.widget.EditText;
    import android.widget.ListView;

    public class ToDoList1 extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle icicle)
    setContentView(R.layout.main); //error
    ListView myListView = (ListView)findViewById(R.id.myListView); //error
    final EditText myEditText = (EditText)findViewById(R.id.myEditText); //error
    final ArrayList<String> todoItems = new ArrayList<String>();
    final ArrayAdapter<String> aa;
    aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,todoItems);
    myEditText.setOnKeyListener(new OnKeyListener()
    public boolean onKey(View v, int keyCode, KeyEvent event)
    if (event.getAction() == KeyEvent.ACTION_DOWN)
    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
    todoItems.add(0, myEditText.getText().toString());
    return true;
    return false;

    and following in my main.xml file

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:text="New To Do Item"


    But when I tried to run the program I got 3 error as "R can not be resolved" at shown above.

    I had to find out solution for this but my problem is not solved. Some forum says make another program and run it. I tried it for 3 times but every time I got same error as "R can not be resolved". Please help me.

    Thank you

  2. pramod.deore

    pramod.deore Member

    Hello everybody

    I don't know how but erros are now solved but now on emulator following error is generated as
    "The application NewApp(process com.micro) has stopped unexpectedly. Please try again".
    and "Force clode" button is displayed.

  3. momoceio

    momoceio Well-Known Member

    Does /res/layout/main.xml exist? The statement setContentView(R.layout.main) calls the main.xml in that location. The .xml file can be named anything...but make sure you are calling it by the correct name. For example if you have /res/layout/my_layout.xml, you would call (R.layout.my_layout)
  4. pramod.deore

    pramod.deore Member

    I had called
    and I have res/layout/main.xml file.

  5. KeithG

    KeithG Well-Known Member

    under the "gen" directory, whats the package name? is it com.micro?

    Also open the gen/<packagename>/R.java file

    does the layout class exist within the R class? does the layout class have a field called main?

    If the package names from your activity class and R class differ, the R is not within the namespace and must be imported. This shouldn't happen unless you created a different package in the src directory.
  6. parthiban

    parthiban New Member

    hi everyone,
    I downloaded the android open source code from this android website Welcome (Android Open Source Project) and i started using contact application in eclipse... When i build the package it mainly causing these two errors com.android.internal.R cannot be resolved and Intent.ACTION_CALL_PRIVILEGED cannot be resolved... I don't know how to fix these errors...
    Plz someone help me on this.....
  7. LeonR

    LeonR Member

    I had the R cannot be resolved problem, it turned out it was the naming of my projects I think, at least from what I can tell!

    I removed all dots (.) from my names, apart from the package, which I use com.appname , then it just worked :|
  8. parthiban

    parthiban New Member

    I will try the thing which u have quoted......

Share This Page