-1

<uses-sdk android:minSdkVersion="8"/>当我第一次创建清单文件指定的应用程序时,我有一个正在处理的应用程序。我可以成功登录 mysql/php 网络服务器。

接下来,我将主题更改为 holo dark,为了让它工作,我将 uses-sdk 更改为

<uses-sdk android:minSdkVersion="8" 
          android:targetSdkVersion="18"
          android:maxSdkVersion="18"/>

现在应用程序崩溃了,但只有当我尝试登录时,其他屏幕才能正常工作。

目录显示

09-19 09:06:30.872: W/dalvikvm(835): threadid=1: thread exiting with uncaught exception (group=0x41465700)
09-19 09:06:30.912: E/AndroidRuntime(835): FATAL EXCEPTION: main
09-19 09:06:30.912: E/AndroidRuntime(835): android.os.NetworkOnMainThreadException
09-19 09:06:30.912: E/AndroidRuntime(835):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)
09-19 09:06:30.912: E/AndroidRuntime(835):  at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
09-19 09:06:30.912: E/AndroidRuntime(835):  at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
09-19 09:06:30.912: E/AndroidRuntime(835):  at libcore.io.IoBridge.connect(IoBridge.java:112)
09-19 09:06:30.912: E/AndroidRuntime(835):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
09-19 09:06:30.912: E/AndroidRuntime(835):  at java.net.Socket.connect(Socket.java:842)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-19 09:06:30.912: E/AndroidRuntime(835):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-19 09:06:30.912: E/AndroidRuntime(835):  at library.JSONParser.getJSONFromUrl(JSONParser.java:42)
09-19 09:06:30.912: E/AndroidRuntime(835):  at library.UserFunctions.loginUser(UserFunctions.java:41)
09-19 09:06:30.912: E/AndroidRuntime(835):  at com.test.testapp.LoginActivity$1.onClick(LoginActivity.java:56)
09-19 09:06:30.912: E/AndroidRuntime(835):  at android.view.View.performClick(View.java:4240)
09-19 09:06:30.912: E/AndroidRuntime(835):  at android.view.View$PerformClick.run(View.java:17721)
09-19 09:06:30.912: E/AndroidRuntime(835):  at android.os.Handler.handleCallback(Handler.java:730)
09-19 09:06:30.912: E/AndroidRuntime(835):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-19 09:06:30.912: E/AndroidRuntime(835):  at android.os.Looper.loop(Looper.java:137)
09-19 09:06:30.912: E/AndroidRuntime(835):  at android.app.ActivityThread.main(ActivityThread.java:5103)
09-19 09:06:30.912: E/AndroidRuntime(835):  at java.lang.reflect.Method.invokeNative(Native Method)
09-19 09:06:30.912: E/AndroidRuntime(835):  at java.lang.reflect.Method.invoke(Method.java:525)
09-19 09:06:30.912: E/AndroidRuntime(835):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-19 09:06:30.912: E/AndroidRuntime(835):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-19 09:06:30.912: E/AndroidRuntime(835):  at dalvik.system.NativeStart.main(Native    Method)

如果我将 uses-sdk 改回来,该应用程序会再次运行,但不会显示全息黑暗。有任何想法吗 ?谢谢

编辑 - 这是我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.testapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <!-- Allow to connect with internet -->
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk android:minSdkVersion="8" 
              android:targetSdkVersion="18"
              android:maxSdkVersion="18"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".FirstRunActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!--  Login Activity -->
        <activity
            android:label="@string/app_name"
            android:name=".LoginActivity"></activity>

        <!--  Register Activity -->
        <activity
            android:label="@string/app_name"
            android:name=".RegisterActivity"></activity>

        <!--  Register Device Activity -->
        <activity
            android:label="@string/app_name"
            android:name=".RegisterDeviceActivity"></activity>

         <!--  Dashboard Activity -->
        <activity
            android:label="@string/app_name"
            android:name=".DashboardActivity"></activity>
    </application>



</manifest>
4

1 回答 1

2

当应用程序尝试在其主线程上执行网络操作时引发的异常。这仅针对面向 Honeycomb SDK 或更高版本的应用程序抛出。允许以早期 SDK 版本为目标的应用程序在其主事件循环线程上进行网络连接,但非常不鼓励这样做。

参考:NetworkOnMainThreadException

并阅读连接到网络


您正在从主线程调用网络相关的东西。使用来自另一个线程的那些/那个方法。

阅读更多关于如何修复 android.os.NetworkOnMainThreadException?

于 2013-09-19T13:18:54.923 回答