1

我是 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..

编辑 错误日志..

我不确定我是否复制了所需的一个,请看这个(我确实从 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>
4

3 回答 3

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>
于 2013-04-06T20:33:26.183 回答
1

您没有在AndroidManifest.xml.

此链接应该对您有所帮助:Best way to add Activity to an Android project in Eclipse?

记住谷歌是你的朋友,努力自学,从长远来看,它会让你受益。

于 2013-04-06T20:37:57.183 回答
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>

在清单文件中,您忘记将布局引用到 java 文件。此外,当您想向应用程序添加新活动时,您需要为布局创建一个新的 xml 文件..和新的 java 类,这个类应该扩展 Activity,然后将 onCreate() 方法添加到此类。

于 2013-04-07T10:53:24.250 回答