我想在我的过滤活动中添加自定义操作栏,这是一个PreferenceActivity。
我可以将addPreferencesFromResource()方法与ActionBarActivity ???
一起使用因为我的java文件和xml文件是正确的,所以一切正常。但是没有操作栏,当我试图调用 getActionBar()。setBackgroundDrawable(R.drawable.xyz); 时会发生崩溃。 请帮帮我。
这是我的偏好屏幕的
import android.graphics.drawable.Drawable;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Filter extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.filter_screen);
Drawable d=getResources().getDrawable(R.drawable.abfilter);
getActionBar().setBackgroundDrawable(d);
}
}
这里是logcat
11-22 16:18:13.377 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ Late-enabling CheckJNI
11-22 16:18:13.481 7460-7460/com.example.avinash.swipetab W/ActivityThread﹕ Application com.example.avinash.swipetab is waiting for the debugger on port 8100...
11-22 16:18:13.487 7460-7460/com.example.avinash.swipetab I/System.out﹕ Sending WAIT chunk
11-22 16:18:13.494 7460-7468/com.example.avinash.swipetab I/dalvikvm﹕ Debugger is active
11-22 16:18:13.687 7460-7460/com.example.avinash.swipetab I/System.out﹕ Debugger has connected
11-22 16:18:13.688 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:13.888 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:14.088 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:14.289 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:14.489 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:14.689 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:14.889 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:15.090 7460-7460/com.example.avinash.swipetab I/System.out﹕ waiting for debugger to settle...
11-22 16:18:15.290 7460-7460/com.example.avinash.swipetab I/System.out﹕ debugger has settled (1413)
11-22 16:18:15.713 7460-7460/com.example.avinash.swipetab I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
11-22 16:18:15.713 7460-7460/com.example.avinash.swipetab W/dalvikvm﹕ VFY: unable to resolve virtual method 11365: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
11-22 16:18:15.713 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
11-22 16:18:15.714 7460-7460/com.example.avinash.swipetab I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
11-22 16:18:15.714 7460-7460/com.example.avinash.swipetab W/dalvikvm﹕ VFY: unable to resolve virtual method 11371: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
11-22 16:18:15.714 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
11-22 16:18:15.716 7460-7460/com.example.avinash.swipetab I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
11-22 16:18:15.716 7460-7460/com.example.avinash.swipetab W/dalvikvm﹕ VFY: unable to resolve virtual method 9059: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
11-22 16:18:15.716 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
11-22 16:18:15.734 7460-7460/com.example.avinash.swipetab I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
11-22 16:18:15.734 7460-7460/com.example.avinash.swipetab W/dalvikvm﹕ VFY: unable to resolve virtual method 367: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
11-22 16:18:15.734 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
11-22 16:18:15.736 7460-7460/com.example.avinash.swipetab I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
11-22 16:18:15.736 7460-7460/com.example.avinash.swipetab W/dalvikvm﹕ VFY: unable to resolve virtual method 389: Landroid/content/res/TypedArray;.getType (I)I
11-22 16:18:15.736 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
11-22 16:18:15.886 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 177K, 10% free 3028K/3328K, paused 10ms, total 10ms
11-22 16:18:15.887 7460-7460/com.example.avinash.swipetab I/dalvikvm-heap﹕ Grow heap (frag case) to 3.681MB for 635812-byte allocation
11-22 16:18:15.900 7460-7473/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 8K, 8% free 3640K/3952K, paused 8ms, total 8ms
11-22 16:18:16.124 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 49K, 6% free 4040K/4272K, paused 10ms, total 10ms
11-22 16:18:16.155 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 323K, 13% free 3897K/4448K, paused 8ms, total 8ms
11-22 16:18:16.220 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 1K, 6% free 4220K/4448K, paused 9ms, total 9ms
11-22 16:18:16.256 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 318K, 12% free 4227K/4768K, paused 9ms, total 9ms
11-22 16:18:16.297 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 5% free 4550K/4768K, paused 9ms, total 9ms
11-22 16:18:16.375 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 1K, 4% free 4887K/5088K, paused 9ms, total 9ms
11-22 16:18:16.436 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 4% free 5217K/5408K, paused 9ms, total 9ms
11-22 16:18:16.584 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 1K, 3% free 5889K/6048K, paused 9ms, total 9ms
11-22 16:18:16.641 7460-7460/com.example.avinash.swipetab E/﹕ appName=com.example.avinash.swipetab, acAppName=/system/bin/surfaceflinger
11-22 16:18:16.641 7460-7460/com.example.avinash.swipetab E/﹕ 0
11-22 16:18:16.645 7460-7460/com.example.avinash.swipetab I/MaliEGL﹕ [Mali]window_type=1, is_framebuffer=0, errnum = 0
11-22 16:18:16.645 7460-7460/com.example.avinash.swipetab I/MaliEGL﹕ [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
11-22 16:18:16.645 7460-7460/com.example.avinash.swipetab I/MaliEGL﹕ [Mali]max_allowed_dequeued_buffers=3
11-22 16:18:16.649 7460-7460/com.example.avinash.swipetab D/OpenGLRenderer﹕ Enabling debug mode 0
11-22 16:18:17.386 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 173K, 5% free 6246K/6544K, paused 10ms, total 10ms
11-22 16:18:17.471 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 32K, 5% free 6989K/7312K, paused 9ms, total 9ms
11-22 16:18:17.572 7460-7460/com.example.avinash.swipetab I/Choreographer﹕ Skipped 94 frames! The application may be doing too much work on its main thread.
11-22 16:18:21.307 7460-7460/com.example.avinash.swipetab D/dalvikvm﹕ GC_FOR_ALLOC freed 94K, 3% free 8280K/8500K, paused 12ms, total 12ms
11-22 16:18:21.451 7460-7460/com.example.avinash.swipetab D/AndroidRuntime﹕ Shutting down VM
11-22 16:18:21.451 7460-7460/com.example.avinash.swipetab W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41541ba8)
11-22 16:18:21.467 7460-7460/com.example.avinash.swipetab E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.avinash.swipetab, PID: 7460
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.avinash.swipetab/com.example.avinash.swipetab.Filter}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.avinash.swipetab.Filter.onCreate(Filter.java:17)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
提前致谢。