• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps R cannot be resolved

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:orientation="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
 
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
 
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)
 
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.
 
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.....
 
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 :|
 
Back
Top Bottom