2013-02-03 59 views
1

我想創建一個應用程序,該應用程序將記錄應用程序的所有通知。我正在創建按鈕,但即時獲取「無法解析或不是字段」無法解析或不是字段

這是activity_get_notification.xml

<Button 
    android:id="@+id/OKButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="116dp" 
    android:text="@string/ok" /> 

,這是java代碼

import android.app.Activity; 

import android.content.Intent; 
import android.os.Bundle; 
import android.widget.Button; 
import com.example.notificationnotifier.R; 

public class GetNotification extends Activity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_get_notification); 

    Button OKButton = (Button) findViewById(R.id.OKButton); 
    Intent getNotification = new Intent("com.example.notificationnotifier.monitorNotification"); 
    startActivity(getNotification); 
} 

而且我androidmanifest是

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.notificationnotifier" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="16" 
     android:targetSdkVersion="16" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.notificationnotifier.GetNotification" 
      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="com.example.notificationnotifier.monitorNotification" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.DEFAULT" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 
</manifest> 

,這是錯誤消息

[2013-02-04 01:18:52 - NotificationNotifier] W/ResourceType(7432): Bad XML block: header size 60 or total size 0 is larger than data size 0 
[2013-02-04 01:18:52 - NotificationNotifier] C:\Users\Trend\workspace\NotificationNotifier\res\layout\activity_get_notification.xml:7: error: Error: No resource found that matches the given name (at 'text' with value '@string/ok'). 
[2013-02-04 01:18:52 - NotificationNotifier] C:\Users\Trend\workspace\NotificationNotifier\res\menu\activity_get_notification.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/menu_settings'). 
[2013-02-04 01:20:23 - NotificationNotifier] W/ResourceType(6764): Bad XML block: header size 85 or total size 0 is larger than data size 0 
[2013-02-04 01:20:23 - NotificationNotifier] C:\Users\Trend\workspace\NotificationNotifier\res\layout\activity_get_notification.xml:7: error: Error: No resource found that matches the given name (at 'text' with value '@string/ok'). 
[2013-02-04 01:20:23 - NotificationNotifier] C:\Users\Trend\workspace\NotificationNotifier\res\menu\activity_get_notification.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/menu_settings'). 
[2013-02-04 01:24:18 - NotificationNotifier] W/ResourceType(5092): Bad XML block: header size 147 or total size 0 is larger than data size 0 
[2013-02-04 01:24:18 - NotificationNotifier] C:\Users\Trend\workspace\NotificationNotifier\res\layout\activity_get_notification.xml:7: error: Error: No resource found that matches the given name (at 'text' with value '@string/ok'). 
[2013-02-04 01:24:18 - NotificationNotifier] C:\Users\Trend\workspace\NotificationNotifier\res\menu\activity_get_notification.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/menu_settings'). 
+0

你在哪裏得到那個錯誤? – Abubakkar

+0

請提供完整的logcat – StarsSky

+0

新的意圖(「com.example.notificationnotifier」);是你的包,而不是一個活動 – StarsSky

回答

0

在日誌中:

沒有資源發現,給定名稱(在 '文本',值爲 '@字符串/ OK')相匹配。

意味着你忘了在res/values/strings.xml文件中添加okmenu_settings字符串。將其添加爲:

<resources> 
    <string name="ok">ok button</string> 
    <string name="menu_settings">menu settings</string> 
</resources> 
+0

加入menu_settings解決了這個問題。我只是想知道爲什麼它一直把責任推給OKButton。無論如何,謝謝! :D –

+0

@srhsnl:最受歡迎的朋友。有可能你這些刺會有一些關係 –