Android-imageView.getDrawable ()이 null을 반환합니다.

user1841702

나는이 겉보기에 쉬운 문제에 갇혀있다. 내가 도대체 ​​뭘 잘못하고있는 겁니까 ?

ImageView mImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mImageView = (ImageView)findViewById(R.id.control);
        ClipDrawable drawable = (ClipDrawable)mImageView.getDrawable();
        drawable.setLevel(10);

    }

앱이 drawable.setLevel (10)에서 NullPointerException (drawable이 null 임)과 함께 충돌합니다.

내 XML은 다음과 같습니다.

circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:innerRadius="50dp"
    >

    <solid
        android:color="#FFAAFF"/>

</shape>

clip.xml

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:clipOrientation="horizontal"
    android:drawable="@drawable/circle"
    android:gravity="clip_horizontal"

/>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <ImageView
        android:id="@+id/image"
        android:layout_height="100dp"
        android:layout_width="100dp"
        android:background="@drawable/clip"
        android:layout_centerHorizontal="true"
        />

</RelativeLayout>

제발 도와주세요!

Mohax

드로어 블을 background'src'속성으로 설정했습니다 .

android : background = "@ drawable / clip"

. 따라서 속성을 다음으로 변경 activity_main.xml하여 변경하십시오 .backgroundsrc

android : src = "@ drawable / clip"

마지막으로 당신 activity_main.xml은 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<ImageView
    android:id="@+id/image"
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:scr="@drawable/clip"
    android:layout_centerHorizontal="true"
    />


또는 getBackground()속성으로 설정된 드로어 블을 반환 하는 메서드 호출하여 드로어 블을 얻을 수 있습니다.android:background

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

ImageView 높이는 항상 Android에서 0을 반환합니다.

Android SwipeRefreshLayout이 null을 반환합니다.

ImageView 배열이 null 개체를 반환합니다.

Android-Gson fromJson이 null을 반환합니다.

Android recyclerView findViewHolderForAdapterPosition이 null을 반환합니다.

Android-Firebase 문자열이 'null'을 반환합니다.

Android : findViewById는 setContentView 이후에도 Null을 반환합니다.

Android JSON 구문 분석이 null을 반환합니다.

Android Geocoder가 null 도시 이름을 반환합니다.

AnimatedVectorDrawable이있는 getDrawable이 Android 버전 4에서 충돌합니다.

Android DataBinding setVariable () 다음에 getVariable () 호출이 null을 반환합니다.

listFiles ()는 Android 6.0 에뮬레이터에서 null을 반환합니다.

조각이있는 Android 에스프레소. getActivity가 NULL을 반환합니다.

Assets의 BitmapFactory.decodeStream이 Android 7에서 null을 반환합니다.

Android 스튜디오, Kotlin : BitmapFactory.decodeStream ()이 null을 반환합니다.

Android : findViewById가 null을 반환합니다.

Android getAllCellInfo ()가 null을 반환합니다.

Android .getDrawable () 오류

@AuthenticationPrincipal이 null을 반환합니다.

목록이 null을 반환합니다.

GetManifestResourceStream이 NULL을 반환합니다.

Linq식이 null을 반환합니다.

ClassLoader getResourceAsStream이 null을 반환합니다.

큰 Json이 null을 반환합니다.

getResourceAsStream이 null을 반환합니다.

mockito stubbing이 null을 반환합니다.

JUnit getMethodName이 null을 반환합니다.

BufferedReader readLine이 null을 반환합니다.

getResourceAsStream이 null 값을 반환합니다.

TOP 리스트

  1. 1

    PrematureCloseException : 연결이 너무 일찍 닫혔습니다.

  2. 2

    MDRotatingPieChart를 회전하면 각도 대신 x / y 위치가 변경됩니다.

  3. 3

    c # 웹 사이트에서 텍스트를 복사하는 방법 (소스 코드 아님)

  4. 4

    jfreecharts에서 x 및 y 축 선을 조정하는 방법

  5. 5

    ArrayBufferLike의 typescript 정의의 깊은 의미

  6. 6

    Ionic 2 로더가 적시에 표시되지 않음

  7. 7

    복사 / 붙여 넣기 비활성화

  8. 8

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    QT Designer를 사용하여 GUI에 이미지 삽입

  11. 11

    java Apache POI Word 기존 테이블 셀 스타일 및 서식이있는 행 삽입

  12. 12

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

  13. 13

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  14. 14

    C # HttpWebRequest 기본 연결이 닫혔습니다. 전송시 예기치 않은 오류가 발생했습니다.

  15. 15

    어떻게 같은 CustomInfoWindow 다른 이벤트를 할 수 있습니다

  16. 16

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  17. 17

    dataSnapShot.getValue () 반환 데이터베이스에 그겁니다 데이터 종료 널 (null)

  18. 18

    ORA-12557 TNS : 프로토콜 어댑터를로드 할 수 없습니다

  19. 19

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  20. 20

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  21. 21

    C # Asp.net 웹 API-JSON / XML 변환기 API 만들기

뜨겁다태그

보관