Xml components are not loaded into Activity

Asked

Viewed 111 times

0

Editing:

I just found out that if I comment on the lines that cause the error, it gets all black screen... IE, does not load the layout.

I’m trying to get a Progressbar and a Textview so I can make changes according to an Asynctask. It is worth mentioning that at the time the project was created, the main Activity is not this, this (named Splashscreen) was created later (I’m saying this because I’m a beginner and I have no knowledge if something can affect, if I left something behind).

protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.splash_screen);

    /* New Handler to start the Menu-Activity
     * and close this Splash-Screen after some seconds.*/

    mProgressBar = (ProgressBar) this.findViewById(R.id.progressBar);
    mProgressText = (TextView) this.findViewById(R.id.progressBarTextView);

    try {
        new WSCatalogo91(this).execute();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

the return of the lines where they make the findViewById is null always.

<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=".SplashScreen">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/logoSplashScreen"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <TextView android:text="@string/progressBar" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:id="@+id/progressBarTextView"
        android:maxWidth="400dp"
        android:maxHeight="400dp"/>

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:indeterminate="false"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="165dp"
        android:minWidth="300dp" />

</RelativeLayout>

Manifest:

<activity
    android:name="com.universo91.catalogo91_android.activity.MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="landscape" >
</activity>


<activity
    android:name="com.universo91.catalogo91_android.activity.SplashScreen"
    android:label="@string/title_activity_splash_screen"
    android:theme="@android:style/Theme.NoTitleBar"
    android:screenOrientation="landscape" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


<activity
    android:name="com.universo91.catalogo91_android.activity.Login"
    android:label="@string/title_activity_login"
    android:screenOrientation="landscape">
</activity>
  • Note that in the method setContentView you make reference to the layout of your screen splash but you’re trying to get elements from the screen of login, soon will not be found and will return a null value.

  • Put as answer.

  • I didn’t put as an answer because I wasn’t sure, and I really got confused. It seems that this question XML is even your screen splash, right? If that’s the case, the implementation is right, because the definition of content with setContentView should make it possible for you to obtain the elements.

  • Yes it is he.

  • @Paulorodrigues I just found out that if you comment on the lines that cause the error, it gets the screen all black... IE, does not load the layout.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.