Note that there are some explanatory texts on larger screens.

plurals
  1. POForce close on Intent null return
    text
    copied!<p>Hola! This is my first post. I'm having trouble with the code snippet below.</p> <p>Basically, you click an EditText and you're presented with a file browser. If you choose a file all is right with the world. If you choose the back/return button on your phone without choosing a file a force close is caused. I think this is because I'm returning a null from the intent, but I do not know how to fix nor what I should try/ catch.</p> <p>Your help is greatly appreciated.</p> <p>Code:</p> <pre><code> filename = (EditText) findViewById(R.id.selectFile); filename.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("text/csv"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent,"Select File"),1); } }); </code></pre> <p>The result from LogCat.</p> <p>02-15 10:03:27.224: DEBUG/dalvikvm(133): GC_EXPLICIT freed 74K, 52% free 2860K/5895K, external 2101K/2456K, paused 69ms 02-15 10:03:30.314: INFO/ActivityManager(61): Starting: Intent { cmp=com.aydabtu.BroadcastSMS/.DataManagerActivity } from pid 557 02-15 10:03:30.483: DEBUG/dalvikvm(557): GC_EXTERNAL_ALLOC freed 228K, 52% free 2656K/5511K, external 1465K/1828K, paused 63ms 02-15 10:03:30.633: WARN/AdMobSDK(557): Ignoring requestFreshAd() because we are requesting an ad right now already. 02-15 10:03:30.643: INFO/AdMobSDK(557): Location information is not being used for ad requests. Enable location 02-15 10:03:30.643: INFO/AdMobSDK(557): based ads with AdManager.setAllowUseOfLocation(true) or by setting 02-15 10:03:30.643: INFO/AdMobSDK(557): meta-data ADMOB_ALLOW_LOCATION_FOR_ADS to true in AndroidManifest.xml 02-15 10:03:30.653: INFO/AdMobSDK(557): Making ad request in test mode 02-15 10:03:31.104: INFO/AdMobSDK(557): Ad returned (493 ms): AdMob Test Android Web Ad 02-15 10:03:31.224: INFO/ActivityManager(61): Displayed com.aydabtu.BroadcastSMS/.DataManagerActivity: +855ms 02-15 10:03:33.903: INFO/ActivityManager(61): Starting: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) } from pid 557 02-15 10:03:34.254: DEBUG/dalvikvm(122): GC_EXTERNAL_ALLOC freed 20K, 44% free 3456K/6151K, external 2546K/2586K, paused 143ms 02-15 10:03:35.124: INFO/ActivityManager(61): Displayed android/com.android.internal.app.ChooserActivity: +1s111ms 02-15 10:03:36.064: DEBUG/dalvikvm(61): GC_CONCURRENT freed 959K, 47% free 4099K/7687K, external 2440K/3047K, paused 7ms+19ms 02-15 10:03:40.623: WARN/KeyCharacterMap(557): No keyboard for id 0 02-15 10:03:40.633: WARN/KeyCharacterMap(557): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 02-15 10:03:40.864: DEBUG/AndroidRuntime(557): Shutting down VM 02-15 10:03:40.864: WARN/dalvikvm(557): threadid=1: thread exiting with uncaught exception (group=0x40015560) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): FATAL EXCEPTION: main 02-15 10:03:40.953: ERROR/AndroidRuntime(557): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {com.aydabtu.BroadcastSMS/com.aydabtu.BroadcastSMS.DataManagerActivity}: java.lang.NullPointerException 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.app.ActivityThread.deliverResults(ActivityThread.java:2496) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2538) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.app.ActivityThread.access$2000(ActivityThread.java:117) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:958) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.os.Handler.dispatchMessage(Handler.java:99) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.os.Looper.loop(Looper.java:123) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.app.ActivityThread.main(ActivityThread.java:3647) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at java.lang.reflect.Method.invokeNative(Native Method) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at java.lang.reflect.Method.invoke(Method.java:507) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at dalvik.system.NativeStart.main(Native Method) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): Caused by: java.lang.NullPointerException 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at com.aydabtu.BroadcastSMS.DataManagerActivity.onActivityResult(DataManagerActivity.java:93) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.app.Activity.dispatchActivityResult(Activity.java:3907) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): at android.app.ActivityThread.deliverResults(ActivityThread.java:2492) 02-15 10:03:40.953: ERROR/AndroidRuntime(557): ... 11 more 02-15 10:03:41.733: WARN/ActivityManager(61): Force finishing activity com.aydabtu.BroadcastSMS/.DataManagerActivity 02-15 10:03:42.244: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{406cdfd8 com.aydabtu.BroadcastSMS/.DataManagerActivity} 02-15 10:03:44.084: INFO/Process(557): Sending signal. PID: 557 SIG: 9 02-15 10:03:44.104: INFO/ActivityManager(61): Process com.aydabtu.BroadcastSMS (pid 557) has died. 02-15 10:03:44.124: ERROR/InputDispatcher(61): channel '406c91a0 com.aydabtu.BroadcastSMS/com.aydabtu.BroadcastSMS.BroadcastSMS (server)' ~ Consumer closed input channel or an error occurred. events=0x8 02-15 10:03:44.124: ERROR/InputDispatcher(61): channel '406c91a0 com.aydabtu.BroadcastSMS/com.aydabtu.BroadcastSMS.BroadcastSMS (server)' ~ Channel is unrecoverably broken and will be disposed! 02-15 10:03:44.154: INFO/WindowManager(61): WIN DEATH: Window{406c91a0 com.aydabtu.BroadcastSMS/com.aydabtu.BroadcastSMS.BroadcastSMS paused=false} 02-15 10:03:44.274: INFO/WindowManager(61): WIN DEATH: Window{406e5f80 com.aydabtu.BroadcastSMS/com.aydabtu.BroadcastSMS.DataManagerActivity paused=false} 02-15 10:03:44.383: INFO/WindowManager(61): WIN DEATH: Window{406c4d58 android/com.android.internal.app.ChooserActivity paused=false} 02-15 10:03:44.423: ERROR/InputDispatcher(61): Received spurious receive callback for unknown input channel. fd=165, events=0x8 02-15 10:03:44.423: ERROR/InputDispatcher(61): Received spurious receive callback for unknown input channel. fd=176, events=0x8 02-15 10:03:45.084: WARN/InputManagerService(61): Got RemoteException sending setActive(false) notification to pid 557 uid 10032</p> <p>I think I have this fixed. Thank you for the clues.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload