1

i am beginner in android and coding small game Intro screen. My problem is that when i add some basic animation to intro screen there is no output and application stops with popup like this enter image description here ,

and when i comment animation method it shows simple xml based layouts please help me where is problem here is my java file

public class MainActivity extends Activity 
{
TextView  logo ;
TextView bottom  ;   
@Override
protected void onCreate(Bundle savedInstanceState)
{   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    animate();
}
public void animate()
{  
    logo=  (TextView) findViewById(R.id.toplogo);
    bottom =(TextView) findViewById(R.id.footer);
    Animation fade1= AnimationUtils.loadAnimation(this, R.anim.fade_in);
    logo.setAnimation(fade1);

    Animation fade2=  AnimationUtils.loadAnimation(this, R.anim.fade_in2);
    bottom.setAnimation(fade2);

    fade2.setAnimationListener(new AnimationListener(){

        @Override
        public void onAnimationEnd(Animation animation)
        {
           startActivity(new  Intent(MainActivity.this, Menu.class));    
           MainActivity.this.finish();  
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub
    }}
    );

 }     
public void onpause()
{
    super.onPause();
    logo.clearAnimation();
    bottom.clearAnimation();        
}
public void onResume()
{
    super.onResume();
    animate();
}

}

activity_main.xml file

<LinearLayout       xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
>

<TextView
    android:id="@+id/toplogo"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:textColor="@color/logoname"
    android:gravity="top|center"
    android:textSize="@dimen/logosize" />

<TableLayout
    android:id="@+id/TableLayout01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/tableRow1"
         android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
             android:minHeight="150px"               
            >
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_gravity="center_vertical|center_horizontal"
            android:src="@drawable/splash1"
              />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:src="@drawable/splash2"
              />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="150px"               

        >
         <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_gravity="center_vertical|center_horizontal"
            android:src="@drawable/splash3" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:src="@drawable/splash4" />
    </TableRow>




</TableLayout>

<TextView
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/logoname"
    android:textSize="@dimen/logosize"
    android:text="Done That " 
    android:gravity="bottom|center"
    android:minHeight="120px"
     >
  </TextView>

   </LinearLayout>

animation files

   fade_in2.xml
   <?xml version="1.0" encoding="utf-8"?>
  <set  xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
  <alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="2500"
    android:startOffset="2500">
 </alpha>

 </set >

and same way fade_in.xml etc. please help me with the problem whats wrong with the logic/code that its not working with animation ..

EDIT Error log ..

i am not sure if i copied requred one or not please see this one ( i did select error in drop down from logcat tab)

04-06 20:18:25.996: E/AndroidRuntime(812): FATAL EXCEPTION: main
04-06 20:18:25.996: E/AndroidRuntime(812): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.simplegame/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivityForResult(Activity.java:3370)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivityForResult(Activity.java:3331)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivity(Activity.java:3566)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivity(Activity.java:3534)
04-06 20:18:25.996: E/AndroidRuntime(812):  at com.example.simplegame.MainActivity$1.onAnimationEnd(MainActivity.java:41)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.animation.AnimationSet.getTransformation(AnimationSet.java:400)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.animation.Animation.getTransformation(Animation.java:940)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.drawAnimation(View.java:13205)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13344)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13715)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13596)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13715)  
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13596)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13594)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at an  droid.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13715)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
04-06 20:18:25.996: E/AndroidRuntime(812):  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
04-06 20:18:25.996: E/AndroidRuntime(812):  at  android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer.doFrame(Choreographer.java:532)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.os.Handler.handleCallback(Handler.java:725)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.os.Looper.loop(Looper.java:137)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.ActivityThread.main(ActivityThread.java:5041)
04-06 20:18:25.996: E/AndroidRuntime(812):  at java.lang.reflect.Method.invokeNative(Native Method)
04-06 20:18:25.996: E/AndroidRuntime(812):  at java.lang.reflect.Method.invoke(Method.java:511)
04-06 20:18:25.996: E/AndroidRuntime(812):  at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-06 20:18:25.996: E/AndroidRuntime(812):  at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-06 20:18:25.996: E/AndroidRuntime(812):  at dalvik.system.NativeStart.main(Native       Method)

EDIT FOR Manifest.xml

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.simplegame"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="17" />

 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
  android:name="com.example.simplegame.MainActivity"
  android:label="@string/app_name" >
  <intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  </activity>
  <activity android:name="Menu"></activity>
   </application>     

  </manifest>
Sikander
  • 2,799
  • 12
  • 48
  • 100
  • 2
    Please post the stack trace from logcat. If you don't know how, please ask. – Simon Apr 06 '13 at 19:56
  • yes i dont know how to read logcat – Sikander Apr 06 '13 at 19:56
  • are you using eclipse or netbeans? – Elior Apr 06 '13 at 19:59
  • so when it stop it should show you the stack trace.. just do copy that to your post – Elior Apr 06 '13 at 20:02
  • 2
    In LogCat when something is wrong it will be in red, when you see the crash happen search for the first chunk of red text and copy it. – Joban Apr 06 '13 at 20:09
  • @Elior please check if i have put right one – Sikander Apr 06 '13 at 20:27
  • @JobanDhillon please check the log and guide me where is problem, . – Sikander Apr 06 '13 at 20:29
  • 1
    `04-06 20:18:25.996: E/AndroidRuntime(812): FATAL EXCEPTION: main 04-06 20:18:25.996: E/AndroidRuntime(812): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.simplegame/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?` Please learn to read logcat. See how time you could have saved? – Simon Apr 06 '13 at 20:35
  • @Elior infect i did never use log even did not know to read it .hopefully next time i will track problem myself – Sikander Apr 06 '13 at 20:45
  • is the menu class should appear after the animated intro? i think that you declare in the manifest.xml a Menu class but you didn't refernce that to the java class.. so it doesn't know from where to load the Menu class, please post your manifest.xml file – Elior Apr 06 '13 at 21:29
  • @Elior yes that would go to Menu.java , i have added Activity in maunfest.xml .. now only screen loads animation does not work as expected and Does not go to Menu.java – Sikander Apr 07 '13 at 09:40
  • in my opinion, you need to create a separate activity for the intro screen, and when the movie's end, close the intro activity with the finish() method, and then load the menu activity.. – Elior Apr 07 '13 at 10:37
  • this activity is for intro , and when finishes goes to menu that is separate one .. public void onAnimationEnd(Animation animation) { startActivity(new Intent(MainActivity.this, Menu.class)); MainActivity.this.finish(); } – Sikander Apr 07 '13 at 10:43

3 Answers3

2

The problem is that you didn't declare the Activity in your Manifest

04-06 20:18:25.996: E/AndroidRuntime(812): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.simplegame/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?

UPDATED

add this to your manifest. and replace package name with your package name which is like com.etc.xxx

    <activity
        android:name="*package name*.Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MENU" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
Ahmed Ekri
  • 4,601
  • 3
  • 23
  • 42
1

You did not create the activity in the AndroidManifest.xml.

This link should help you: Best way to add Activity to an Android project in Eclipse?

Remember Google is your friend, make an effort to learn things on your own, it will benefit you in the long run.

Community
  • 1
  • 1
Joban
  • 1,318
  • 7
  • 19
1
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.simplegame"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
  android:minSdkVersion="8"
  android:targetSdkVersion="17" />

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

   <activity
       android:name="com.example.simplegame.INTRO"
       android:label="@string/app_name" >
       <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
   </activity>
   <activity
       android:name= "com.example.simplegame.Menu" <!-- java file-->
       android:label="@string/app_name">
       <intent-filter>
         <action android:name="thePackageOfTheLayoutsXmlFiles.MENU"/> <!-- layout -->
         <category androi:name = "android.intent.category.DEFAULT"/>
      </intent-filter>
   </activity>
 </application>     
 </manifest>

in the manifest file you forgot to refernce the layout to the java file.. also, when you want to add a new activity to your app, you need to create a new xml file for the layout.. and new java class, this class should extends the Activity and then add to this class the onCreate() method..

Elior
  • 3,178
  • 6
  • 37
  • 67