本人新手,遇到疯狂android书上的一个例子,按照书上输入到eclipse中编译没有报错,点击发送按钮消息发送正常,但是在下拉菜单中点击消息不能跳转到OtherActivity,logcat提示错误java.lang.RuntimeException:Unable to start activityComponentInfo{com.example.notificationtest/com.example.notification.OtherActivity}:android.view.inflateException:Binaty XML file line#6:Error inflating class<unknow>,检查了好几遍AndroidManifest、Activity布局资源配置都没有发现问题,求指点谢谢,代码如下
NotificationTest.java:
package com.example.notificationtest;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class NotificationTest extends Activity {
static final int NOTIFICATION_ID=0x123;
NotificationManager nm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
public void send(View v){
Intent intent=new Intent(NotificationTest.this,OtherActivity.class);
PendingIntent pi=PendingIntent.getActivity(NotificationTest.this, 0, intent, 0);
Notification notify=new Notification.Builder(this).setAutoCancel(true).setTicker("新消息").setSmallIcon(R.drawable.notify)
.setContentTitle("一条新通知").setContentText("恭喜你加薪了,工资增加20%!").setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis()).setContentIntent(pi).build();
nm.notify(NOTIFICATION_ID, notify);
}
public void del(View v){
nm.cancel(NOTIFICATION_ID);
}
}
OtherActivity.java:
package com.example.notificationtest;
import android.app.Activity;
import android.os.Bundle;
public class OtherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.notificationtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.notificationtest.NotificationTest"
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=".OtherActivity"
android:label="@string/other_activity" >
</activity>
</application>
</manifest>
NotificationTest.java:
package com.example.notificationtest;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class NotificationTest extends Activity {
static final int NOTIFICATION_ID=0x123;
NotificationManager nm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
public void send(View v){
Intent intent=new Intent(NotificationTest.this,OtherActivity.class);
PendingIntent pi=PendingIntent.getActivity(NotificationTest.this, 0, intent, 0);
Notification notify=new Notification.Builder(this).setAutoCancel(true).setTicker("新消息").setSmallIcon(R.drawable.notify)
.setContentTitle("一条新通知").setContentText("恭喜你加薪了,工资增加20%!").setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis()).setContentIntent(pi).build();
nm.notify(NOTIFICATION_ID, notify);
}
public void del(View v){
nm.cancel(NOTIFICATION_ID);
}
}
OtherActivity.java:
package com.example.notificationtest;
import android.app.Activity;
import android.os.Bundle;
public class OtherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.notificationtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.notificationtest.NotificationTest"
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=".OtherActivity"
android:label="@string/other_activity" >
</activity>
</application>
</manifest>