2013-04-06 45 views
1

我是初学者在android和编码小游戏介绍屏幕。我的问题是,当我添加一些基本的动画介绍屏幕没有输出和应用程序停止弹出这样的enter image description here,Android应用程序停止当动画添加

当我评论动画方法,它显示简单的基于XML的布局,请帮助我这里的问题是什么我的Java文件

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> 

动画文件

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 > 

和同样的方式fade_in.xml等,请帮助我的问题什么错与逻辑/代码,它不是用animation工作..

编辑错误日志..

我不知道,如果我复制requred一个或不请参见这一个(我没有在下拉菜单中选择错误的logcat的标签下)

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) 

编辑的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> 
+2

请从logcat发布堆栈跟踪。如果你不知道如何,请询问。 – Simon 2013-04-06 19:56:18

+0

是的,我不知道如何阅读logcat – Sikander 2013-04-06 19:56:36

+0

你使用的是eclipse或netbeans吗? – Elior 2013-04-06 19:59:38

回答

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> 
清单文件

你忘了布局refernce到java文件.. 也,当你想要一个新的活动添加到您的应用程序,你需要创建一个新的XML文件 为布局..和新的java类,这个类应扩展活动 ,然后添加到这个类的onCreate()方法..

+0

是的,我修好了,现在可以工作。感谢你的帮助 – Sikander 2013-04-09 15:02:25

2

的问题是,你没有申报的活动在你的清单

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? 

修订

添加到您的清单。与它就像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> 
+0

我现在怎么办? – Sikander 2013-04-06 20:35:23

+0

检查我编辑的答案。 – 2013-04-07 19:29:48