how to reach my locahost DB from android phone [duplicate] - android

This question already has answers here:
NetworkOnMainThreadException [duplicate]
(5 answers)
Closed 9 years ago.
I have developed an Android and now I want to test it in my real phone
this app has a webserivice for user reg. and login, also it has a xampp server hosting my DB and a forum which I access from the app.
can soembody plz help to figure out why I can't use it in my device
here is my logcat
03-10 17:54:56.360: E/SensorManager(2377): thread start
03-10 17:54:56.555: E/SpannableStringBuilder(2377): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-10 17:54:56.555: E/SpannableStringBuilder(2377): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-10 17:56:06.415: E/SpannableStringBuilder(2377): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-10 17:56:06.415: E/SpannableStringBuilder(2377): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-10 17:56:12.920: E/AndroidRuntime(2377): FATAL EXCEPTION: main
03-10 17:56:12.920: E/AndroidRuntime(2377): android.os.NetworkOnMainThreadException
03-10 17:56:12.920: E/AndroidRuntime(2377): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
03-10 17:56:12.920: E/AndroidRuntime(2377): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
03-10 17:56:12.920: E/AndroidRuntime(2377): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
03-10 17:56:12.920: E/AndroidRuntime(2377): at libcore.io.IoBridge.connect(IoBridge.java:112)
03-10 17:56:12.920: E/AndroidRuntime(2377): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
03-10 17:56:12.920: E/AndroidRuntime(2377): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
03-10 17:56:12.920: E/AndroidRuntime(2377): at java.net.Socket.connect(Socket.java:842)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
03-10 17:56:12.920: E/AndroidRuntime(2377): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-10 17:56:12.920: E/AndroidRuntime(2377): at com.mohammed.watzIslam.library.JSONParser.getJSONFromUrl(JSONParser.java:44)
03-10 17:56:12.920: E/AndroidRuntime(2377): at com.mohammed.watzIslam.library.UserFunctions.loginUser(UserFunctions.java:39)
03-10 17:56:12.920: E/AndroidRuntime(2377): at com.mohammed.watzIslam.LoginActivity$1.onClick(LoginActivity.java:59)
03-10 17:56:12.920: E/AndroidRuntime(2377): at android.view.View.performClick(View.java:4211)
03-10 17:56:12.920: E/AndroidRuntime(2377): at android.view.View$PerformClick.run(View.java:17267)
03-10 17:56:12.920: E/AndroidRuntime(2377): at android.os.Handler.handleCallback(Handler.java:615)
03-10 17:56:12.920: E/AndroidRuntime(2377): at android.os.Handler.dispatchMessage(Handler.java:92)
03-10 17:56:12.920: E/AndroidRuntime(2377): at android.os.Looper.loop(Looper.java:137)
03-10 17:56:12.920: E/AndroidRuntime(2377): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-10 17:56:12.920: E/AndroidRuntime(2377): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 17:56:12.920: E/AndroidRuntime(2377): at java.lang.reflect.Method.invoke(Method.java:511)
03-10 17:56:12.920: E/AndroidRuntime(2377): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-10 17:56:12.920: E/AndroidRuntime(2377): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-10 17:56:12.920: E/AndroidRuntime(2377): at dalvik.system.NativeStart.main(Native Method)
any help is appreciated

You're doing network stuff on the main thread. Don't do that. Use AsyncTasks instead.

Related

Genymotion emulator crashes when logging in

My app crashes when trying to verify username and password from mySQL database (logging in). This is verified on an AsyncTask method. It works fine on the normal Eclipse emulator. Are there any settings or tweaks to be done? Does it crash coz of the AsyncTask, or is there any other factor?
Here's the logcat:
03-14 17:01:57.755: W/EGL_genymotion(2395): eglSurfaceAttrib not implemented
03-14 17:03:00.862: W/System.err(2395): org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2 refused
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.library.JSONParser.getJSONFromUrl(JSONParser.java:33)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.library.UserFunctions.loginUser(UserFunctions.java:35)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.Login$ProcessLogin.doInBackground(Login.java:204)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.Login$ProcessLogin.doInBackground(Login.java:1)
03-14 17:03:00.862: W/System.err(2395): at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-14 17:03:00.862: W/System.err(2395): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-14 17:03:00.862: W/System.err(2395): at java.lang.Thread.run(Thread.java:856)
03-14 17:03:00.862: W/System.err(2395): Caused by: java.net.ConnectException: failed to connect to /10.0.2.2 (port 80): connect failed: ETIMEDOUT (Connection timed out)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.IoBridge.connect(IoBridge.java:114)
03-14 17:03:00.862: W/System.err(2395): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
03-14 17:03:00.862: W/System.err(2395): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
03-14 17:03:00.862: W/System.err(2395): at java.net.Socket.connect(Socket.java:842)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
03-14 17:03:00.862: W/System.err(2395): ... 17 more
03-14 17:03:00.862: W/System.err(2395): Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.Posix.connect(Native Method)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.IoBridge.connect(IoBridge.java:112)
03-14 17:03:00.862: W/System.err(2395): ... 22 more
03-14 17:03:00.862: E/Buffer Error(2395): Error converting result java.lang.NullPointerException
03-14 17:03:00.862: E/JSON Parser(2395): Error parsing data org.json.JSONException: End of input at character 0 of
03-14 17:03:00.878: D/AndroidRuntime(2395): Shutting down VM
03-14 17:03:00.878: W/dalvikvm(2395): threadid=1: thread exiting with uncaught exception (group=0xa62d0288)
03-14 17:03:00.878: E/AndroidRuntime(2395): FATAL EXCEPTION: main
03-14 17:03:00.878: E/AndroidRuntime(2395): java.lang.NullPointerException
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.example.shareity.Login$ProcessLogin.onPostExecute(Login.java:210)
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.example.shareity.Login$ProcessLogin.onPostExecute(Login.java:1)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.AsyncTask.finish(AsyncTask.java:631)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.Looper.loop(Looper.java:137)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-14 17:03:00.878: E/AndroidRuntime(2395): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 17:03:00.878: E/AndroidRuntime(2395): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-14 17:03:00.878: E/AndroidRuntime(2395): at dalvik.system.NativeStart.main(Native Method)
03-14 17:08:00.935: I/Process(2395): Sending signal. PID: 2395 SIG: 9

I tried to connect to my web service using JSON in my android app, but I got this error:

E/test(20965): Exception E/AndroidRuntime(20965): FATAL EXCEPTION:
main E/AndroidRuntime(20965): java.lang.RuntimeException: Unable to
start activity
ComponentInfo{sliit.mad.contact_list/sliit.mad.contact_list.TEST}:
android.os.NetworkOnMainThreadException E/AndroidRuntime(20965): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2062)
E/AndroidRuntime(20965): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
E/AndroidRuntime(20965): at
android.app.ActivityThread.access$600(ActivityThread.java:133)
E/AndroidRuntime(20965): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
E/AndroidRuntime(20965): at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(20965): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(20965): at
android.app.ActivityThread.main(ActivityThread.java:4793)
E/AndroidRuntime(20965):at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(20965):at
java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(20965):at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
E/AndroidRuntime(20965): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
E/AndroidRuntime(20965):at dalvik.system.NativeStart.main(Native
Method) E/AndroidRuntime(20965): Caused by:
android.os.NetworkOnMainThreadException E/AndroidRuntime(20965):at
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
E/AndroidRuntime(20965):at
libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
E/AndroidRuntime(20965):at
libcore.io.IoBridge.connectErrno(IoBridge.java:127)
E/AndroidRuntime(20965):at
libcore.io.IoBridge.connect(IoBridge.java:112)
E/AndroidRuntime(20965):at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
E/AndroidRuntime(20965):at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
E/AndroidRuntime(20965):at java.net.Socket.connect(Socket.java:832)
E/AndroidRuntime(20965):at
org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
E/AndroidRuntime(20965):at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
E/AndroidRuntime(20965):at
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
E/AndroidRuntime(20965):at
org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
E/AndroidRuntime(20965):at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
E/AndroidRuntime(20965):at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
E/AndroidRuntime(20965):at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
E/AndroidRuntime(20965):at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
E/AndroidRuntime(20965):at
sliit.mad.contact_list.JSONParser.makeHttpRequest(JSONParser.java:65)
E/AndroidRuntime(20965):at
sliit.mad.contact_list.TEST.onCreate(TEST.java:38)
E/AndroidRuntime(20965):at
android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime(20965): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime(20965):at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2026)
E/AndroidRuntime(20965):... 11 more
Maybe you already had fixed this issue. but this issue was caused by that you tried to do network operation in the main UI thread and that is not allowed.
The exception log can explain itself.
E/AndroidRuntime(20965): Caused by: android.os.NetworkOnMainThreadException E/AndroidRuntime(20965):at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)

Running empty Android program - is this behavior expected?

I'm learning the basics of Android development and I've ran into some issues with setting up the programming environment. Now I've created a new Android Application Project and I'm running it using my phone. When I do, I get an error message on my phone: "Unfortunately, HelloWorld has stopped." and I'm not sure if it's supposed to or not, considering that I've done absolutely nothing to the project files. Here is the LogCat output in its entirety:
03-10 18:34:16.264: D/dalvikvm(2673): Late-enabling CheckJNI
03-10 18:34:16.361: W/dalvikvm(2673): VFY: unable to resolve static field 1559 (ActionBarWindow) in Landroid/support/v7/appcompat/R$styleable;
03-10 18:34:16.361: D/dalvikvm(2673): VFY: replacing opcode 0x62 at 0x0004
03-10 18:34:16.364: D/AndroidRuntime(2673): Shutting down VM
03-10 18:34:16.364: W/dalvikvm(2673): threadid=1: thread exiting with uncaught exception (group=0x416d7d40)
03-10 18:34:16.368: E/AndroidRuntime(2673): FATAL EXCEPTION: main
03-10 18:34:16.368: E/AndroidRuntime(2673): Process: com.example.helloworld, PID: 2673
03-10 18:34:16.368: E/AndroidRuntime(2673): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
03-10 18:34:16.368: E/AndroidRuntime(2673): at com.example.helloworld.MainActivity.onCreate(MainActivity.java:18)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.app.Activity.performCreate(Activity.java:5248)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.app.ActivityThread.access$800(ActivityThread.java:139)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.os.Handler.dispatchMessage(Handler.java:102)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.os.Looper.loop(Looper.java:136)
03-10 18:34:16.368: E/AndroidRuntime(2673): at android.app.ActivityThread.main(ActivityThread.java:5102)
03-10 18:34:16.368: E/AndroidRuntime(2673): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 18:34:16.368: E/AndroidRuntime(2673): at java.lang.reflect.Method.invoke(Method.java:515)
03-10 18:34:16.368: E/AndroidRuntime(2673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-10 18:34:16.368: E/AndroidRuntime(2673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-10 18:34:16.368: E/AndroidRuntime(2673): at dalvik.system.NativeStart.main(Native Method)
03-10 18:34:18.259: I/Process(2673): Sending signal. PID: 2673 SIG: 9
03-10 18:36:57.062: W/dalvikvm(2984): VFY: unable to resolve static field 1559 (ActionBarWindow) in Landroid/support/v7/appcompat/R$styleable;
03-10 18:36:57.063: D/dalvikvm(2984): VFY: replacing opcode 0x62 at 0x0004
03-10 18:36:57.064: D/AndroidRuntime(2984): Shutting down VM
03-10 18:36:57.064: W/dalvikvm(2984): threadid=1: thread exiting with uncaught exception (group=0x416d7d40)
03-10 18:36:57.066: E/AndroidRuntime(2984): FATAL EXCEPTION: main
03-10 18:36:57.066: E/AndroidRuntime(2984): Process: com.example.helloworld, PID: 2984
03-10 18:36:57.066: E/AndroidRuntime(2984): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
03-10 18:36:57.066: E/AndroidRuntime(2984): at com.example.helloworld.MainActivity.onCreate(MainActivity.java:18)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.app.Activity.performCreate(Activity.java:5248)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.app.ActivityThread.access$800(ActivityThread.java:139)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.os.Handler.dispatchMessage(Handler.java:102)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.os.Looper.loop(Looper.java:136)
03-10 18:36:57.066: E/AndroidRuntime(2984): at android.app.ActivityThread.main(ActivityThread.java:5102)
03-10 18:36:57.066: E/AndroidRuntime(2984): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 18:36:57.066: E/AndroidRuntime(2984): at java.lang.reflect.Method.invoke(Method.java:515)
03-10 18:36:57.066: E/AndroidRuntime(2984): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-10 18:36:57.066: E/AndroidRuntime(2984): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-10 18:3
6:57.066: E/AndroidRuntime(2984): at dalvik.system.NativeStart.main(Native Method)
So, is this normal behavior or have I done something wrong while setting up Eclipse, etc?
It looks like the Android compatibility library is not correctly configured for your project. In Eclipse, right click on the project in the package explorer and select Android Tools > Add Support Library. After setting up the support library, clean and rebuild your project.
This is normal behavior when reporting an error with your application.

Getting warning when trying to view saved camera picture in gridview

I am going to use camera/gallery in my project. FOr this i have first taken picture and saved it in my folder(Suppose pictureworld) and also saved the imageuri in the localdatabase. Then when i am trying to get the picture to show it in the gridview i am getting a warning message. In the gridview there is no picture but it can view the picture name. I have checked that it is creating the picture and also the uri in the localdatabase is correct.I want to add that when i am trying to save the pic using the gallery ..there is no problem. I have used the same adapter for viewing the saved gallery and camera picture. I am attaching the warning here:
03-10 17:48:11.367: W/System.err(522): at libcore.io.IoBridge.open(IoBridge.java:406)
03-10 17:48:11.367: W/System.err(522): at java.io.FileInputStream.<init>(FileInputStream.java:78)
03-10 17:48:11.367: W/System.err(522): at java.io.FileInputStream.<init>(FileInputStream.java:105)
03-10 17:48:11.367: W/System.err(522): at android.content.ContentResolver.openInputStream(ContentResolver.java:369)
03-10 17:48:11.367: W/System.err(522): at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:705)
03-10 17:48:11.367: W/System.err(522): at hr.s2is.ischool.admin.adapter.CommunityUserAdapter.getView(CommunityUserAdapter.java:71)
03-10 17:48:11.367: W/System.err(522): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
03-10 17:48:11.367: W/System.err(522): at android.widget.GridView.makeAndAddView(GridView.java:1323)
03-10 17:48:11.377: W/System.err(522): at android.widget.GridView.makeRow(GridView.java:328)
03-10 17:48:11.377: W/System.err(522): at android.widget.GridView.fillDown(GridView.java:281)
03-10 17:48:11.377: W/System.err(522): at android.widget.GridView.fillFromTop(GridView.java:403)
03-10 17:48:11.377: W/System.err(522): at android.widget.GridView.layoutChildren(GridView.java:1215)
03-10 17:48:11.377: W/System.err(522): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
03-10 17:48:11.377: W/System.err(522): at android.view.View.layout(View.java:11278)
03-10 17:48:11.377: W/System.err(522): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.377: W/System.err(522): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
03-10 17:48:11.387: W/System.err(522): at android.view.View.layout(View.java:11278)
03-10 17:48:11.387: W/System.err(522): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.387: W/System.err(522): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
03-10 17:48:11.387: W/System.err(522): at android.view.View.layout(View.java:11278)
03-10 17:48:11.387: W/System.err(522): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.387: W/System.err(522): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
03-10 17:48:11.397: W/System.err(522): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
03-10 17:48:11.397: W/System.err(522): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
03-10 17:48:11.397: W/System.err(522): at android.view.View.layout(View.java:11278)
03-10 17:48:11.397: W/System.err(522): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.397: W/System.err(522): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
03-10 17:48:11.397: W/System.err(522): at android.view.View.layout(View.java:11278)
03-10 17:48:11.397: W/System.err(522): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.407: W/System.err(522): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
03-10 17:48:11.407: W/System.err(522): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
03-10 17:48:11.407: W/System.err(522): at android.os.Handler.dispatchMessage(Handler.java:99)
03-10 17:48:11.407: W/System.err(522): at android.os.Looper.loop(Looper.java:137)
03-10 17:48:11.407: W/System.err(522): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-10 17:48:11.407: W/System.err(522): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 17:48:11.417: W/System.err(522): at java.lang.reflect.Method.invoke(Method.java:511)
03-10 17:48:11.417: W/System.err(522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-10 17:48:11.417: W/System.err(522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-10 17:48:11.417: W/System.err(522): at dalvik.system.NativeStart.main(Native Method)
03-10 17:48:11.417: W/System.err(522): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
03-10 17:48:11.427: W/System.err(522): at libcore.io.Posix.open(Native Method)
03-10 17:48:11.427: W/System.err(522): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
03-10 17:48:11.427: W/System.err(522): at libcore.io.IoBridge.open(IoBridge.java:390)
Have you given the permission to read the local storage? You should check if any permission is declared in Android Manifest regarding Writing and reading of Internal Storage.
did you add permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
One more thing:
With sdk, you can't write to the root of internal storage. This cause your error.Try something like this
final File dir = new File(context.getFilesDir() + "/nfs/guille/groce/users/nicholsk/workspace3/SQLTest");
dir.mkdirs(); //create folders where write files
final File file = new File(dir, "BlockForTest.txt");

Android http-request causes Error - sitting since 3 days

I am sitting since 3 days, looking everywhere on net but it dosnt work ... every time I try to make a http-request on android: it comes the error: unfourtunately, ... has stopped. here my code:
package sd.s;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class SdsdActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread trd = new Thread(new Runnable(){
public void run(){
// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpPost httpPost = new HttpPost(
"http://www.test.com");
// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("test", "test"));
nameValuePair.add(new BasicNameValuePair("message",
"Hi, trying Android HTTP post!"));
// Url Encoding the POST parameters
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = httpClient.execute(httpPost);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
} });
trd.run();
}
}
here my output on LogCat
02-24 17:53:39.003: D/dalvikvm(516): Not late-enabling CheckJNI (already on)
02-24 17:53:40.293: D/AndroidRuntime(516): Shutting down VM
02-24 17:53:40.304: W/dalvikvm(516): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-24 17:53:40.313: E/AndroidRuntime(516): FATAL EXCEPTION: main
02-24 17:53:40.313: E/AndroidRuntime(516): java.lang.RuntimeException: Unable to start activity ComponentInfo{sd.s/sd.s.SdsdActivity}: android.os.NetworkOnMainThreadException
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.os.Looper.loop(Looper.java:137)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 17:53:40.313: E/AndroidRuntime(516): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-24 17:53:40.313: E/AndroidRuntime(516): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-24 17:53:40.313: E/AndroidRuntime(516): at dalvik.system.NativeStart.main(Native Method)
02-24 17:53:40.313: E/AndroidRuntime(516): Caused by: android.os.NetworkOnMainThreadException
02-24 17:53:40.313: E/AndroidRuntime(516): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.net.InetAddress.getAllByName(InetAddress.java:220)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-24 17:53:40.313: E/AndroidRuntime(516): at sd.s.SdsdActivity.onCreate(SdsdActivity.java:52)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.Activity.performCreate(Activity.java:4465)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-24 17:53:40.313: E/AndroidRuntime(516): ... 11 more
02-24 17:59:31.783: D/AndroidRuntime(584): Shutting down VM
02-24 17:59:31.783: W/dalvikvm(584): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-24 17:59:31.793: E/AndroidRuntime(584): FATAL EXCEPTION: main
02-24 17:59:31.793: E/AndroidRuntime(584): java.lang.RuntimeException: Unable to start activity ComponentInfo{sd.s/sd.s.SdsdActivity}: android.os.NetworkOnMainThreadException
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.os.Looper.loop(Looper.java:137)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 17:59:31.793: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-24 17:59:31.793: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-24 17:59:31.793: E/AndroidRuntime(584): at dalvik.system.NativeStart.main(Native Method)
02-24 17:59:31.793: E/AndroidRuntime(584): Caused by: android.os.NetworkOnMainThreadException
02-24 17:59:31.793: E/AndroidRuntime(584): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.net.InetAddress.getAllByName(InetAddress.java:220)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-24 17:59:31.793: E/AndroidRuntime(584): at sd.s.SdsdActivity$1.run(SdsdActivity.java:53)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.lang.Thread.run(Thread.java:856)
02-24 17:59:31.793: E/AndroidRuntime(584): at sd.s.SdsdActivity.onCreate(SdsdActivity.java:66)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.Activity.performCreate(Activity.java:4465)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-24 17:59:31.793: E/AndroidRuntime(584): ... 11 more
02-24 18:08:12.242: D/AndroidRuntime(626): Shutting down VM
02-24 18:08:12.242: W/dalvikvm(626): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-24 18:08:12.262: E/AndroidRuntime(626): FATAL EXCEPTION: main
02-24 18:08:12.262: E/AndroidRuntime(626): java.lang.RuntimeException: Unable to start activity ComponentInfo{sd.s/sd.s.SdsdActivity}: android.os.NetworkOnMainThreadException
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.os.Looper.loop(Looper.java:137)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 18:08:12.262: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-24 18:08:12.262: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-24 18:08:12.262: E/AndroidRuntime(626): at dalvik.system.NativeStart.main(Native Method)
02-24 18:08:12.262: E/AndroidRuntime(626): Caused by: android.os.NetworkOnMainThreadException
02-24 18:08:12.262: E/AndroidRuntime(626): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.net.InetAddress.getAllByName(InetAddress.java:220)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-24 18:08:12.262: E/AndroidRuntime(626): at sd.s.SdsdActivity$1.run(SdsdActivity.java:53)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.lang.Thread.run(Thread.java:856)
02-24 18:08:12.262: E/AndroidRuntime(626): at sd.s.SdsdActivity.onCreate(SdsdActivity.java:66)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.Activity.performCreate(Activity.java:4465)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-24 18:08:12.262: E/AndroidRuntime(626): ... 11 more
Maybe I am to stupid but since 3 days I trying to get it running, The Applications starts, but stops after start everytime ...
Permission Internet is done and Firewall is np > WebBrowser in emulator works as well, what is wrong? pls - thank you very much for every answer!
You are executing the run() method of your Thread object on the main thread. Replace this:
trd.run();
with this:
trd.start();
As of Android 3.0, you cannot perform this type of request on the main thread.
NetworkOnMainThreadException
Class Overview
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. See the document Designing for Responsiveness.
Also see StrictMode.
See http://developer.android.com/guide/practices/design/responsiveness.html for guidelines on building responsive applications.
From your log, it looks like the error is android.os.NetworkOnMainThreadException. From http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html, it sounds like the error is that you're trying to do network operations in your main thread. Since this can make your UI unresponsive, it's discouraged. And since you seem to be running in strict mode (http://developer.android.com/reference/android/os/StrictMode.html), it's crashing the app.
Also, you should be calling trd.start() instead of trd.run()

Categories

Resources