我正在尝试为相对布局设置背景图像,但这里发生了一些错误是我的代码提前感谢
relative_topheader = new RelativeLayout(this);
relative_topheader.setId(1);
RelativeLayout.LayoutParams lp_topheader = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
Resources resources_topheader = getResources();
Drawable drawable_topheader = resources_topheader.getDrawable(R.drawable.headerbar_m);
relative_topheader.setBackground(drawable_topheader);
setContentView(1);
我的原木猫:
05-21 11:40:05.655: I/dalvikvm(510): Could not find method android.widget.RelativeLayout.setBackground, referenced from method com.example.metromatineeapplicationlayer.MainActivity.onCreate
05-21 11:40:05.698: W/dalvikvm(510): VFY: unable to resolve virtual method 3324: Landroid/widget/RelativeLayout;.setBackground (Landroid/graphics/drawable/Drawable;)V
05-21 11:40:05.698: D/dalvikvm(510): VFY: replacing opcode 0x6e at 0x0052
05-21 11:40:05.788: D/AndroidRuntime(510): Shutting down VM
05-21 11:40:05.788: W/dalvikvm(510): threadid=1: thread exiting with uncaught exception (group=0x40014760)
05-21 11:40:05.795: E/AndroidRuntime(510): FATAL EXCEPTION: main
05-21 11:40:05.795: E/AndroidRuntime(510): java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground
05-21 11:40:05.795: E/AndroidRuntime(510): at com.example.metromatineeapplicationlayer.MainActivity.onCreate(MainActivity.java:60)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.os.Looper.loop(Looper.java:132)
05-21 11:40:05.795: E/AndroidRuntime(510): at android.app.ActivityThread.main(ActivityThread.java:4025)
05-21 11:40:05.795: E/AndroidRuntime(510): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 11:40:05.795: E/AndroidRuntime(510): at java.lang.reflect.Method.invoke(Method.java:491)
05-21 11:40:05.795: E/AndroidRuntime(510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-21 11:40:05.795: E/AndroidRuntime(510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-21 11:42:44.945: E/AndroidRuntime(546): FATAL EXCEPTION: main
05-21 11:42:44.945: E/AndroidRuntime(546): java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground
05-21 11:42:44.945: E/AndroidRuntime(546): at com.example.metromatineeapplicationlayer.MainActivity.onCreate(MainActivity.java:60)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.os.Looper.loop(Looper.java:132)
05-21 11:42:44.945: E/AndroidRuntime(546): at android.app.ActivityThread.main(ActivityThread.java:4025)
05-21 11:42:44.945: E/AndroidRuntime(546): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 11:42:44.945: E/AndroidRuntime(546): at java.lang.reflect.Method.invoke(Method.java:491)
05-21 11:42:44.945: E/AndroidRuntime(546): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-21 11:42:44.945: E/AndroidRuntime(546): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-21 11:42:44.945: E/AndroidRuntime(546): at dalvik.system.NativeStart.main(Native Method)