-1

I have an application that I am working on, when I first created the app the manifest file had <uses-sdk android:minSdkVersion="8"/> specified. I can successfully login an against a mysql/php webserver.

Next, I changed the theme to holo dark, to get it to work , I changed the uses-sdk to

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

Now the application is crashing, but only when I try to login , the other screens work fine.

Catlog shows

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)

If I change the uses-sdk back , the app works again but holo dark isnt displayed. Any ideas ? Thanks

EDIT - here is my manifest file

<?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>
Gary
  • 377
  • 1
  • 6
  • 22
  • See here: http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception – laalto Sep 19 '13 at 13:18
  • I think you are missing a use-permission, can you post your full Manifest? You need the and also it has to be a non-uI thread – Hector Sanchez Sep 19 '13 at 13:19

1 Answers1

2

The exception that is thrown when an application attempts to perform a networking operation on its main thread. This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged.

Ref : NetworkOnMainThreadException

And read Connecting to the Network


You are calling network related stuffs from main Thread. Use those/ that method from another Thread.

Read more about How to fix android.os.NetworkOnMainThreadException?

Community
  • 1
  • 1
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186