当我点击imgPlayGame - >打开新活动 - >错误 我的主要:
ImageView imgPlayGame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.start_game);
AddEvents();
}
我的活动:
public void AddEvents(){
imgPlayGame=(ImageView) findViewById(R.id.imgPlayGame);
//repeat imgPlayGame
Start_Repeat_ImgPlayGame();
imgPlayGame.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StartGame();
}
});
}
动画Drawable:
public void Start_Repeat_ImgPlayGame(){
imgPlayGame.setBackgroundResource(R.drawable.play_anim_repeat);
animationDrawable= (AnimationDrawable) imgPlayGame.getBackground();
animationDrawable.start();
}
打开新活动:
protected void StartGame() {
Intent select_level= new Intent(StartGameActivity.this, SelectLevelActivity.class);
startActivity(select_level);
}
类play_anim_repeat:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/ic_play_2"
android:duration="300"
>
</item>
<item
android:drawable="@drawable/ic_play_3"
android:duration="300">
</item>
<item
android:drawable="@drawable/ic_play_4"
android:duration="300">
</item>
</animation-list>
错误:
11-30 16:14:16.476:E / dalvikvm-heap(11347):30025744字节分配的内存不足。 11-30 16:14:16.491:E / AndroidRuntime(11347): 致命异性:主要11-30 16:14:16.491:E / AndroidRuntime(11347): 过程:com.thoai.leminh.huntervsfruit,PID:11347 11-30 16:14:16.491:E / AndroidRuntime(11347):java.lang.RuntimeException: 无法开始活动 ComponentInfo {com.thoai.leminh.huntervsfruit / com.thoai.leminh.huntervsfruit.EasyLevelActivity}: android.view.InflateException:二进制XML文件行#2:错误 膨胀等级11-30 16:14:16.491:E / AndroidRuntime(11347): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.app.ActivityThread.access $ 900(ActivityThread.java:161)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1265) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.os.Handler.dispatchMessage(Handler.java:102)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.os.Looper.loop(Looper.java:157)11-30 16:14:16.491: E / AndroidRuntime(11347):at android.app.ActivityThread.main(ActivityThread.java:5356)11-30 16:14:16.491:E / AndroidRuntime(11347):at java.lang.reflect.Method.invokeNative(Native Method)11-30 16:14:16.491:E / AndroidRuntime(11347):at java.lang.reflect.Method.invoke(Method.java:515)11-30 16:14:16.491: E / AndroidRuntime(11347):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1265) 11-30 16:14:16.491:E / AndroidRuntime(11347):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)11-30 16:14:16.491:E / AndroidRuntime(11347):at dalvik.system.NativeStart.main(Native Method)11-30 16:14:16.491: E / AndroidRuntime(11347):引起:android.view.InflateException: 二进制XML文件行#2:错误膨胀类11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.LayoutInflater.createView(LayoutInflater.java:626)11-30 16:14:16.491:E / AndroidRuntime(11347):at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.LayoutInflater.inflate(LayoutInflater.java:470)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.LayoutInflater.inflate(LayoutInflater.java:398)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.LayoutInflater.inflate(LayoutInflater.java:354)11-30 16:14:16.491:E / AndroidRuntime(11347):at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.app.Activity.setContentView(Activity.java:2010)11-30 16:14:16.491:E / AndroidRuntime(11347):at com.thoai.leminh.huntervsfruit.EasyLevelActivity.onCreate(EasyLevelActivity.java:20) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.app.Activity.performCreate(Activity.java:5426)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269) 11-30 16:14:16.491:E / AndroidRuntime(11347):... 11更多11-30 16:14:16.491:E / AndroidRuntime(11347):引起: java.lang.reflect.InvocationTargetException 11-30 16:14:16.491: E / AndroidRuntime(11347):at java.lang.reflect.Constructor.constructNative(Native Method)11-30 16:14:16.491:E / AndroidRuntime(11347):at java.lang.reflect.Constructor.newInstance(Constructor.java:423)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.LayoutInflater.createView(LayoutInflater.java:600)11-30 16:14:16.491:E / AndroidRuntime(11347):... 23更多11-30 16:14:16.491:E / AndroidRuntime(11347):引起: java.lang.OutOfMemoryError 11-30 16:14:16.491: E / AndroidRuntime(11347):at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.content.res.Resources.loadDrawable(Resources.java:3024)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.content.res.TypedArray.getDrawable(TypedArray.java:602)11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.View。(View.java:3694)11-30 16:14:16.491: E / AndroidRuntime(11347):在android.view.View。(View.java:3624) 11-30 16:14:16.491:E / AndroidRuntime(11347):at android.view.ViewGroup。(ViewGroup.java:474)11-30 16:14:16.491: E / AndroidRuntime(11347):at android.widget.RelativeLayout。(RelativeLayout.java:236)11-30 16:14:16.491:E / AndroidRuntime(11347):... 26更多
答案 0 :(得分:1)
你的形象@ drawable / backgound_easy可能太大了。尝试使用另一个
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html