I'm pretty new to Android programming, however I'm used to program for iOS though...
Now in iOS you have the function of NSString stringWithContentOfURL. Now my Question is, if there is a similar option in java as well...? While searching in google i've come through some examples, but using them my app always crashes...
I used codes like this: http://www.coderzheaven.com/2011/07/17/how-to-read-webpage-contents-as-a-string-in-android/ but it keeps crashing... Could you please help me?
Thank you!
Edit:
LogCat Errors:
01-22 19:34:12.718: E/AndroidRuntime(5481): FATAL EXCEPTION: main
01-22 19:34:12.718: E/AndroidRuntime(5481): android.os.NetworkOnMainThreadException
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.net.InetAddress.getAllByName(InetAddress.java:220)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.example.test4.DieActivity.meldeAn(DieActivity.java:150)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.example.test4.DieActivity$1.onClick(DieActivity.java:56)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.view.View.performClick(View.java:3511)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.view.View$PerformClick.run(View.java:14105)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.Handler.handleCallback(Handler.java:605)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.Handler.dispatchMessage(Handler.java:92)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.Looper.loop(Looper.java:137)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.lang.reflect.Method.invoke(Method.java:511)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-22 19:34:12.718: E/AndroidRuntime(5481): at dalvik.system.NativeStart.main(Native Method)
you have tried to perform (network) IO on the UI thread. this is not allowed. why? because if you hang the UI thread, the system will post an ANR (activity not responding) dialog to the user..
you must perform IO asynchronously,
new AysyncTask<String,Void,String>() {
protected String doInBackground(String... urls) {
String url = urls[0];
// do network operation, get result in a string (for example)
return resultString;
}
protected void onPostExecute(String result) {
JSONObject jo = new JSONObject(result);
// update UI with the results of the network call here
}
}.execute(aUrl);
this is especially important for network IO, but it follows for disk IO as well. take a look at AsyncTask for details. the interface for AsyncTask is a little obtuse IMHO.
there's nothing special about AsyncTask, it's wraps a pattern around creating a thread and updating the user interface based on the results. in the old days, we used to do it like this,
new Thread(new Runnable() {
#Override
public void run() {
// do network operation
runOnUiThread(new Runnable() {
#Override
public void run() {
// update UI thread here
}
});
}
}}.start();
Android is telling you that you shouldn't be doing network operations on the UI thread. It doesn't want you to block the thread, and for good reasons.
Try using an AsyncTask instead. Put your HTTP request code in the doInBackground() method and update the TextView in the onPostExecute() method.
Keep in mind that you CANNOT access the UI thread from the doInBackground() method.
Related
I added Jsoup library from : File > Project Structure > Dependencies
When I wrote This Code :
val dockhalij = Jsoup.connect("http://khalikmusic.org").get()
my application will compile correctly but when I test it on my device (Galaxy Grand Duos), will be close and show be message Unfortunately 'app name' has stopped.
Without this line My application works correctly but I can't use Jsoup Library.
logcat :
08-29 18:09:39.188 31871-31871/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.bostanu.jelvilmusic/ir.bostanu.jelvilmusic.MainActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:652)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:629)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:261)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:250)
at ir.bostanu.jelvilmusic.MainActivity.onCreate(MainActivity.kt:49)
at android.app.Activity.performCreate(Activity.java:5283)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
When I Add libraries with file > project Structure > Dependencies, libraries don't Work for me (Always), I don't know why
This is because you are performing network operation on main thread,
try this:
Thread threadJSoup = new Thread(new Runnable() {
#Override
public void run() {
try {
val dockhalij = Jsoup.connect("http://khalikmusic.org").get();
} catch (Exception e) {
e.printStackTrace();
}
}
});
threadJSoup.start();
See post How do I fix android.os.NetworkOnMainThreadException?
It is explained there, that you are not allowed to perform network operations on the main thread and it seems that you perform that line
val dockhalij = Jsoup.connect("http://khalikmusic.org").get()
on the main thread.
I'm trying to access website through simple HttpClient and its throwing error as below/ I have tried to put this in android manifest android.permission.INTERNET but still it's throwing same error
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
04-25 19:10:05.380 12689-12710/? E/Launcher.BadgeCache,﹕ Do not updateBadgeCounts!!, multiple data for appIndex=1
04-25 19:10:09.875 2346-2744/? E/DatabaseUtils﹕ Writing exception to parcel
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
04-25 19:10:10.405 2749-2749/com.example.innovator.httpclientapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.innovator.httpclientapp/com.example.innovator.httpclientapp.MainActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1144)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at com.example.innovator.httpclientapp.MyHttpClient.getWebsiteResult(MyHttpClient.java:42)
at com.example.innovator.httpclientapp.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
Below is my onCreateMethod
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// here instantiate a java class for retrieving the https url result
MyHttpClient client = new MyHttpClient();
// read the input stream
TextView textView = (TextView)findViewById(R.id.tvResult);
// setting the output to text view
textView.setText(client.getWebsiteResult());
}
According to answer from here.
android.permission.INTERACT_ACROSS_USERS_FULL is a signature level
permission. Your app will not be able to use it until and unless it
has the same signature as the system.
Which is not something you can achieve unless you either are the
creator or the system build, or collaborating with them such that they
are willing to sign your apk with their certificate. In other words,
this is off limits for most developers.
However, reading your loagcat and code.
04-25 19:10:10.405 2749-2749/com.example.innovator.httpclientapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.innovator.httpclientapp/com.example.innovator.httpclientapp.MainActivity}: android.os.NetworkOnMainThreadException
Above error suggests that a network call cannot be made on main thread. So, make a new thread and start network call from that thread. It might solve your problem.
new Thread() {
public void run() {
// your network call
}
}.start();
If you want to have callbacks and stuff you can use AsyncTask as well.
Also a suggestion, for making nice and quick network calls you can use volley. It is my personal favorite and very easy to use!
I managed to fix the previous linking problem I had with NDK which was caused by android api 21, and managed to get SDL_TTF built and working easily, but with SDL_Mixer I bumped into another runtime Unsatisfiedlinkererror where the app somehow can't link smpeg2 lib with SDL2_Mixer. This time I don't see how it could have anything to do with api-level and have tried everything I could come up with, gone through every makefile and triple-checked every version.
I am using SDL_Mixer 2.0.0 and smpeg2-2.0.0 as its only dependecy. Smpeg2 is located in jni/ folder and the whole thing is built without compiler coughing.
I downloaded SDL_Mixer 2.0.0 source and put it in jni/ folder, copied smpeg2-2.0.0 from it's external/ folder to jni/ and set from mixer makefile to build only smpeg2. I edited src/Android.mk to see the mixer source and get the shared lib and then edited SDLActivity to pull SDL2_mixer library. SDL_TTF worked this way.
libsmpeg2.so DOES exist in libs/ folder so I don't see how it can't find it.
I am using android-19 as build target for NDK, no warnings or errors are given by the compiler.
01-22 18:17:43.760: D/dalvikvm(22101): Trying to load lib /data/data/com.kebabkeisari.peli/lib/libSDL2.so 0x41d88e78
01-22 18:17:43.760: D/dalvikvm(22101): Added shared lib /data/data/com.kebabkeisari.peli/lib/libSDL2.so 0x41d88e78
01-22 18:17:43.760: D/dalvikvm(22101): Trying to load lib /data/data/com.kebabkeisari.peli/lib/libSDL2_mixer.so 0x41d88e78
01-22 18:17:43.765: W/dalvikvm(22101): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/libsdl/app/SDLActivity;
01-22 18:17:43.765: W/dalvikvm(22101): Class init failed in newInstance call (Lcom/kebabkeisari/peli/Ribale;)
01-22 18:17:43.765: D/AndroidRuntime(22101): Shutting down VM
01-22 18:17:43.765: W/dalvikvm(22101): threadid=1: thread exiting with uncaught exception (group=0x410c52a0)
01-22 18:17:43.765: E/AndroidRuntime(22101): FATAL EXCEPTION: main
01-22 18:17:43.765: E/AndroidRuntime(22101): java.lang.ExceptionInInitializerError
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.Class.newInstanceImpl(Native Method)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.Class.newInstance(Class.java:1319)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.access$600(ActivityThread.java:140)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.os.Looper.loop(Looper.java:137)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.main(ActivityThread.java:4898)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.reflect.Method.invoke(Method.java:511)
01-22 18:17:43.765: E/AndroidRuntime(22101): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
01-22 18:17:43.765: E/AndroidRuntime(22101): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-22 18:17:43.765: E/AndroidRuntime(22101): at dalvik.system.NativeStart.main(Native Method)
01-22 18:17:43.765: E/AndroidRuntime(22101): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1892]: 1952 could not load needed library 'libsmpeg2.so' for 'libSDL2_mixer.so' (load_library[1094]: Library 'libsmpeg2.so' not found)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.Runtime.loadLibrary(Runtime.java:370)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.System.loadLibrary(System.java:535)
01-22 18:17:43.765: E/AndroidRuntime(22101): at org.libsdl.app.SDLActivity.<clinit>(SDLActivity.java:51)
01-22 18:17:43.765: E/AndroidRuntime(22101): ... 15 more
You need to load the libraries in reverse dependency order. That is, if libSDL2_mixer.so depends on libsmpeg2.so, you first need to load libsmpeg2.so before you can try to load libSDL2_mixer.so.
That is, in order to load the library, you need to do this:
System.loadLibrary("smpeg2");
System.loadLibrary("SDL2_mixer");
IIRC this has been fixed in some very recent version of Android, but in order to have things working on older versions, you need to explicitly load them one at a time.
I'm doing an app in which a Service initiates a GPSListener which gets location updates in a regular interval of time.Upto this part its woking fine,and Im getting updates correctly.
I need to update this lat,long values to a server database,for which I use a http post request to a php script;which individually works fien.But when its called inside the LocationListener,Im getting the following error stacktrace.
How can I overcome this situation and make the post request?
> android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.childtrack.service.SimpleService$mylocationlistener.postData(SimpleService.java:165)
at com.childtrack.service.SimpleService$mylocationlistener.onLocationChanged(SimpleService.java:101)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:237)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:170)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:186)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
W/System.err(5560): android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.childtrack.service.SimpleService$mylocationlistener.postData(SimpleService.java:165)
at com.childtrack.service.SimpleService$mylocationlistener.onLocationChanged(SimpleService.java:101)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:237)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:170)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:186)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
you are doing network operation on main(UI) thread. do use asyntask for network operation.
android does not allow to perform network operation on main thread. because it may freezes the UI.
whenever this exception occur android.os.NetworkOnMainThreadException its mean you have done something network operation on UI.
Even though Service is intended for background processing they run in the main thread .
A short quote from the documentation:
Caution: A services runs in the same process as the application in which
it is declared and in the main thread of that application, by default. So,
if your service performs intensive or blocking operations while the user
interacts with an activity from the same application, the service will
slow down activity performance. To avoid impacting application performance,
you should start a new thread inside the service.
I'm trying to test for first time my App on my mobile phone, I already did all the usb driver installation, allow non-market apps to install stuff... and now when I launch I get this error on Eclipse LogCat, I don't know what to do anymore, it's a PhoneGap app by the way:
01-22 12:40:08.534: W/asset(15063): Asset path /data/app/com.example.appprueba-1.apk is neither a directory nor file (type=1).
01-22 12:40:08.542: W/asset(15063): Asset path /data/app/com.example.appprueba-1.apk is neither a directory nor file (type=1).
01-22 12:40:08.542: D/AndroidRuntime(15063): Shutting down VM
01-22 12:40:08.542: W/dalvikvm(15063): threadid=1: thread exiting with uncaught exception (group=0x410aa930)
01-22 12:40:08.550: E/AndroidRuntime(15063): FATAL EXCEPTION: main
01-22 12:40:08.550: E/AndroidRuntime(15063): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.appprueba/com.example.appprueba.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.appprueba.MainActivity" on path: /data/app/com.example.appprueba-1.apk
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.os.Looper.loop(Looper.java:137)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-22 12:40:08.550: E/AndroidRuntime(15063): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 12:40:08.550: E/AndroidRuntime(15063): at java.lang.reflect.Method.invoke(Method.java:511)
01-22 12:40:08.550: E/AndroidRuntime(15063): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-22 12:40:08.550: E/AndroidRuntime(15063): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-22 12:40:08.550: E/AndroidRuntime(15063): at dalvik.system.NativeStart.main(Native Method)
01-22 12:40:08.550: E/AndroidRuntime(15063): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.appprueba.MainActivity" on path: /data/app/com.example.appprueba-1.apk
01-22 12:40:08.550: E/AndroidRuntime(15063): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
01-22 12:40:08.550: E/AndroidRuntime(15063): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-22 12:40:08.550: E/AndroidRuntime(15063): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
01-22 12:40:08.550: E/AndroidRuntime(15063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
01-22 12:40:08.550: E/AndroidRuntime(15063): ... 11 more
You might have not put everything on its place, review Tutorials and have set everything as it says..
Check docs and implementation on phonegap website as well as cardova website.