user3505775
user3505775

Reputation: 339

Error Binary XML file line #2: Error inflating class on android programming

I have an android program with 2 layouts. The first layout is Login. When the login is started first, I have no problem. When I try to change in AndroidManifest from login to splash layout, I got an error. The error is like the title of this posts.

In this android manifest, I change my code from :

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    >

    <activity
        android:name=".Login"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

to :

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    >

    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Here is the layout for login:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Login">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Your total is 0"
    android:textSize="45dp"
    android:gravity="center"
    android:id="@+id/tvDisplay"
    />

<Button
    android:layout_width="250dp"
    android:layout_height="100dp"
    android:text="Add One"
    android:gravity="center"
    android:layout_gravity="center"
    android:id="@+id/bAdd"
    android:textSize="20dp"/>
<Button
    android:layout_width="250dp"
    android:layout_height="100dp"
    android:text="Substract One"
    android:gravity="center"
    android:layout_gravity="center"
    android:id="@+id/bSub"
    android:textSize="20dp"/>

And here the layout of splash:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/sertifikat"
tools:context=".Splash"></LinearLayout>

And structure of my code :

enter image description here

Log in logcat:

enter image description here

Here splash.java enter image description here

How can I fix my code?

Upvotes: 1

Views: 1062

Answers (4)

Om Komawar
Om Komawar

Reputation: 251

Hey You missed some small things

Here is a small example from your code on Github that i wrote

This is running example of your code

Other than the ending tags The <intent-filter> should only be one

most probably the problem lies in your @drawable

as well as look at these tutorials they are great

http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/

Upvotes: 1

koni
koni

Reputation: 1795

For better performance I recommend you to follow this : http://www.cutehacks.com/blog/2014/01/13/splash-screens

If you use an high end device you won't see a big difference, but for common devices you will see an huge improvement

Upvotes: 0

Jschools
Jschools

Reputation: 2758

You are missing the closing tag of your LinearLayout in splash.xml. Add </LinearLayout> to the end of the file. You also might want to consider using an ImageView with android:scaleType="centerCrop" instead of using a LinearLayout with a background. Using android:background will stretch to fit the size of the screen, which can give a different aspect ratio on different devices, whereas an ImageView will scale it to maintain the aspect ratio (depending on the scaleType).

Also, a LinearLayout is not appropriate for a single image, since it is meant to be a container for other views.

Upvotes: 0

pony
pony

Reputation: 1381

Obviously,you have lost a character '/' in the splash layout at the end.

Upvotes: 0

Related Questions