Dua'a Shloul Dua'a Shloul - 29 days ago 10
Android Question

my application sometimes has stopped

my android application when click button it must go to another layout .. sometimes it go correctly and sometimes it has stopped ..
in some devices it work everytime and in another devices it sometimes work and sometimes doesn't work .

Here's my xml file for the layout which i have to go for :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context=".weddingActivity" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".weddingActivity" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="enter your text here"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/etFName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="choose your frame"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/w1"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w1" />

<ImageView
android:id="@+id/w3"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w3" />
<ImageView
android:id="@+id/w4"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w4" />
<ImageView
android:id="@+id/w5"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w5" />
<ImageView
android:id="@+id/w6"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w6" />
<ImageView
android:id="@+id/w7"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w7" />
<ImageView
android:id="@+id/w8"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w8" />
<ImageView
android:id="@+id/w9"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w9" />
<ImageView
android:id="@+id/w10"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w10" />
<ImageView
android:id="@+id/w11"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w11" />
<ImageView
android:id="@+id/w12"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w12" />
<ImageView
android:id="@+id/w14"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w14" />
<ImageView
android:id="@+id/w15"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w15" />
<ImageView
android:id="@+id/w16"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/w16" />
</LinearLayout>
</ScrollView>


and this is my weddingActivity.java (( which I have to go to )):

package com.example.invitationcard;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import android.widget.ImageView;


public class weddingActivity extends ActionBarActivity {
Button button;
ImageView imageView ;
EditText etFName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wedding);
addListenerOnImagew1() ;

etFName = (EditText) findViewById(R.id.etFName);
}

public void addListenerOnImagew1() {

final Context context = this;

imageView = (ImageView) findViewById(R.id.w1);

imageView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, w1.class);
startActivity(intent);
Intent intent1 = new Intent(context , w1.class);
intent1.putExtra("fname" , etFName.getText().toString());
startActivity(intent1);

}

}); }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}


}

and this is segment of code for the button which make a problem when i click on it :

button = (Button) findViewById(R.id.buttonW);
button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, weddingActivity.class);
startActivity(intent);

}

}); }


and this is a logcat

12-06 19:31:11.445: E/dalvikvm-heap(10195): Out of memory on a 30873616-byte allocation.
12-06 19:31:11.455: E/AndroidRuntime(10195): FATAL EXCEPTION: main
12-06 19:31:11.455: E/AndroidRuntime(10195): Process: com.example.invitationcard, PID: 10195
12-06 19:31:11.455: E/AndroidRuntime(10195): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.invitationcard/com.example.invitationcard.weddingActivity}: android.view.InflateException: Binary XML file line #104: Error inflating class <unknown>
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.os.Handler.dispatchMessage(Handler.java:102)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.os.Looper.loop(Looper.java:212)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.ActivityThread.main(ActivityThread.java:5135)
12-06 19:31:11.455: E/AndroidRuntime(10195): at java.lang.reflect.Method.invokeNative(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195): at java.lang.reflect.Method.invoke(Method.java:515)
12-06 19:31:11.455: E/AndroidRuntime(10195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
12-06 19:31:11.455: E/AndroidRuntime(10195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
12-06 19:31:11.455: E/AndroidRuntime(10195): at dalvik.system.NativeStart.main(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195): Caused by: android.view.InflateException: Binary XML file line #104: Error inflating class <unknown>
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
12-06 19:31:11.455: E/AndroidRuntime(10195): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
12-06 19:31:11.455: E/AndroidRuntime(10195): at com.example.invitationcard.weddingActivity.onCreate(weddingActivity.java:27)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.Activity.performCreate(Activity.java:5231)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
12-06 19:31:11.455: E/AndroidRuntime(10195): ... 11 more
12-06 19:31:11.455: E/AndroidRuntime(10195): Caused by: java.lang.reflect.InvocationTargetException
12-06 19:31:11.455: E/AndroidRuntime(10195): at java.lang.reflect.Constructor.constructNative(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
12-06 19:31:11.455: E/AndroidRuntime(10195): ... 25 more
12-06 19:31:11.455: E/AndroidRuntime(10195): Caused by: java.lang.OutOfMemoryError
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:856)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.content.res.Resources.loadDrawable(Resources.java:2129)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.widget.ImageView.<init>(ImageView.java:129)
12-06 19:31:11.455: E/AndroidRuntime(10195): at android.widget.ImageView.<init>(ImageView.java:119)
12-06 19:31:11.455: E/AndroidRuntime(10195): ... 28 more

Answer Source
  • you are having too many imageviews which tend to have for example 925 * 1300 kinda like dimension, now this will not always run on some devices but maybe run or will run on tablets..so trim your images and it will work all the time..

    if it will be suitable trim your images and put the original size in your xxxhdpi folder, and trim the images to smaller sizes and put it in your maybe hdpi folder.. or maybe if you have created a "drawable" folder place it in.. so that the android os will call for the trimed images on smaller sized phones on call the bigger image on tablet kinda phones

    OR

  • to make things easier google "supporting screen sizes in android" you will get a better foresight on how to go about this in terms of re-sizing the images for phones and tablets ok.

As i said, for rep sake.. be good..