Nick Robertson
Nick Robertson

Reputation: 1047

Android Exception

I try to implement a project where I will load many pictures in a listview. I implement this with a lazy instatiation. I also inflate the list with an adapter and with the following way:

 static class ViewHolder {
    ImageView imageView;
    TextView brand;
    TextView text;
    TextView cost;
    TextView saleCost;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {


    ViewHolder holder;
    // Set the product.
    Product currentProduct = getItem(position);

    if(convertView ==null){
        Activity activity = (Activity)getContext();
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_item, null);
        holder = new ViewHolder();

        // Extract the ImageView from the row.
        holder.imageView = (ImageView) convertView.findViewById(R.id.image);

        holder.text = (TextView) convertView.findViewById(R.id.text);
        holder.brand = (TextView) convertView.findViewById(R.id.brand);

        holder.cost = (TextView) convertView.findViewById(R.id.cost);
        holder.saleCost = (TextView) convertView.findViewById(R.id.saleCost);

        convertView.setTag(holder);

    }else {
        holder = (ViewHolder) convertView.getTag();
    } 

    //here I set the values

The list_item:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >

<!-- Image Thumbnail -->

<ImageView
    android:id="@+id/image"
    android:layout_width="100dp"
    android:layout_height="100dp" />

<!-- Name, Brand, and Cost -->

<LinearLayout
    android:id="@+id/nameAlign"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:paddingLeft="10dip" >

    <TextView
        android:id="@+id/brand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/cost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/saleCost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
  </LinearLayout>

</LinearLayout>

And the I take the following errors:

 01-03 17:31:13.055: E/AndroidRuntime(22860): FATAL EXCEPTION: main
 01-03 17:31:13.055: E/AndroidRuntime(22860): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nn/com.nn.HomeScreen}: android.view.InflateException:    Binary XML file line #22: Error inflating class <unknown>
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.os.Handler.dispatchMessage(Handler.java:99)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.os.Looper.loop(Looper.java:130)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.app.ActivityThread.main(ActivityThread.java:3683)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at java.lang.reflect.Method.invokeNative(Native Method)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at java.lang.reflect.Method.invoke(Method.java:507)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at dalvik.system.NativeStart.main(Native Method)
 01-03 17:31:13.055: E/AndroidRuntime(22860): Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class <unknown>
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.createView(LayoutInflater.java:518)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:857)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:218)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at com.nn.HomeScreen.onCreate(HomeScreen.java:205)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   ... 11 more
 01-03 17:31:13.055: E/AndroidRuntime(22860): Caused by: java.lang.reflect.InvocationTargetException
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at java.lang.reflect.Constructor.constructNative(Native Method)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.view.LayoutInflater.createView(LayoutInflater.java:505)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   ... 24 more
 01-03 17:31:13.055: E/AndroidRuntime(22860): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.Bitmap.nativeCreate(Native Method)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.content.res.Resources.loadDrawable(Resources.java:1709)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.widget.ImageView.<init>(ImageView.java:118)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   at android.widget.ImageView.<init>(ImageView.java:108)
 01-03 17:31:13.055: E/AndroidRuntime(22860):   ... 27 more

Can anyone explain me the log file?because I can't understand what is the MAIN problem..

Upvotes: 1

Views: 285

Answers (4)

itsrajesh4uguys
itsrajesh4uguys

Reputation: 4638

Please try like as follows method. and also provide the details about listitem.xml

public View getView(final int position, View convertView, ViewGroup parent) {
            System.out.println("***********IngetView************");
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            //View Listview;
            final ViewHolder viewHolder ;

            if (convertView == null) {
                //viewHolder = new ViewHolder();
                //Listview = new View(context);
                viewHolder = new ViewHolder();
                // get layout from gridlayout.xml
                convertView = inflater.inflate(R.layout.list_item, null);

            } else {
                //Listview = (View) convertView;
                viewHolder = (ViewHolder) convertView.getTag();

            }

Upvotes: 1

Sergey Vakulenko
Sergey Vakulenko

Reputation: 1667

Your bitmap is too big:

01-03 17:31:13.055: E/AndroidRuntime(22860): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Upvotes: 0

koljaTM
koljaTM

Reputation: 10262

The main problem is the

 java.lang.OutOfMemoryError: bitmap size exceeds VM budget

There is only a certain amount of memory allocated to your app for loading bitmaps.

Upvotes: 1

Axarydax
Axarydax

Reputation: 16603

There are "Caused by:" statements in the log, and the main problem is this:

Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class <unknown>

that means you have in the xml file, and xml inflater doesn't know what class Something corresponds to.

Upvotes: -1

Related Questions