问题
I wrote a function to set the background of a view depending on the android version:
package com.pthuermer.juraquiz;
import android.graphics.drawable.Drawable;
import android.view.View;
public class SupportFunctions {
@SuppressWarnings("deprecation")
public static void setViewBackgroundWithDrawable(View v, Drawable drawable) {
if(android.os.Build.VERSION.SDK_INT < 16) {
v.setBackgroundDrawable(drawable);
}
else {
v.setBackground(drawable);
}
}
}
This is how I call it:
FrameLayout fl = (FrameLayout)findViewById(R.id.container);
Drawable drawable = getResources().getDrawable(R.drawable.quiz_app_background);
SupportFunctions.setViewBackgroundWithDrawable(fl, drawable);
TextView tv = (TextView)findViewById(R.id.tv_heading_app_launch);
Drawable drw = getResources().getDrawable(R.drawable.quiz_heading_background);
SupportFunctions.setViewBackgroundWithDrawable(tv, drw);
It works for fl
but not for tv
it breaks down with these errors:
Pick [Android Application]
Pick [Android Application]
Pick [Android Application]
Pick [Android Application]
Pick [Android Application]
DalvikVM [localhost:8600]
Pick [Android Application]
DalvikVM [localhost:8600]
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2295
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2349
ActivityThread.access$700(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 159
ActivityThread$H.handleMessage(Message) line: 1316
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5419
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 525
ZygoteInit$MethodAndArgsCaller.run() line: 1187
ZygoteInit.main(String[]) line: 1003
NativeStart.main(String[]) line: not available [native method]
Thread [<10> Binder_2] (Running)
Thread [<9> Binder_1] (Running)
来源:https://stackoverflow.com/questions/22489054/dalvikerror-with-my-function