This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I fix android.os.NetworkOnMainThreadException?
I just built a demo application through this tutorial and when I run the application I get the following error in log cat and the main application is stopped. Does anyone know why I am getting this error?
05-11 15:52:06.492: E/AndroidRuntime(584): FATAL EXCEPTION: main
05-11 15:52:06.492: E/AndroidRuntime(584): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.jsonparsing/com.androidhive.jsonparsing.AndroidJSONParsingActivity}: android.os.NetworkOnMainThreadException
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.os.Looper.loop(Looper.java:137)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-11 15:52:06.492: E/AndroidRuntime(584): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 15:52:06.492: E/AndroidRuntime(584): at java.lang.reflect.Method.invoke(Method.java:511)
05-11 15:52:06.492: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-11 15:52:06.492: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-11 15:52:06.492: E/AndroidRuntime(584): at dalvik.system.NativeStart.main(Native Method)
05-11 15:52:06.492: E/AndroidRuntime(584): Caused by: android.os.NetworkOnMainThreadException
05-11 15:52:06.492: E/AndroidRuntime(584): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
05-11 15:52:06.492: E/AndroidRuntime(584): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
05-11 15:52:06.492: E/AndroidRuntime(584): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
05-11 15:52:06.492: E/AndroidRuntime(584): at java.net.InetAddress.getAllByName(InetAddress.java:220)
05-11 15:52:06.492: E/AndroidRuntime(584): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
05-11 15:52:06.492: E/AndroidRuntime(584): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-11 15:52:06.492: E/AndroidRuntime(584): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-11 15:52:06.492: E/AndroidRuntime(584): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-11 15:52:06.492: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-11 15:52:06.492: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-11 15:52:06.492: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-11 15:52:06.492: E/AndroidRuntime(584): at com.androidhive.jsonparsing.JSONParser.getJSONFromUrl(JSONParser.java:38)
05-11 15:52:06.492: E/AndroidRuntime(584): at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:54)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.Activity.performCreate(Activity.java:4465)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-11 15:52:06.492: E/AndroidRuntime(584): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-11 15:52:06.492: E/AndroidRuntime(584): ... 11 more
Rebuild the same for android target before 3.0 (such as for 2.1). Androids before 3.0 don't check if you're making network connections on main thread.
After it works as a quick fix then move your networking away from the main thread.
see: http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
Related
I'm trying to establish communication between Arduino UNO R3 and Galaxy SII on Android 4.1 cross usb. The code sample i am following i here: http://androidgurusolutions.blogspot.com/2012/07/arduino-adk-board-blink-led-with-your.html . Unfortunately, i am getting this message 'app has stopped' and here is LogCat error
LogCat:
E/AndroidRuntime(535): FATAL EXCEPTION: main
E/AndroidRuntime(535): java.lang.NoClassDefFoundError: com.android.future.usb.UsbManager
E/AndroidRuntime(535): at com.example.mypro.MainActivity.onCreate(MainActivity.java:123)
E/AndroidRuntime(535): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(535): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime(535): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(535):at android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(535):at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(535):at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(535):at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(535):at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(535):at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(535):at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(535):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(535):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(535):at dalvik.system.NativeStart.main(Native Method)
please can anybody help me. thanks in advance.....
I need to delete multiple rows from my database table.
This is my code for deletion
String[] paragraph;
.....
//here you can to put various strings within it (1 or more)
.....
db.delete(mytablename,"Paragraph = ?",paragraphs);
It works with 1 string, but it doesn't work with more strings.
Can someone help me, please?
Here there is the error shown by LogCat:
05-11 11:03:01.400: E/AndroidRuntime(767): FATAL EXCEPTION: main
05-11 11:03:01.400: E/AndroidRuntime(767): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x377500
05-11 11:03:01.400: E/AndroidRuntime(767): at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
05-11 11:03:01.400: E/AndroidRuntime(767): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:241)
05-11 11:03:01.400: E/AndroidRuntime(767): at android.database.DatabaseUtils.bindObjectToProgram(DatabaseUtils.java:191)
05-11 11:03:01.400: E/AndroidRuntime(767): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1769)
05-11 11:03:01.400: E/AndroidRuntime(767): at it.tirocinio.Segnalibro$3$3.onClick(Segnalibro.java:196)
05-11 11:03:01.400: E/AndroidRuntime(767): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
05-11 11:03:01.400: E/AndroidRuntime(767): at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 11:03:01.400: E/AndroidRuntime(767): at android.os.Looper.loop(Looper.java:123)
05-11 11:03:01.400: E/AndroidRuntime(767): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-11 11:03:01.400: E/AndroidRuntime(767): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 11:03:01.400: E/AndroidRuntime(767): at java.lang.reflect.Method.invoke(Method.java:521)
05-11 11:03:01.400: E/AndroidRuntime(767): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-11 11:03:01.400: E/AndroidRuntime(767): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-11 11:03:01.400: E/AndroidRuntime(767): at dalvik.system.NativeStart.main(Native Method)
use this way:
for(int i = 0 ; i < paragraphs.lenght;i++)
{
db.delete(mytablename,"Paragraph ='"+paragraphs[i]+"'",null);
}
i have this messages from LogCat
dalvikvm(526): Could not find class 'com.temp.pt.database.DBHelper',
referenced from method com.temp.pt.database.DBUtils.getDBHelper
and after this i have this
05-11 21:46:25.305: E/AndroidRuntime(526): FATAL EXCEPTION: main
05-11 21:46:25.305: E/AndroidRuntime(526): java.lang.NoClassDefFoundError: com.temp.pt.database.DBHelper
05-11 21:46:25.305: E/AndroidRuntime(526): at com.temp.pt.database.DBUtils.getDBHelper(DBUtils.java:20)
05-11 21:46:25.305: E/AndroidRuntime(526): at com.temp.pt.CategoriesFragment$CategoryAsyncLoader.<init>(CategoriesFragment.java:169)
05-11 21:46:25.305: E/AndroidRuntime(526): at com.temp.pt.CategoriesFragment.onCreateLoader(CategoriesFragment.java:76)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.LoaderManagerImpl.createLoader(LoaderManager.java:486)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.LoaderManagerImpl.createAndInstallLoader(LoaderManager.java:495)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.LoaderManagerImpl.initLoader(LoaderManager.java:549)
05-11 21:46:25.305: E/AndroidRuntime(526): at com.temp.pt.CategoriesFragment.onActivityCreated(CategoriesFragment.java:45)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:891)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1810)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:501)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.app.Activity.performStart(Activity.java:4475)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.os.Looper.loop(Looper.java:137)
05-11 21:46:25.305: E/AndroidRuntime(526): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-11 21:46:25.305: E/AndroidRuntime(526): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 21:46:25.305: E/AndroidRuntime(526): at java.lang.reflect.Method.invoke(Method.java:511)
05-11 21:46:25.305: E/AndroidRuntime(526): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-11 21:46:25.305: E/AndroidRuntime(526): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-11 21:46:25.305: E/AndroidRuntime(526): at dalvik.system.NativeStart.main(Native Method)
note i have define the class and the app compiles without error but crash at runtime . any suggestion , ,solution for this problem ?
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()
I have a problem. I can't seem to download a .jpg image from a URL source and then set it into a imageview which is inside a listview. It gives me the error "NullPointerException". I am currently using the ImageDownloader class from here.
This are the lines of code where i download the image files:
onCreate()...
for (int i = 0; i < listData.size(); i++) {
imageISBN = listData.get(i).get("coverImage");
String isbnURL = "http://lib.syndetics.com/index.aspx?isbn=" + imageISBN +
"/SC.GIF&client=tpoly&type=xw12";
ImageView iv = (ImageView) findViewById(R.id.cover_image);
imageDownloader.download(isbnURL,iv);
}
I'm thinking that it maybe due to my setContentView(R.layout.list) that's producing the error since it is just a listview and the imageview link is in another xml file.
Below is the LogCat:
05-11 09:26:58.063: ERROR/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.TPLibrary/com.TPLibrary.Search.SearchResults}: java.lang.NullPointerException
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.os.Looper.loop(Looper.java:123)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at java.lang.reflect.Method.invoke(Method.java:521)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at dalvik.system.NativeStart.main(Native Method)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): Caused by: java.lang.NullPointerException
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.TPLibrary.Search.ImageDownloader.forceDownload(ImageDownloader.java:80)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.TPLibrary.Search.ImageDownloader.download(ImageDownloader.java:49)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.TPLibrary.Search.SearchResults.onCreate(SearchResults.java:185)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-11 09:26:58.063: ERROR/AndroidRuntime(305): ... 11 more
So guys, any ideas? Could it be that i'm using the ImageDownloader class wrongly?
In ImageDownloader class, the mode is assigned to NO_ASYNC_TASK:
public enum Mode { NO_ASYNC_TASK, NO_DOWNLOADED_DRAWABLE, CORRECT }
private Mode mode = Mode.NO_ASYNC_TASK;
Your intention was to download the image. So try setting the mode variable to NO_DOWNLOADED_DRAWABLE.