Android平板电脑上的动画显示错误

时间:2013-02-19 13:26:18

标签: android animation tablet

我正在开发一个以这个启动画面开始的android项目。除了平板电脑外,该项目在模拟器和真实设备上运行顺畅..

package com.example.project;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class Splashscreen extends Activity 
{
    private static String TAG=Splashscreen.class.getName();
    private static long SLEEP_TIME=6;
    TextView tv;
    ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splash1);

        TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0,Animation.ABSOLUTE,250,Animation.ABSOLUTE,0);
        translate.setDuration(3000);
        translate.reset();  
        translate.setFillAfter(true);

        tv=(TextView)findViewById(R.id.tt1);

        tv.startAnimation(translate);


        iv=(ImageView)findViewById(R.id.i1);
        Animation anim1= new AlphaAnimation(1, 0);
        anim1.setDuration(1000);
        anim1.setInterpolator(new LinearInterpolator());
        anim1.setRepeatCount(1);
        anim1.setRepeatMode(Animation.REVERSE);
        iv.startAnimation(anim1);


        IntentLauncher launcher=new IntentLauncher();
        launcher.start();
    }
    private class IntentLauncher extends Thread
    {
        public void run()
        {
            try{
                Thread.sleep(SLEEP_TIME*1000);

            }catch(Exception e)
            {
                Log.e(TAG,e.getMessage());
            }
            Intent i=new Intent(Splashscreen.this,Login_or_up.class);
            Splashscreen.this.startActivity(i);
            Splashscreen.this.finish();
        }
    }

}

logCat中显示的错误是

    02-19 18:04:45.434: D/AndroidRuntime(613): Shutting down VM
02-19 18:04:45.454: W/dalvikvm(613): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-19 18:04:45.464: E/AndroidRuntime(613): FATAL EXCEPTION: main
02-19 18:04:45.464: E/AndroidRuntime(613): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project/com.example.project.Splashscreen}: java.lang.NullPointerException
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.os.Looper.loop(Looper.java:123)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-19 18:04:45.464: E/AndroidRuntime(613):  at java.lang.reflect.Method.invokeNative(Native Method)
02-19 18:04:45.464: E/AndroidRuntime(613):  at java.lang.reflect.Method.invoke(Method.java:521)
02-19 18:04:45.464: E/AndroidRuntime(613):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-19 18:04:45.464: E/AndroidRuntime(613):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-19 18:04:45.464: E/AndroidRuntime(613):  at dalvik.system.NativeStart.main(Native Method)
02-19 18:04:45.464: E/AndroidRuntime(613): Caused by: java.lang.NullPointerException
02-19 18:04:45.464: E/AndroidRuntime(613):  at com.example.project.Splashscreen.onCreate(Splashscreen.java:38)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-19 18:04:45.464: E/AndroidRuntime(613):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-19 18:04:45.464: E/AndroidRuntime(613):  ... 11 more
02-19 18:04:47.394: I/Process(613): Sending signal. PID: 613 SIG: 9

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:1)

学会阅读日志,你必须,年轻的padawan !!!

02-19 18:04:45.464: E/AndroidRuntime(613): Caused by: java.lang.NullPointerException
02-19 18:04:45.464: E/AndroidRuntime(613):  at com.example.project.Splashscreen.onCreate(Splashscreen.java:38)

像38这样的Nullpointer异常,如你所说,第38行正在使用tvtranslate。因为肯定会启动翻译,所以你只能在平板电脑上使用它,因为R.layout.splash1的xlarge或sw720没有带有ID R.id.i1的TextView

答案 1 :(得分:0)

我不喜欢你的IntentLauncher。注释掉它并在onCreate的末尾添加此代码:

new Handler().postDelayed(new Runnable() {
   public void run() {
        Intent i=new Intent(Splashscreen.this,Login_or_up.class);
        Splashscreen.this.startActivity(i);
        Splashscreen.this.finish();
   }
}, 6000);

第38行是什么?