verweist Hallo, ich habe das folgende kodiert, um die Ansicht vom Include-Layout zu bekommen. Aber ich bekomme Nullzeigerausnahme. Wo ich falsch liege?Wie man eine Ansicht innerhalb des Includelayouts in android
Mein Java-Code:
View actionbar = findViewById(R.id.actionbar);
RelativeLayout actionRRl = (RelativeLayout)actionbar.findViewById(R.id.actionRR);
actionRRl.setEnabled(false);
actionRRl.setClickable(false);
In meinem Activity.xml,
<include
android:id="@+id/actionbar"
layout="@layout/actionbar" />
-Layout, die enthalten ist, dh actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/header"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
android:id="@+id/actionRR"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:clickable="false"
android:padding="@dimen/logo_size"
android:src="@drawable/logo" />
</RelativeLayout>
Fehler-Stack.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setEnabled(boolean)' on a null object reference
Versucht Ihr Code: Sein Wurffehler Kumpel! Verursacht von: java.lang.NullPointerException: Versuch, die virtuelle Methode 'void android.widget.RelativeLayout.setEnabled (boolean)' bei einem Nullobjekt-Verweis aufzurufen –
Bitte stellen Sie sicher, dass Sie den Aufruf nach dem 'setContentView()' durchführen –