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()
Related
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)
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 have this exception:
java.lang.NullPointerException
at android.webkit.WebViewClassic.requestFocus(WebViewClassic.java:10003)
at android.webkit.WebView.requestFocus(WebView.java:2133)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2382)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2338)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2382)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2338)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2382)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2341)
at android.view.View.requestFocus(View.java:6538)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1899)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
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:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
But it doesn't tell me what line it happened on or anything else. Any idea how to debug this?
Thanks,
Alex
I am getting error message on my AVD for my first android app named "My creativity".
Its showing:
Unfortunately My creativity has stopped
It has a simple text box and a button with background.
I am taking help of google.developers but getting above problem.
How to solve this?
Here's my LogCat:
02-24 10:18:48.624: I/Process(1068): Sending signal. PID: 1068 SIG: 9
02-24 10:18:51.654: W/Trace(1088): Unexpected value from nativeGetEnabledTags: 0
02-24 10:18:51.654: W/Trace(1088): Unexpected value from nativeGetEnabledTags: 0
02-24 10:18:52.194: D/dalvikvm(1088): GC_FOR_ALLOC freed 77K, 8% free 2513K/2708K, paused 52ms, total 56ms
02-24 10:18:52.534: I/dalvikvm-heap(1088): Grow heap (frag case) to 21.787MB for 20155408-byte allocation
02-24 10:18:52.674: D/dalvikvm(1088): GC_FOR_ALLOC freed 1K, 1% free 22194K/22392K, paused 137ms, total 137ms
02-24 10:18:52.784: D/dalvikvm(1088): GC_CONCURRENT freed <1K, 1% free 22194K/22392K, paused 9ms+21ms, total 109ms
02-24 10:18:55.204: D/dalvikvm(1088): GC_FOR_ALLOC freed <1K, 1% free 22194K/22392K, paused 41ms, total 41ms
02-24 10:18:55.204: I/dalvikvm-heap(1088): Forcing collection of SoftReferences for 45349648-byte allocation
02-24 10:18:55.284: D/dalvikvm(1088): GC_BEFORE_OOM freed 9K, 1% free 22184K/22392K, paused 72ms, total 73ms
02-24 10:18:55.284: E/dalvikvm-heap(1088): Out of memory on a 45349648-byte allocation.
02-24 10:18:55.284: I/dalvikvm(1088): "main" prio=5 tid=1 RUNNABLE
02-24 10:18:55.284: I/dalvikvm(1088): | group="main" sCount=0 dsCount=0 obj=0x40a719a0 self=0x2a00bba8
02-24 10:18:55.284: I/dalvikvm(1088): | sysTid=1088 nice=0 sched=0/0 cgrp=apps handle=1073849308
02-24 10:18:55.284: I/dalvikvm(1088): | state=R schedstat=( 3224239902 1154906764 146 ) utm=280 stm=42 core=0
02-24 10:18:55.284: I/dalvikvm(1088): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-24 10:18:55.294: I/dalvikvm(1088): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
02-24 10:18:55.294: I/dalvikvm(1088): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
02-24 10:18:55.294: I/dalvikvm(1088): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
02-24 10:18:55.294: I/dalvikvm(1088): at android.content.res.Resources.loadDrawable(Resources.java:1965)
02-24 10:18:55.304: I/dalvikvm(1088): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-24 10:18:55.304: I/dalvikvm(1088): at android.view.View.<init>(View.java:3328)
02-24 10:18:55.304: I/dalvikvm(1088): at android.view.ViewGroup.<init>(ViewGroup.java:431)
02-24 10:18:55.304: I/dalvikvm(1088): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
02-24 10:18:55.304: I/dalvikvm(1088): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
02-24 10:18:55.316: I/dalvikvm(1088): at java.lang.reflect.Constructor.constructNative(Native Method)
02-24 10:18:55.316: I/dalvikvm(1088): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-24 10:18:55.316: I/dalvikvm(1088): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
02-24 10:18:55.316: I/dalvikvm(1088): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-24 10:18:55.316: I/dalvikvm(1088): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
02-24 10:18:55.316: I/dalvikvm(1088): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-24 10:18:55.316: I/dalvikvm(1088): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
02-24 10:18:55.324: I/dalvikvm(1088): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-24 10:18:55.324: I/dalvikvm(1088): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-24 10:18:55.324: I/dalvikvm(1088): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-24 10:18:55.324: I/dalvikvm(1088): at android.app.Activity.setContentView(Activity.java:1881)
02-24 10:18:55.334: I/dalvikvm(1088): at com.example.iamgreat.GreatPiyu.onCreate(GreatPiyu.java:12)
02-24 10:18:55.334: I/dalvikvm(1088): at android.app.Activity.performCreate(Activity.java:5104)
02-24 10:18:55.334: I/dalvikvm(1088): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-24 10:18:55.344: I/dalvikvm(1088): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-24 10:18:55.344: I/dalvikvm(1088): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-24 10:18:55.344: I/dalvikvm(1088): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-24 10:18:55.344: I/dalvikvm(1088): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-24 10:18:55.354: I/dalvikvm(1088): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 10:18:55.354: I/dalvikvm(1088): at android.os.Looper.loop(Looper.java:137)
02-24 10:18:55.354: I/dalvikvm(1088): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-24 10:18:55.354: I/dalvikvm(1088): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 10:18:55.354: I/dalvikvm(1088): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 10:18:55.354: I/dalvikvm(1088): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-24 10:18:55.354: I/dalvikvm(1088): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-24 10:18:55.354: I/dalvikvm(1088): at dalvik.system.NativeStart.main(Native Method)
02-24 10:18:55.364: D/skia(1088): --- allocation failed for scaled bitmap
02-24 10:18:55.404: D/AndroidRuntime(1088): Shutting down VM
02-24 10:18:55.404: W/dalvikvm(1088): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-24 10:18:55.515: E/AndroidRuntime(1088): FATAL EXCEPTION: main
02-24 10:18:55.515: E/AndroidRuntime(1088): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iamgreat/com.example.iamgreat.GreatPiyu}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.os.Looper.loop(Looper.java:137)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-24 10:18:55.515: E/AndroidRuntime(1088): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 10:18:55.515: E/AndroidRuntime(1088): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 10:18:55.515: E/AndroidRuntime(1088): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-24 10:18:55.515: E/AndroidRuntime(1088): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-24 10:18:55.515: E/AndroidRuntime(1088): at dalvik.system.NativeStart.main(Native Method)
02-24 10:18:55.515: E/AndroidRuntime(1088): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
02-24 10:18:55.515: E/AndroidRuntime(1088): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-24 10:18:55.515: E/AndroidRuntime(1088): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.Activity.setContentView(Activity.java:1881)
02-24 10:18:55.515: E/AndroidRuntime(1088): at com.example.iamgreat.GreatPiyu.onCreate(GreatPiyu.java:12)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.Activity.performCreate(Activity.java:5104)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-24 10:18:55.515: E/AndroidRuntime(1088): ... 11 more
02-24 10:18:55.515: E/AndroidRuntime(1088): Caused by: java.lang.reflect.InvocationTargetException
02-24 10:18:55.515: E/AndroidRuntime(1088): at java.lang.reflect.Constructor.constructNative(Native Method)
02-24 10:18:55.515: E/AndroidRuntime(1088): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
02-24 10:18:55.515: E/AndroidRuntime(1088): ... 23 more
02-24 10:18:55.515: E/AndroidRuntime(1088): Caused by: java.lang.OutOfMemoryError
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.content.res.Resources.loadDrawable(Resources.java:1965)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.View.<init>(View.java:3328)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.view.ViewGroup.<init>(ViewGroup.java:431)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
02-24 10:18:55.515: E/AndroidRuntime(1088): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
02-24 10:18:55.515: E/AndroidRuntime(1088): ... 26 more
Out of memory on a 45349648-byte allocation
I think you are using lots of images and its not able to inflate it all at once.
Have a look at:
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
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