android - R.drawable.icon 错误;图标无法解析或不是字段

标签 android

自动生成的代码部分出现错误:R.drawable。请建议错误的解决方案:

R.drawable.icon :- 图标无法解析或不是字段

出现此错误的 .java 文件如下所示:

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's up!",
            System.currentTimeMillis());

        CharSequence from = "AlarmManager - Time's 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();
    }
}

list 文件也表明了这一点:

<?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>

最佳答案

我只是想为这个主题添加一个快速的附加答案。我是 Android 开发的新手,发现我的一个类没有编译,因为它找不到我的任何可绘制属性。最后,我将问题归结为该类正在导入 android.R(由 Eclipse 自动添加到导入列表)。该行一被删除,该类就编译了。

关于android - R.drawable.icon 错误;图标无法解析或不是字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11747272/

相关文章:

java - OkHttp 回调吞噬异常 - 设计缺陷或常见做法

javascript - HTML5 Canvas ,防手掌误触

android - Handler是否同时执行Runnable

android - android初学者有必要使用android中的MVVM模式或架构组件吗?

java - 添加自定义控件作为标记 OSMDROID BONUS PACK

android - 如何填充 Canvas 中两个圆圈之间的区域?

android - ListView 滚动错误

android - 在android中的 ImageView 中显示矩阵

java - 相对布局中的 ViewPager 消耗完整高度(选项卡)

android - 在 Android API <21 中使用 Job Scheduler