0

I am trying to make a splash screen with a fixed photo and animated text. However, the application always stops when launching. In the logcat, the only problem that appears is in SplashScreen line 17, and more specifically this line of code:

setContentView(R.layout.activity_splash_screen);

My code:

activity_splash_screen.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="com.example.lenovo.tryfinal.SplashScreen">

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/garagny"
    android:id="@+id/imageView"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Park Easily"
    android:layout_marginBottom="93dp"
    android:textSize="60dp"
    android:layout_alignBottom="@+id/imageView"
    android:layout_centerHorizontal="true"
    android:id="@+id/ParkEasily"/>

    </RelativeLayout>

SplashScreen.java

package com.example.lenovo.garagnyapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

public class SplashScreen extends Activity {

TextView ParkEasily;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
    ParkEasily = (TextView) findViewById(R.id.ParkEasily);
    Animation fade1 = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.fade_in);
    ParkEasily.startAnimation(fade1);

    ParkEasily.startAnimation(fade1);

    fade1.setAnimationListener(new Animation.AnimationListener() {
        public void onAnimationEnd(Animation animation) {
            startActivity(new
                    Intent(SplashScreen.this, MainActivity.class));
            SplashScreen.this.finish();
        }

        public void onAnimationRepeat(Animation animation){
        }
        public void onAnimationStart(Animation animation){
        }



    });
}
}

fade_in.xml

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:duration="5000" android:repeatCount="infinite"/>
</set>
3751_Creator
  • 656
  • 2
  • 8
  • 22
  • @ZahanSafallwa I think the app is crashing at launch and would be caused by SplashScreen on line 17 – 3751_Creator Oct 27 '15 at 12:58
  • java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lenovo.garagnyapplication/com.example.lenovo.garagnyapplication.SplashScreen}: android.view.InflateException: Binary XML file line #9: Error inflating class – Mahmoud S. Ahmed Oct 27 '15 at 13:09
  • at com.example.lenovo.garagnyapplication.SplashScreen.onCreate(SplashScreen.java:17) – Mahmoud S. Ahmed Oct 27 '15 at 13:09

3 Answers3

2

Your xml context refers this:

tools:context="com.example.lenovo.tryfinal.SplashScreen"

but your package is:

com.example.lenovo.garagnyapplication;

Your xml contex should be (tools:context="com.example.lenovo.garagnyapplication.SplashScreen")

Alican Temel
  • 1,318
  • 13
  • 13
  • Layout cant be inflated. Because contex is different. – Alican Temel Oct 27 '15 at 16:51
  • As per my knowledge "tools:context" is used by Android Studio to render the activity screen in Preview. It will not be used at run time when application is built. You may refer http://stackoverflow.com/questions/11078487/whats-toolscontext-in-android-layout-files for more details – Jickson Oct 28 '15 at 01:13
  • You right, I know it is used by android studio to render the activity screen in Preview. But, I get the same crash, when ı changed the context, crash disappeared. I don't know why it happens. Maybe, it can be android studio bug. – Alican Temel Oct 28 '15 at 06:26
0

I think you should import the R of your app. Try add "import {your package name}.R" line above Activity class. If it still shows error message, clean your project and check your xml file whether it has error. Then, build again and try to import generated R file.

0

Your SplashActivity class is under package com.example.lenovo.garagnyapplication

But your tools:context in xml is com.example.lenovo.tryfinal.SplashScreen

Make them same. in xml make it

   tools:context="com.example.lenovo.garagnyapplication.SplashScreen"
Zahan Safallwa
  • 3,880
  • 2
  • 25
  • 32