Reputation: 19
I am having a weird problem with my program in eclipse. I have multiple activity and my intent methods jumps to one activity to another. It was working to other activities but for a certain activity it doesn't work, hence, app crashes. I have the following activity intent hop:
GameMenu
intent buttons direct to > AppInfo
& InstructionScreen
(works fine)AppInfo
intent button directs back to > GameMenu
(works fine)Instruction
intent button directs to > ColorGame
activity
(crashes).Here is my code for the InstructionScreen
:
public class InstructionScreen extends Activity {
ViewFlipper c2s;
ImageView c2s1,c2s2;
MediaPlayer buttonClick;
Intent playGame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_instruction_screen);
c2s = (ViewFlipper) findViewById (R.id.click2start);
buttonClick = MediaPlayer.create(this, R.raw.buttonclick);
c2s.setFlipInterval(100);
c2s.startFlipping();
this.clickToStart();
}
private void clickToStart() {
c2s1 = (ImageView) findViewById (R.id.c2s1);
c2s2 = (ImageView) findViewById (R.id.c2s2);
c2s1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonClick.start();
c2s.stopFlipping();
playGame = new Intent(InstructionScreen.this, ColorGame.class);
playGame.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(playGame);
}
});
c2s2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonClick.start();
c2s.stopFlipping();
playGame = new Intent(InstructionScreen.this, ColorGame.class);
playGame.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(playGame);
}
});
}
}
Here is the code for ColorGame
: (the content is not done, but i doubt that it was the problem)
public class ColorGame extends Activity {
TextView timer, score;
ViewFlipper colors;
ImageView yellow, red, green;
MediaPlayer backgroundMusic;
int gameTime, points;
Random colorNum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_color_game);
backgroundMusic = MediaPlayer.create(this, R.raw.colorgamebgs);
backgroundMusic.start();
yellow = (ImageView) findViewById(R.id.yellowbar);
red = (ImageView) findViewById(R.id.redbar);
green = (ImageView) findViewById(R.id.greenbar);
colorNum = new Random();
timer = (TextView) findViewById(R.id.timer);
timer.setText("START");
this.startGame();
}
private void startGame() {
// TODO Auto-generated method stub
}
}
Also, here is the XML for ColorGame
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/colorgame"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ColorGame" >
<TextView
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="@string/game_timer"
android:textSize="100sp" />
<TextView
android:id="@+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timer"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:contentDescription="@string/score_pts"
android:text="@string/score_pts"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="@+id/yellowbar"
android:layout_width="70dp"
android:layout_height="125dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:contentDescription="@string/yellow_bar"
android:src="@drawable/yellowbar" />
<ImageView
android:id="@+id/greenbar"
android:layout_width="70dp"
android:layout_height="125dp"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/redbar"
android:contentDescription="@string/green_bar"
android:src="@drawable/greenbar" />
<ViewFlipper
android:id="@+id/colors"
android:layout_width="150dp"
android:layout_height="100dp"
android:layout_centerVertical="true"
android:layout_below="@+id/score"
android:visibility="invisible"
android:layout_toLeftOf="@+id/greenbar" >
<ImageView
android:id="@+id/green1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/green"
android:src="@drawable/green1" />
<ImageView
android:id="@+id/green2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/green"
android:src="@drawable/green2" />
<ImageView
android:id="@+id/green3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/green"
android:src="@drawable/green3" />
<ImageView
android:id="@+id/red1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/red"
android:src="@drawable/red1" />
<ImageView
android:id="@+id/red2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/red"
android:src="@drawable/red2" />
<ImageView
android:id="@+id/red3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/red"
android:src="@drawable/red3" />
<ImageView
android:id="@+id/dilaw1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/dilaw"
android:src="@drawable/yellow1" />
<ImageView
android:id="@+id/dilaw2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/dilaw"
android:src="@drawable/yellow2" />
<ImageView
android:id="@+id/dilaw3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/dilaw"
android:src="@drawable/yellow3" />
</ViewFlipper>
<ImageView
android:id="@+id/redbar"
android:layout_width="70dp"
android:layout_height="125dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/red_bar"
android:src="@drawable/redbar" />
</RelativeLayout>
LogCat:
05-03 20:46:12.479: E/SpannableStringBuilder(28535): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-03 20:46:12.479: E/SpannableStringBuilder(28535): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-03 20:46:19.594: E/dalvikvm-heap(28535): Out of memory on a 1200016-byte allocation.
05-03 20:46:19.634: E/AndroidRuntime(28535): FATAL EXCEPTION: main
05-03 20:46:19.634: E/AndroidRuntime(28535): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ics136.colorgame/com.ics136.colorgame.ColorGame}: android.view.InflateException: Binary XML file line #42: Error inflating class <unknown>
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.ActivityThread.access$700(ActivityThread.java:140)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.os.Looper.loop(Looper.java:137)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.ActivityThread.main(ActivityThread.java:4938)
05-03 20:46:19.634: E/AndroidRuntime(28535): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 20:46:19.634: E/AndroidRuntime(28535): at java.lang.reflect.Method.invoke(Method.java:511)
05-03 20:46:19.634: E/AndroidRuntime(28535): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
05-03 20:46:19.634: E/AndroidRuntime(28535): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
05-03 20:46:19.634: E/AndroidRuntime(28535): at dalvik.system.NativeStart.main(Native Method)
05-03 20:46:19.634: E/AndroidRuntime(28535): Caused by: android.view.InflateException: Binary XML file line #42: Error inflating class <unknown>
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.createView(LayoutInflater.java:619)
05-03 20:46:19.634: E/AndroidRuntime(28535): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-03 20:46:19.634: E/AndroidRuntime(28535): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.Activity.setContentView(Activity.java:1924)
05-03 20:46:19.634: E/AndroidRuntime(28535): at com.ics136.colorgame.ColorGame.onCreate(ColorGame.java:22)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.Activity.performCreate(Activity.java:5188)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
05-03 20:46:19.634: E/AndroidRuntime(28535): ... 11 more
05-03 20:46:19.634: E/AndroidRuntime(28535): Caused by: java.lang.reflect.InvocationTargetException
05-03 20:46:19.634: E/AndroidRuntime(28535): at java.lang.reflect.Constructor.constructNative(Native Method)
05-03 20:46:19.634: E/AndroidRuntime(28535): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
05-03 20:46:19.634: E/AndroidRuntime(28535): ... 24 more
05-03 20:46:19.634: E/AndroidRuntime(28535): Caused by: java.lang.OutOfMemoryError
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:636)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:484)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:813)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.content.res.Resources.loadDrawable(Resources.java:2277)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.widget.ImageView.<init>(ImageView.java:126)
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.widget.ImageView.<init>(ImageView.java:116)
05-03 20:46:19.634: E/AndroidRuntime(28535): ... 27 more
Upvotes: 0
Views: 88
Reputation: 6220
You have some exceptions, like
Caused by: android.view.InflateException: Binary XML file line #42
Caused by: android.view.InflateException: Binary XML file line #42: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.OutOfMemoryError
As @JafarKhQ said, probably you have an Image too large and it is consuming the memory budget of the app, check if may be an image you have in ColorGame
is too large.
I will bet the problem is the background image of your RelativeLayout
, as you said in the comments, that image is almost 2Mb, I think the problem is there.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
<!-- .... -->
android:background="@drawable/colorgame"
<!-- .... -->
>
Try to reduce the size of the image or remove it to find if that is the problem.
Upvotes: 0
Reputation: 8734
You have OutOfMemoryError
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
look like you are trying to load a large bitmap or something like that, check line #42 at the layout
for ColorGame
Activity
Unable to start activity ComponentInfo
{com.ics136.colorgame/com.ics136.colorgame.ColorGame}:
android.view.InflateException: Binary XML file line #42: Error inflating class <unknown>
Upvotes: 1
Reputation: 1020
As per the Logcat
"Caused by: android.view.InflateException: Binary XML file line #42: Error inflating class <unknown>
05-03 20:46:19.634: E/AndroidRuntime(28535): at android.view.LayoutInflater.createView(LayoutInflater.java:619)"
There is an error at Line #42. Please check your XML
Upvotes: 1