csh_34 2013-05-27 09:49 采纳率: 0%
浏览 2390
已采纳

在 android 平板上的动画显示错误

我开发一个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);

错误显示在logcat中:

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

如何解决这个问题?

  • 写回答

1条回答

  • balmy 2013-05-27 11:46
    关注

    是不是手机和平板所使用的布局文件夹不一样,导致平板找不到对应的布局,不能初始化textview对象tv

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn