在android中动画期间关闭力的错误?

时间:2011-01-05 08:31:48

标签: android

这是我在Android和Iam中的动画代码出现以下错误

 package com.viewslide;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.provider.MediaStore;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

public class slideview extends Activity {

  private Animation Animationtype;
    /** Called when the activity is first created. */
   int i=0;
   ImageView img1,img2;
   int PICK_REQUEST_CODE=0;
   MyCount counter;
   Uri startDir1;
  @Override
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Animationtype= AnimationUtils
     .loadAnimation(this, R.anim.slide_top_to_bottom);
        openSdcard();
         counter=new MyCount(2000,1000);
      }

  public void openSdcard()
  {
   Intent intent = new Intent();
      intent.setAction(Intent.ACTION_GET_CONTENT);
      Uri startDir1= Uri.fromFile(new File("/"));
      intent.setDataAndType(startDir1, "vnd.android.cursor.dir/lysesoft.andexplorer.file");
      intent.putExtra("browser_filter_extension_whitelist", "*.txt,*.mp3,*.jpg"); 
      intent.putExtra("explorer_title", "Select a file");
         // Optional colors
      intent.putExtra("browser_title_background_color", "440000AA");
      intent.putExtra("browser_title_foreground_color", "FFFFFFFF");
      intent.putExtra("browser_list_background_color", "66000000");
      intent.putExtra("browser_list_fontscale", "120%");
      intent.putExtra("browser_list_layout", "1");
     //if( Uri startDir1== Uri.fromFile(new File("/")))
    //  if(startDir1==Uri.fromFile(new File("/sdcard/DCIM")))
   //  {
     startActivityForResult(intent,PICK_REQUEST_CODE);
     onActivityResult(PICK_REQUEST_CODE, PICK_REQUEST_CODE, intent);
     //}
  }


  protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
         super.onActivityResult(requestCode, resultCode,intent); 

          if (requestCode == PICK_REQUEST_CODE)
          {
           if (resultCode == RESULT_OK)
           {   
             StartTimer();
           }
          }
  }

        public void slideshow()
        {
        String[] filePathColumn = {MediaStore.Images.Media.DATA};
        Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, filePathColumn, null, null, null);
        int count= cursor.getCount();
         if(i<count-1){     

        cursor.moveToPosition(i);
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String filePath = cursor.getString(columnIndex);
        cursor.close();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inTempStorage = new byte[16*1024];

      //  bitmapImage = BitmapFactory.decodeFile(path,opt);
        Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath,options);
        img1 = (ImageView)findViewById(R.id.img1);

        img1.setImageBitmap(yourSelectedImage);

       img1.startAnimation(Animationtype);
       registerForContextMenu(img1);
       i=i+1;
  }
         else
         {
          img1.setImageBitmap(null);
         // Toast.makeText(getBaseContext(), "End of SlideShow", 1000).show();

         }
  }

public void StartTimer(){
    counter.start();
        }

private void pause() {
 counter.cancel();
}

private void resume() {
 counter = new MyCount(2000,1000);
 counter.start();
}

private class MyCount extends CountDownTimer {

public MyCount(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
    // TODO Auto-generated constructor stub
   }

   @Override
   public void onFinish() {
   // TODO Auto-generated method stub
    slideshow();
    StartTimer();
    }
   @Override
   public void onTick(long millisUntilFinished) {
    // TODO Auto-generated method stub
   }
        }

public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo) {  
         super.onCreateContextMenu(menu, v, menuInfo);
         pause();
         menu.setHeaderTitle("Animation");  
         menu.add(0, v.getId(), 0, "hyperspace_jump");  

         menu.add(0, v.getId(), 0, "shake");  
         menu.add(0, v.getId(), 0, "rotate");  
         menu.add(0, v.getId(), 0, "magnify");  
         menu.add(0, v.getId(), 0, "zoom_enter");  
         menu.add(0, v.getId(), 0, "zoom_exit");  
         menu.add(0, v.getId(), 0, "hyperspace_in");
       }

public boolean onContextItemSelected(MenuItem item){

     if("hyperspace_jump".equals(item.getTitle()))

          { 
           resume();
           slideshow();
           Animationtype= AnimationUtils
           .loadAnimation(this, R.anim.hyperspace_jump);
           img1.startAnimation(Animationtype);
           }

       else if("shake".equals(item.getTitle()))
           { 
        resume();
           slideshow();
           Animationtype= AnimationUtils
              .loadAnimation(this, R.anim.shake);
              img1.startAnimation(Animationtype);
             }
       else if("rotate".equals(item.getTitle()))
              { 
        resume();
           slideshow();
           Animationtype= AnimationUtils
              .loadAnimation(this, R.anim.rotate);
               img1.startAnimation(Animationtype);
             }else if("magnify".equals(item.getTitle()))
               { 
                     resume();
               slideshow();
               Animationtype= AnimationUtils
                  .loadAnimation(this, R.anim.magnify);
                  img1.startAnimation(Animationtype);
                 }
                   else if("zoom_enter".equals(item.getTitle()))

                  { 
                  resume();
                  slideshow();
                  Animationtype= AnimationUtils
                  .loadAnimation(this, R.anim.zoom_enter);
                  img1.startAnimation(Animationtype);
                  }
                   else if("zoom_exit".equals(item.getTitle()))
                  { 
                  resume();
                  slideshow();
                  Animationtype= AnimationUtils
                  .loadAnimation(this, R.anim.zoom_exit);
                  img1.startAnimation(Animationtype);
                  }
                   else if("hyperspace_in".equals(item.getTitle()))
                  { 
                  resume();
                  slideshow();
                  Animationtype= AnimationUtils
                  .loadAnimation(this, R.anim.hyperspace_in);
                  img1.startAnimation(Animationtype);
                  }
                   else
                     {
                    return false;
                     }
         return true;
   }


}  

我得到的错误是

E/AndroidRuntime(26250): FATAL EXCEPTION: main
E/AndroidRuntime(26250): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(26250): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
E/AndroidRuntime(26250): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
E/AndroidRuntime(26250): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:271)
E/AndroidRuntime(26250): at com.viewslide.slideview.slideshow(slideview.java:91)
E/AndroidRuntime(26250): at com.viewslide.slideview$MyCount.onFinish(slideview.java:131)
E/AndroidRuntime(26250): at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
E/AndroidRuntime(26250): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(26250): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(26250): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(26250): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(26250): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(26250): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime(26250): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime(26250): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(18078): Force finishing activity com.viewslide/.slideview

请尽快帮助 谢谢你提前