1. Download our Official Android App: Forums for Android!

Apps R cannot be resolved

Discussion in 'Android Development' started by pramod.deore, Jan 11, 2010.

  1. pramod.deore

    pramod.deore Newbie
    Thread Starter
    35

    Jan 10, 2010
    22
    0
    35
    J2ME developer
    mumbai(India)
    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. */
    @Override
    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);
    myListView.setAdapter(aa);
    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());
    aa.notifyDataSetChanged();
    myEditText.setText("");
    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:eek:rientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <EditText
    android:id="@+id/myEditText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="New To Do Item"
    />

    <ListView
    android:id="@+id/myListView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
    </LinearLayout>

    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
     

    Advertisement

  2. pramod.deore

    pramod.deore Newbie
    Thread Starter
    35

    Jan 10, 2010
    22
    0
    35
    J2ME developer
    mumbai(India)
    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.

    Thanks
     
  3. momoceio

    momoceio Android Expert
    163

    Dec 14, 2009
    1,235
    149
    163
    Sr. Systems Administrator
    St. Louis
    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 Newbie
    Thread Starter
    35

    Jan 10, 2010
    22
    0
    35
    J2ME developer
    mumbai(India)
    I had called
    setContentView(R.layout.
    main);
    and I have res/layout/main.xml file.

     
  5. KeithG

    KeithG Well-Known Member
    46

    Nov 15, 2009
    103
    3
    46
    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 Lurker
    5

    Feb 12, 2010
    2
    0
    5
    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 Newbie
    15

    Feb 22, 2010
    18
    0
    15
    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 Lurker
    5

    Feb 12, 2010
    2
    0
    5
    I will try the thing which u have quoted......
     

Share This Page

Loading...