java– 我的应用程序适用于姜饼…崩溃ICS和HC

java– 我的应用程序适用于姜饼…崩溃ICS和HC,第1张

概述我需要你的帮助.我的应用程序在GingerBread上工作正常,但在ICS和HC崩溃.这是logcat01-1420:26:51.831:E/AndroidRuntime(698):FATALEXCEPTION:main01-1420:26:51.831:E/AndroidRuntime(698):android.os.NetworkOnMainThreadException01-1420:26:51.831:E/AndroidRun

我需要你的帮助.
我的应用程序在GingerBread上工作正常,但在ICS和HC崩溃.
这是logcat

01-14 20:26:51.831: E/AndroIDRuntime(698): FATAL EXCEPTION: main01-14 20:26:51.831: E/AndroIDRuntime(698): androID.os.@R_502_663@Exception01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.os.StrictMode$AndroIDBlockGuardPolicy.onNetwork(StrictMode.java:1099)01-14 20:26:51.831: E/AndroIDRuntime(698):  at java.net.InetAddress.lookupHostByname(InetAddress.java:391)01-14 20:26:51.831: E/AndroIDRuntime(698):  at java.net.InetAddress.getAllBynameImpl(InetAddress.java:242)01-14 20:26:51.831: E/AndroIDRuntime(698):  at java.net.InetAddress.getAllByname(InetAddress.java:220)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpconnection.<init>(httpconnection.java:71)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpconnection.<init>(httpconnection.java:50)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpconnection$Address.connect(httpconnection.java:351)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpconnectionPool.get(httpconnectionPool.java:86)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpconnection.connect(httpconnection.java:128)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpEngine.openSocketConnection(httpEngine.java:308)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpEngine.connect(httpEngine.java:303)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpEngine.sendSocketRequest(httpEngine.java:282)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpEngine.sendRequest(httpEngine.java:232)01-14 20:26:51.831: E/AndroIDRuntime(698):  at libcore.net.http.httpURLConnectionImpl.connect(httpURLConnectionImpl.java:80)01-14 20:26:51.831: E/AndroIDRuntime(698):  at com.bozz.milaircraft.f23$ImageAdapter.getVIEw(f23.java:125)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.Absspinner.onMeasure(Absspinner.java:192)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4698)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1369)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.measureVertical(linearLayout.java:660)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.onMeasure(linearLayout.java:553)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4698)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:293)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4698)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1369)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.measureVertical(linearLayout.java:660)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.onMeasure(linearLayout.java:553)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4698)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:293)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4698)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1369)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.measureVertical(linearLayout.java:660)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.onMeasure(linearLayout.java:553)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4698)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:293)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.measureVertical(linearLayout.java:812)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.linearLayout.onMeasure(linearLayout.java:553)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4698)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:293)01-14 20:26:51.831: E/AndroIDRuntime(698):  at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.onMeasure(PhoneWindow.java:2092)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEw.measure(VIEw.java:12723)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwRootImpl.performTraversals(VIEwRootImpl.java:1064)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.vIEw.VIEwRootImpl.handleMessage(VIEwRootImpl.java:2442)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.os.Handler.dispatchMessage(Handler.java:99)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.os.Looper.loop(Looper.java:137)01-14 20:26:51.831: E/AndroIDRuntime(698):  at androID.app.ActivityThread.main(ActivityThread.java:4424)01-14 20:26:51.831: E/AndroIDRuntime(698):  at java.lang.reflect.Method.invokeNative(Native Method)01-14 20:26:51.831: E/AndroIDRuntime(698):  at java.lang.reflect.Method.invoke(Method.java:511)01-14 20:26:51.831: E/AndroIDRuntime(698):  at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)01-14 20:26:51.831: E/AndroIDRuntime(698):  at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551)01-14 20:26:51.831: E/AndroIDRuntime(698):  at dalvik.system.NativeStart.main(Native Method)

这是layout.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="vertical" >    <linearLayout        androID:ID="@+ID/linearLayout3"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:background="#000"        androID:paddingBottom="5dp"        androID:paddingtop="5dp" >        <button            androID:ID="@+ID/homebutton"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_gravity="center"            androID:background="@drawable/homebutton" />        <TextVIEw            androID:ID="@+ID/textVIEw1"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_gravity="center"            androID:layout_weight="1"            androID:gravity="center"            androID:text="@string/nomeF22Raptor"            androID:textcolor="#FFD800"            androID:textSize="22dp"            androID:textStyle="bold" />        <button            androID:ID="@+ID/searchbutton"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_gravity="center"            androID:background="@drawable/searchbutton" >        </button>    </linearLayout>    <TabHost        androID:ID="@+ID/tabhost"        androID:layout_wIDth="match_parent"        androID:layout_height="420dp"        androID:layout_weight="0.80"        androID:background="@drawable/background" >        <linearLayout            androID:ID="@+ID/linearLayout1"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:orIEntation="vertical" >            <TabWidget                androID:ID="@androID:ID/tabs"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content" >            </TabWidget>            <FrameLayout                androID:ID="@androID:ID/tabcontent"                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent" >                <linearLayout                    androID:ID="@+ID/tab1"                    androID:layout_wIDth="match_parent"                    androID:layout_height="match_parent" >                    <ScrollVIEw                        androID:ID="@+ID/ScrollVIEw01"                        androID:layout_wIDth="fill_parent"                        androID:layout_height="wrap_content" >                        <linearLayout                            androID:ID="@+ID/linearLayout2"                            androID:layout_wIDth="fill_parent"                            androID:layout_height="wrap_content"                            androID:orIEntation="vertical" >                            <TextVIEw                                androID:ID="@+ID/textVIEw1"                                androID:layout_wIDth="wrap_content"                                androID:layout_height="wrap_content"                                androID:text="@string/datiF22Raptor" />                        </linearLayout>                    </ScrollVIEw>                </linearLayout>                <linearLayout                    androID:ID="@+ID/tab2"                    androID:layout_wIDth="match_parent"                    androID:layout_height="match_parent" >                    <ScrollVIEw                        androID:ID="@+ID/ScrollVIEw01"                        androID:layout_wIDth="fill_parent"                        androID:layout_height="wrap_content" >                        <linearLayout                            androID:ID="@+ID/linearLayout2"                            androID:layout_wIDth="fill_parent"                            androID:layout_height="wrap_content"                            androID:orIEntation="vertical" >                            <TextVIEw                                androID:ID="@+ID/textVIEw1"                                androID:layout_wIDth="wrap_content"                                androID:layout_height="wrap_content"                                androID:text="@string/cartecF22Raptor" />                        </linearLayout>                    </ScrollVIEw>                </linearLayout>                <linearLayout                    androID:ID="@+ID/tab3"                    androID:layout_wIDth="match_parent"                    androID:layout_height="match_parent" >                    <ScrollVIEw                        androID:ID="@+ID/ScrollVIEw01"                        androID:layout_wIDth="fill_parent"                        androID:layout_height="wrap_content" >                        <linearLayout                            androID:ID="@+ID/linearLayout2"                            androID:layout_wIDth="fill_parent"                            androID:layout_height="wrap_content"                            androID:orIEntation="vertical" >                            <TextVIEw                                androID:ID="@+ID/textVIEw1"                                androID:layout_wIDth="wrap_content"                                androID:layout_height="wrap_content"                                androID:text="@string/utilizzatoriF22Raptor" />                        </linearLayout>                    </ScrollVIEw>                </linearLayout>                <linearLayout                    androID:ID="@+ID/tab4"                    androID:layout_wIDth="match_parent"                    androID:layout_height="match_parent"                    androID:orIEntation="vertical" >                    <gallery                        androID:ID="@+ID/gallery"                        androID:layout_wIDth="fill_parent"                        androID:layout_height="fill_parent"/>                    <ImageVIEw                        androID:ID="@+ID/ImageVIEw01"                        androID:layout_wIDth="wrap_content"                        androID:layout_height="fill_parent"                        androID:layout_gravity="center" >                    </ImageVIEw>                </linearLayout>            </FrameLayout>        </linearLayout>    </TabHost></linearLayout>

这是java代码

import java.io.BufferedinputStream;import java.io.IOException;import java.io.inputStream;import java.net.URL;import java.net.URLConnection;import androID.app.Activity;import androID.content.Context;import androID.content.Intent;import androID.graphics.Bitmap;import androID.graphics.BitmapFactory;import androID.os.Bundle;import androID.util.Log;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.BaseAdapter;import androID.Widget.button;import androID.Widget.gallery;import androID.Widget.ImageVIEw;import androID.Widget.TabHost;import androID.Widget.TabHost.TabSpec;public class f23 extends Activity {    /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.f23);        button bhome = (button) findVIEwByID(R.ID.homebutton);        bhome.setonClickListener(new VIEw.OnClickListener() {            public voID onClick(VIEw v) {                // Todo auto-generated method stub                startActivity(new Intent("com.bozz.milaircraft.MENU"));            }        });        TabHost th = (TabHost) findVIEwByID(R.ID.tabhost);        th.setup();        TabSpec specs = th.newTabSpec("tag1");        specs.setContent(R.ID.tab1);        specs.setIndicator("BRIEFING");        th.addTab(specs);        specs = th.newTabSpec("tag2");        specs.setContent(R.ID.tab2);        specs.setIndicator("DESIGN");        th.addTab(specs);        specs = th.newTabSpec("tag3");        specs.setContent(R.ID.tab3);        specs.setIndicator("USERS");        th.addTab(specs);        specs = th.newTabSpec("tag4");        specs.setContent(R.ID.tab4);        specs.setIndicator("galLERY");        th.addTab(specs);        gallery ga = (gallery) findVIEwByID(R.ID.gallery);        ga.setAdapter(new ImageAdapter(this));    }    public class ImageAdapter extends BaseAdapter {        /** The parent context */        private Context myContext;        int imagebackground;        /** URL-Strings to some remote images. */        private String[] myRemoteImages = {                "http://www.medicinarozzano.it/images/milair/f4_1.jpg",                "http://www.medicinarozzano.it/images/milair/f4_2.jpg",                "http://www.medicinarozzano.it/images/milair/f4_3.jpg",                "http://www.medicinarozzano.it/images/milair/f4_4.jpg",                "http://www.medicinarozzano.it/images/milair/f4_5.jpg",                "http://www.medicinarozzano.it/images/milair/f4_6.jpg",                "http://www.medicinarozzano.it/images/milair/f4_7.jpg",                "http://www.medicinarozzano.it/images/milair/f4_8.jpg",                "http://www.medicinarozzano.it/images/milair/f4_9.jpg",                "http://www.medicinarozzano.it/images/milair/f4_10.jpg"};        /** Simple Constructor saving the 'parent' context. */        public ImageAdapter(Context c) {            this.myContext = c;        }        /** Returns the amount of images we have defined. */        public int getCount() {            return this.myRemoteImages.length;        }        /* Use the array-positions as unique IDs */        public Object getItem(int position) {            return position;        }        public long getItemID(int position) {            return position;        }        /**         * Returns a new ImageVIEw to be displayed, depending on the position         * passed.         */        public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) {            ImageVIEw i = new ImageVIEw(this.myContext);            try {                /* Open a new URL and get the inputStream to load data from it. */                URL aURL = new URL(myRemoteImages[position]);                URLConnection conn = aURL.openConnection();                conn.connect();                inputStream is = conn.getinputStream();                /* Buffered is always good for a performance plus. */                BufferedinputStream bis = new BufferedinputStream(is);                /* Decode url-data to a bitmap. */                Bitmap bm = BitmapFactory.decodeStream(bis);                bis.close();                is.close();                /* Apply the Bitmap to the ImageVIEw that will be returned. */                i.setimageBitmap(bm);            } catch (IOException e) {                i.setimageResource(R.drawable.f4_1);                Log.e("DEBUGTAG", "Remote Image Exception", e);            }            /* Image should be scaled as wIDth/height are set. */            i.setScaleType(ImageVIEw.ScaleType.CENTER_INSIDE);            /* Set the WIDth/Height of the ImageVIEw. */            i.setLayoutParams(new gallery.LayoutParams(480, 640));            return i;        }        /**         * Returns the size (0.0f to 1.0f) of the vIEws depending on the         * 'offset' to the center.         */        public float getScale(boolean focused, int offset) {            /* Formula: 1 / (2 ^ offset) */            return Math.max(0, 1.0f / (float) Math.pow(2, Math.abs(offset)));        }    }}

单击“图库”选项卡时,应用程序崩溃.

解决方法:

在您的应用程序主线程上执行(可能阻止)网络 *** 作是一个坏主意,这就是您正在做的事情.在Honeycomb(AndroID 3.0)之前,这只是一个坏主意.从AndroID 3.0开始,它是禁止的,如果您尝试这样做,则会收到此异常.

见http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

您需要将此网络逻辑分配到单独的异步线程.或者,看看处理程序.您将需要更改代码体系结构;不容易解决.

总结

以上是内存溢出为你收集整理的java – 我的应用程序适用于姜饼…崩溃ICS和HC全部内容,希望文章能够帮你解决java – 我的应用程序适用于姜饼…崩溃ICS和HC所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120129.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存