0

我有一个带有主要活动(MainMenu)的android应用程序。有时当我运行它时,我会收到以下错误。

这不会一直发生......这是一个简单的活动,在layput中有几张图片。

错误

01-11 17:58:45.638: E/AndroidRuntime(13960): FATAL EXCEPTION: main
01-11 17:58:45.638: E/AndroidRuntime(13960): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycity.roshhaayn/com.city.base.MainMenu}: android.view.InflateException: Binary XML file line #85: Error inflating class <unknown>
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.os.Looper.loop(Looper.java:137)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.ActivityThread.main(ActivityThread.java:4511)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at java.lang.reflect.Method.invokeNative(Native Method)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at java.lang.reflect.Method.invoke(Method.java:511)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at dalvik.system.NativeStart.main(Native Method)
01-11 17:58:45.638: E/AndroidRuntime(13960): Caused by: android.view.InflateException: Binary XML file line #85: Error inflating class <unknown>
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.Activity.setContentView(Activity.java:1835)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at com.city.base.MainMenu.onCreate(MainMenu.java:72)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.Activity.performCreate(Activity.java:4470)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-11 17:58:45.638: E/AndroidRuntime(13960):    ... 11 more
01-11 17:58:45.638: E/AndroidRuntime(13960): Caused by: java.lang.reflect.InvocationTargetException
01-11 17:58:45.638: E/AndroidRuntime(13960):    at java.lang.reflect.Constructor.constructNative(Native Method)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.LayoutInflater.createView(LayoutInflater.java:586)
01-11 17:58:45.638: E/AndroidRuntime(13960):    ... 25 more
01-11 17:58:45.638: E/AndroidRuntime(13960): Caused by: java.lang.OutOfMemoryError
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.Bitmap.nativeCreate(Native Method)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:618)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:593)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:445)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.content.res.Resources.loadDrawable(Resources.java:1968)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.content.res.Resources.getDrawable(Resources.java:677)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:867)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.content.res.Resources.loadDrawable(Resources.java:1953)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.View.<init>(View.java:2841)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.View.<init>(View.java:2778)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.view.ViewGroup.<init>(ViewGroup.java:380)
01-11 17:58:45.638: E/AndroidRuntime(13960):    at android.widget.RelativeLayout.<init>(RelativeLayout.java:174)
01-11 17:58:45.638: E/AndroidRuntime(13960):    ... 28 more         '

我的活动是:

    public class MainMenu extends CityBase
    {

        RelativeLayout messenger;
        RelativeLayout contact_center;
        RelativeLayout settings;
        RelativeLayout facebook;
        RelativeLayout web;


        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.main_menu);

            //LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
            //LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.mm_btns, null);

            //LinearLayout bigLL = (LinearLayout) findViewById(R.id.big_lay);
            //bigLL.addView(ll);

            messenger = (RelativeLayout) findViewById(R.id.messenger);  
            messenger.setOnClickListener(new OnClickListener() {    
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getApplicationContext(), Messenger.class);
                    startActivity(intent);

                }
            });

            contact_center = (RelativeLayout) findViewById(R.id.contact_center);    
            contact_center.setOnClickListener(new OnClickListener() {   
                @Override
                public void onClick(View v) {
                    Intent intent_c_m = new Intent(getApplicationContext(),ContactCenter.class);
                    startActivity(intent_c_m);

                }
            });

            Button web = (Button) findViewById(R.id.web_icon);
            //web.setBackgroundResource(R.drawable.arrow_green);
            web.setOnClickListener(new OnClickListener() {  
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(AppDelegate.WEBSITE_URL));
                    startActivity(i);

                }
            });

            Button facebookBtn = (Button) findViewById(R.id.facebook_icon);
            //facebookBtn.setBackgroundResource(R.drawable.arrow_green);
            facebookBtn.setOnClickListener(new OnClickListener() {  
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(AppDelegate.FACEBOOK_URL));
                    startActivity(intent);

                }
            });


            Button profile = (Button) findViewById(R.id.settings_icon); 
            //profile.setBackgroundResource(R.drawable.arrow_green);
            profile.setOnClickListener(new OnClickListener() {  
                @Override
                public void onClick(View v) {

                    SharedPreferences sp = getSharedPreferences("user_data",0);
                    Editor edit = sp.edit();
                    edit.putString("mode", "update");
                    edit.commit();

                    Intent intent = new Intent(getApplicationContext(), RegisterBase.class);
                    startActivity(intent);

                }
            });
            Button dialer = (Button) findViewById(R.id.dialer_icon);
            //dialer.setBackgroundResource(R.drawable.arrow_green);
            dialer.setOnClickListener(new OnClickListener() {   
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getApplicationContext(), CityDialer.class);
                    startActivity(intent);
                }
            });


        }

         private void unbindDrawables(View view) {
                if (view.getBackground() != null) {
                view.getBackground().setCallback(null);
                }
                if (view instanceof ViewGroup) {
                    for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                    unbindDrawables(((ViewGroup) view).getChildAt(i));
                    }
                ((ViewGroup) view).removeAllViews();
                }
            }

        @Override
        protected void onDestroy() {
            // TODO Auto-generated method stub
            super.onDestroy();
               unbindDrawables(findViewById(R.id.huge_lay));
               //unbindDrawables(findViewById(R.id.contact_center));
                System.gc();
                Runtime.getRuntime().gc();
        }  '

我的 XML 是:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/huge_lay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/back_texture"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/big_lay"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:orientation="vertical" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="150dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:contentDescription="Logo for the city of Rosh-Ha&apos;ayin"
                android:src="@drawable/rosh_new_logo2" />

            <RelativeLayout
                android:id="@+id/messenger"
                android:layout_width="wrap_content"
                android:layout_height="76dp"
                android:background="@drawable/mm_messages" >

                <ImageView
                    android:id="@+id/messages_icon"
                    android:layout_width="68dp"
                    android:layout_height="68dp"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="8dp"
                    android:src="@drawable/icon_messages"
                    android:visibility="invisible" />

                <RelativeLayout
                    android:id="@+id/text_msgs"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="5dp"
                    android:layout_toLeftOf="@+id/messages_icon" >

                    <TextView
                        android:id="@+id/messages_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:text="@string/your_messages"
                        android:textColor="@color/grey"
                        android:textSize="20dp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_below="@+id/messages_title"
                        android:text="@string/your_messages_desc"
                        android:textColor="@color/grey"
                        android:textSize="13sp" />

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_below="@+id/textView1"
                        android:text="@string/your_messages_desc2"
                        android:textColor="@color/grey"
                        android:textSize="13sp" />
                </RelativeLayout>




            </RelativeLayout>


            <RelativeLayout
                android:id="@+id/contact_center"
                android:layout_width="wrap_content"
                android:layout_height="76dp"
                android:background="@drawable/cc_messages" >

             <ImageView
                    android:id="@+id/messages_icon1"
                    android:layout_width="68dp"
                    android:layout_height="68dp"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="8dp"
                    android:src="@drawable/icon_messages"
                    android:visibility="invisible" />

                <RelativeLayout
                    android:id="@+id/text_msgs1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="5dp"
                    android:layout_toLeftOf="@+id/messages_icon1" >

                    <TextView
                        android:id="@+id/messages_title1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:text="@string/contact_moked_menu"
                        android:textColor="@color/grey"
                        android:textSize="20dp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/textView11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"

                        android:layout_below="@+id/messages_title1"
                        android:text="@string/contact_moked_desc_menu"
                        android:textColor="@color/grey"
                        android:textSize="13sp" />                
                </RelativeLayout>


            </RelativeLayout>

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="12dp"
                android:orientation="horizontal" >

                <RelativeLayout
                    android:id="@+id/settings"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="6dp" >

                    <Button
                        android:id="@+id/settings_icon"
                        android:layout_width="68dp"
                        android:layout_height="68dp"
                        android:background="@drawable/mm_profile"
                         />
    <!--  -->
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/settings_icon"
                        android:layout_centerInParent="true"
                        android:gravity="center_vertical"
                        android:text="@string/profile"
                        android:textColor="@color/black" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/web"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="6dp" >

                    <Button
                        android:id="@+id/web_icon"
                        android:layout_width="68dp"
                        android:layout_height="68dp"
                        android:background="@drawable/mm_website"
                         />
    <!--  -->
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/web_icon"
                        android:layout_centerInParent="true"
                        android:gravity="center"
                        android:text="@string/web"
                        android:textColor="@color/black" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/facebook"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="6dp" >

                    <Button
                        android:id="@+id/facebook_icon"
                        android:layout_width="68dp"
                        android:layout_height="68dp"
                        android:background="@drawable/mm_facebook"
                         />
                    <!--  -->

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/facebook_icon"
                        android:layout_centerInParent="true"
                        android:gravity="center_vertical"
                        android:text="@string/facebook"
                        android:textColor="@color/black" />
                </RelativeLayout>


                <RelativeLayout
                    android:id="@+id/dialer"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <!--  -->

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:text="@string/dialer"
                        android:textColor="@color/black" />

                    <Button
                        android:id="@+id/dialer_icon"
                        android:layout_width="68dp"
                        android:layout_height="68dp"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:background="@drawable/mm_fast_dial" />
                </RelativeLayout>

            </LinearLayout>
        </LinearLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="10dp" >

            <ImageView
                android:id="@+id/bottom_logo"
                android:layout_width="200dp"
                android:layout_height="30dp"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:src="@drawable/my_city_bottom_logo" />
        </RelativeLayout>

    </RelativeLayout>

请帮忙,谢谢

4

1 回答 1

0

Issue is with your images. Looks like you are loading heavy images.

于 2013-01-11T19:35:59.587 回答