DalvikError with my Function

筅森魡賤 提交于 2019-12-12 05:40:03

问题


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 flbut 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!