Error with R.drawable.icon; icon cannot be resolved or is not a field

The code of the generated code is configured: R.drawable. Please suggest a solution for the error:

R.drawable.icon: - the icon cannot be resolved or is not a field

The .java file containing this error is as follows:

package net.learn2develop.UsingNotifications; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; public class DisplayNotifications extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //---get the notification ID for the notification; // passed in by the MainActivity--- int notifID = getIntent().getExtras().getInt("NotifID"); //---PendingIntent to launch activity if the user selects // the notification--- Intent i = new Intent("net.learn2develop.AlarmDetails"); i.putExtra("NotifID", notifID); PendingIntent detailsIntent = PendingIntent.getActivity(this, 0, i, 0); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notif = new Notification( R.drawable.icon, "Time up!", System.currentTimeMillis()); CharSequence from = "AlarmManager - Time up!"; CharSequence message = "This is your alert, courtesy of the AlarmManager"; notif.setLatestEventInfo(this, from, message, detailsIntent); //---100ms delay, vibrate for 250ms, pause for 100 ms and // then vibrate for 500ms--- notif.vibrate = new long[] { 100, 250, 100, 500}; nm.notify(notifID, notif); //---destroy the activity--- finish(); } } 

The manifest file also indicates it:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.learn2develop.UsingNotifications" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.VIBRATE"></uses-permission> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".AlarmDetails" android:label="Details of the alarm"> <intent-filter> <action android:name="net.learn2develop.AlarmDetails" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name=".DisplayNotification" > <intent-filter> <action android:name="net.learn2develop.DisplayNotification" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest> 
+4
source share
2 answers

You should check if there is a file named R.java in the dir gen directory. If so open and check if there is an attribute named icon.

Perhaps you transferred your project or copied something from other projects. In any case, you can manually delete the file under Gen and let Eclipse recreate them. If not, you can go to the "Projects" section, and then "Clean" to select your project. It should work.

+1
source

I just thought I'd add a quick additional answer on this topic. I am very new to Android development and found that one of my classes did not compile because I could not find any of my available attributes. In the end, I tracked the problem to the point that the class imported android.R (automatically added to the Eclipse import list). Once this line has been output, the class is compiled.

+3
source

All Articles