- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要你的帮助。我的应用程序在 GingerBread 上运行良好,但在 ICS 和 HC 上崩溃。这是日志
01-14 20:26:51.831: E/AndroidRuntime(698): FATAL EXCEPTION: main
01-14 20:26:51.831: E/AndroidRuntime(698): android.os.NetworkOnMainThreadException
01-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
您需要将此网络逻辑外包给单独的异步线程。或者,查看 Handler
。您将需要更改代码架构;没有简单的解决办法。
关于java - 我的应用程序适用于 Gingerbread ......在 ICS 和 HC 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8865213/
我在我的 Xcode 项目目录中输入了以下内容: keytool -genkey -v -keystore release.keystore -alias mykey -keyalg RSA \
假设我有一个像这样的 DataFrame(或 Series): Value 0 0.5 1 0.8 2 -0.2 3 None 4 None 5 None
我正在对一个 Pandas 系列进行相对繁重的应用。有什么方法可以返回一些打印反馈,说明每次调用函数时在函数内部进行打印还有多远? 最佳答案 您可以使用跟踪器包装您的函数。以下两个示例,一个基于完成的
我有一个 DataFrame,其中一列包含列表作为单元格内容,如下所示: import pandas as pd df = pd.DataFrame({ 'col_lists': [[1, 2
我想使用 Pandas df.apply 但仅限于某些行 作为一个例子,我想做这样的事情,但我的实际问题有点复杂: import pandas as pd import math z = pd.Dat
我有以下 Pandas 数据框 id dist ds 0 0 0 0 5 1 0 0 7 2 0 0
这发生在我尝试使用 Gradle 构建时。由于字符串是对象,因此似乎没有理由发生此错误: No signature of method: java.util.HashMap.getOrDefault(
您好,有人可以解释为什么在 remaining() 函数中的 Backbone 示例应用程序 ( http://backbonejs.org/examples/todos/index.html ) 中
我有两个域类:用户 class User { String username String password String email Date dateCreated
问题陈述: 一个 pandas dataframe 列系列,same_group 需要根据两个现有列 row 和 col 的值从 bool 值创建。如果两个值在字典 memberships 中具有相似
apporable 报告以下错误: error: unknown type name 'MKMapItem'; did you mean 'MKMapView'? MKMapItem* destina
我有一个带有地址列的大型 DataFrame: data addr 0 0.617964 IN,Krishnagiri,635115 1 0.635428 IN,Chennai
我有一个列表list,里面有这样的项目 ElementA: Number=1, Version=1 ElementB: Number=1, Version=2 ElementC: Number=1,
我正在编译我的源代码,它只是在没有运行应用程序的情况下终止。这是我得到的日志: Build/android-armeabi-debug/com.app4u.portaldorugby/PortalDo
我正在尝试根据另一个单元格的值更改单元格值(颜色“红色”或“绿色”)。我运行以下命令: df.loc[0, 'Colour'] = df.loc[0, 'Count'].apply(lambda x:
我想弄清楚如何使用 StateT结合两个 State基于对我的 Scalaz state monad examples 的评论的状态转换器回答。 看来我已经很接近了,但是在尝试申请 sequence
如果我已经为它绑定(bind)了集合,我该如何添加 RibbonLibrary 默认的快速访问项容器。当我从 UI 添加快速访问工具项时,它会抛出 Operation is not valid whi
在我学习期间Typoclassopedia我遇到了这个证明,但我不确定我的证明是否正确。问题是: One might imagine a variant of the interchange law
我是一名优秀的程序员,十分优秀!