Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

android R cannot be resolved to a variable error

anroid

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 game2d

game2d

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 11 June 2013 - 06:52 PM

error on lines:
setContentView(R.layout.activity_main);

getMenuInflater().inflate(R.menu.activity_main, menu);

 

error: -----  R cannot be resolved to a variable

 

 

 
package com.example.android_01;




import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;


public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

note i also tried importing:

import com.example.android_01.R;

but didnt worked.

 

 

 

 

 

i than try adding:

import android.R;

but than i got another error:" activity_main cannot be resolved or is not a field" on line:

 

setContentView(R.layout.activity_main);

 

 

 



#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 12 June 2013 - 01:15 AM

Did you declare: layout.activity_main in android manifest.xml?

 

did you create the xml with the .menu.activity_main?

 

I think the error lies in there, you are missing some declaration.



#3 kevinvwallace

kevinvwallace

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 14 June 2013 - 01:23 AM

You have to declare layout.activity in manifiest.xml file, and create .xml file in activity_main. I think there is missing some declaration, check it first.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download