Reputation: 23
I'm following the android basic tutorial and have been stuck on this one most of the day. I have highlighted the error line with '//'. I've tried all sorts of import lines .. previous searches seem to say it's an import defining type error.
package com.example.myapp3;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
public class DisplayMessageActivity extends Activity {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_display_message);
setContentView(R.layout.activity_display_message);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.`enter code here`
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
Upvotes: 2
Views: 5765
Reputation: 121
I had this exact problem and I couldn't find the answer anywhere on stackoverflow. I tried cleaning, rebuilding etc. The help tip insisted that I should create the file but when I accepted the suggestion it said the file already existed. What ultimately fixed it for me was just restarting the IDE.
Upvotes: 2
Reputation: 41
Check your Manifest.xml. Make sure that the activity is referenced there along with the package name where it is been defined.
Upvotes: 0
Reputation: 1
My problem was: after creating the activity_display_message in my xml file, I didn't save the changes. After hours of research, I saved the file and my problem is gone! Hope this helps!
Upvotes: -1
Reputation: 1672
If you see import android.R; in the imports , remove that as well. it resolved my compilation error.
Upvotes: 0
Reputation: 1619
Even though this line: setContentView(R.layout.activity_display_message); Had and error message underlining the text "activity_display_message", it still ran for me.
But I hated seeing the underline telling me there was something wrong.
After a bit of searching and trial and error I realized that the problem was that the auto generated file "activity_display_message.xml" was missing the proper xml first line.
<?xml version="1.0" encoding="utf-8"?>
Once I added that as the first line in the "activity_display_message.xml" file the error underline went away.
Upvotes: 0
Reputation: 1194
With which IDE are you working?
For Eclipse, you need to import R file generated for the project automatically if your project does not contain any error. The R file generated contains reference to your resources that you will be creating.
So make sure
Upvotes: 0
Reputation: 21805
According to the guide you are following..it states
Note: If you are using an IDE other than Eclipse, your project does not contain the activity_display_message layout that's requested by setContentView(). That's OK because you will update this method later and won't be using that layout.
So just follow along.. your code will be updated.
On other note
setContentView(R.layout.activity_display_message);
here you are trying to set the view of your activity... and referencing the layout which does not exist.. if you will create a xml named activity_display_message.xml
inside res->layout folder of your project.. error will resolve.
Upvotes: 4
Reputation: 5085
When you build an Android application, a file named R.java is created that contains identifiers for all of your resources. If the file R.java does not exist or does not contain an identifier for your layout, I can think of at least 4 possible reasons.
In the case of number 4, try doing a "Clean"
Upvotes: 0