Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old January 10th, 2010, 11:35 PM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2010
Location: mumbai(India)
Posts: 22
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default 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"
androidrientation="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

Advertisements
pramod.deore is offline  
Reply With Quote
sponsored links
Old January 11th, 2010, 12:14 AM   #2 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2010
Location: mumbai(India)
Posts: 22
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
pramod.deore is offline  
Reply With Quote
Old January 11th, 2010, 08:36 AM   #3 (permalink)
Senior Member
 
momoceio's Avatar
 
Join Date: Dec 2009
Location: St. Louis
Posts: 1,235
 
Device(s): EVO 3d
Carrier: Not Provided

Thanks: 106
Thanked 151 Times in 95 Posts
Default

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)
momoceio is offline  
Last edited by momoceio; January 11th, 2010 at 08:45 AM.
Reply With Quote
Old January 11th, 2010, 08:51 PM   #4 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2010
Location: mumbai(India)
Posts: 22
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had called
setContentView(R.layout.
main);
and I have res/layout/main.xml file.

pramod.deore is offline  
Reply With Quote
Old January 12th, 2010, 10:06 AM   #5 (permalink)
Member
 
Join Date: Nov 2009
Posts: 103
 
Device(s): Droid
Carrier: Not Provided

Thanks: 0
Thanked 4 Times in 4 Posts
Default

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.
KeithG is offline  
Reply With Quote
Old February 12th, 2010, 11:12 PM   #6 (permalink)
New Member
 
Join Date: Feb 2010
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.....
parthiban is offline  
Reply With Quote
Old February 22nd, 2010, 08:39 AM   #7 (permalink)
Junior Member
 
Join Date: Feb 2010
Posts: 18
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 :|
LeonR is offline  
Reply With Quote
Old March 2nd, 2010, 01:31 AM   #8 (permalink)
New Member
 
Join Date: Feb 2010
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default thanks for ur valuable reply LeonR,

I will try the thing which u have quoted......
parthiban is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:56 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.