NumberFormatException in GPS processing - android

I am having a weird problem.
I am developing a program to log GPS and sensor readings periodically. My friend runs the code on his machine using Eclipse Galileo 3.6 and it works perfectly fine for her.
When I run the code on my machine which has Eclipse Galileo 3.5.2 it shows service stopped unexpectedly.
We have the same JDK version. I am not able to figure out what may be the exact problem.
Please let me know what else information I need to give in order to fix the problem.
logcat
I/ActivityManager( 1104): Start proc com.sensor.test for service com.sensor.test/.SensorReadings: pid=3539 uid=10057 gids={3003, 1015}
D/AndroidRuntime( 3539): Shutting down VM
W/dalvikvm( 3539): threadid=1: thread exiting with uncaught exception (group=0x4001d7e0)
E/AndroidRuntime( 3539): FATAL EXCEPTION: main
E/AndroidRuntime( 3539): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.BATTERY_CHANGED flg=0x60000000 (has extras) } in com.sensor.test.SensorReadings$2#44770958
E/AndroidRuntime( 3539): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:905)
E/AndroidRuntime( 3539): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 3539): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 3539): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3539): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 3539): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3539): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3539): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 3539): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 3539): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3539): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 3539): at com.sensor.test.SensorReadings$2.onReceive(SensorReadings.java:327)
E/AndroidRuntime( 3539): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:892)
E/AndroidRuntime( 3539): ... 9 more
W/ActivityManager( 1104): Activity destroy timeout for HistoryRecord{44b38508 com.sensor.test/.MainScreen}
D/WifiService( 1104): acquireWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder#44963d80}
D/LocationMasfClient( 1104): getNetworkLocation(): Location not found in cache, making network request
D/LocationMasfClient( 1104): getNetworkLocation(): Number of prefetched entries 10
E/LocationMasfClient( 1104): getNetworkLocation(): Returning *server* computed location with accuracy 28
D/libgps ( 1104): GpsInterface_inject_location( 35.772249, -78.673950, 28.000 )
D/WifiService( 1104): releaseWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder#44963d80}
D/WifiService( 1104): acquireWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder#44963d80}
D/WifiService( 1104): releaseWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder#44963d80}
D/NativeCrypto( 1104): Freeing OpenSSL session
D/dalvikvm( 1104): GC_FOR_MALLOC freed 22104 objects / 1169312 bytes in 128ms
D/NativeCrypto( 1104): Freeing OpenSSL session
I/Process ( 3539): Sending signal. PID: 3539 SIG: 9
W/InputManagerService( 1104): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#44b40dd0
I/ActivityManager( 1104): Process com.sensor.test (pid 3539) has died.
The pertinent code for line 88 with parsing going on:
public void startService(){
//startService(new Intent(MainScreen.this,SensorReadings.class));
Intent intent = new Intent(MainScreen.this, SensorReadings.class);
**intent.putExtra("lp", Integer.parseInt(""+longPeriod.getText()));// LINE 88**
intent.putExtra("gp", Integer.parseInt(""+gpsPeriod.getText()));
intent.putExtra("sp", Integer.parseInt(""+snrPeriod.getText()));
//startActivity(intent);
startService(intent);
}
Thanks.
AG

E/AndroidRuntime( 2934): java.lang.NumberFormatException: unable to parse '' as integer
E/AndroidRuntime( 2934): at java.lang.Integer.parseInt(Integer.java:412)
E/AndroidRuntime( 2934): at java.lang.Integer.parseInt(Integer.java:382)
E/AndroidRuntime( 2934): at com.sensor.test.MainScreen.startService(MainScreen.java:88)
Perhaps at line 88 in MainScreen.java, your startService method is calling Integer.parseInt with an empty string?
Can you show us the pertinent code?

I don't get why you are putting "".
So to be sure this is not the problem try either this:
intent.putExtra("lp", Integer.parseInt(longPeriod.getText()));
intent.putExtra("gp", Integer.parseInt(gpsPeriod.getText()));
intent.putExtra("sp", Integer.parseInt(snrPeriod.getText()));
or
String lp = longPeriod.getText();
String gp = gpsPeriod.getText();
String sp = snrPeriod.getText();
intent.putExtra("lp", Integer.parseInt(lp));
intent.putExtra("gp", Integer.parseInt(gp));
intent.putExtra("sp", Integer.parseInt(sp));
The second way is better for debugging... so you can see what is actually happening.

Related

Solving 'application has stopped' crash errors

Building an AOA application, my Android device communicates with an external accessory, in this case an arduino.
When I connect the accessory, my Android application launches correctly as I have a USB_ATTACHED action within my intent-filter for my mainActivity.
However, my Android application unfortunately crashes when disconnected from the USB accessory.
My shell immediately switches from TCPIP to USB mode on disconect but reconnecting I get a complete stack trace
Can any Android gurus suggest how I might debug this further based on the following logcat output?
E/run ( 5092): java.io.IOException: read failed: EIO (I/O error)
D/PicasaSyncManager( 4877): battery info: false
D/UsbDeviceManager( 781): exited USB accessory mode
E/UsbDebuggingManager( 781): got -1 reading
E/UsbDebuggingManager( 781): Communication error:
E/UsbDebuggingManager( 781): java.io.IOException: No such file or directory
E/UsbDebuggingManager( 781): at android.net.LocalSocketImpl.connectLocal(Native Method)
E/UsbDebuggingManager( 781): at android.net.LocalSocketImpl.connect(LocalSocketImpl.java:287)
E/UsbDebuggingManager( 781): at android.net.LocalSocket.connect(LocalSocket.java:130)
E/UsbDebuggingManager( 781): at com.android.server.usb.UsbDebuggingManager.listenToSocket(UsbDebuggingManager.java:75)
E/UsbDebuggingManager( 781): at com.android.server.usb.UsbDebuggingManager.run(UsbDebuggingManager.java:111)
E/UsbDebuggingManager( 781): at java.lang.Thread.run(Thread.java:841)
D/dalvikvm( 781): GC_FOR_ALLOC freed 1069K, 14% free 31156K/35896K, paused 54ms, total 55ms
V/SearchControllerCache( 2819): creating SearchController
W/Sidekick_LocationOracleImpl( 2819): Best location was null
D/dalvikvm( 2819): GC_FOR_ALLOC freed 514K, 5% free 18100K/18940K, paused 15ms, total 15ms
D/audio_hw_primary( 182): select_devices: out_snd_device(0: ) in_snd_device(35: voice-rec-mic)
D/ ( 182): Failed to fetch the lookup information of the device 0000003E
E/ACDB-LOADER( 182): Error: ACDB AudProc vol returned = -19
I/SearchController( 2819): #onHotwordDetectorStarted
D/MainActivity( 5092): ASSERT registerPhone and register =false
D/MainActivity( 5092): ASSERT registerSms and register =false
I/WroxAccessory( 5092): disconnect
D/AndroidRuntime( 5092): Shutting down VM
W/dalvikvm( 5092): threadid=1: thread exiting with uncaught exception (group=0x41e7cba8)
E/AndroidRuntime( 5092): FATAL EXCEPTION: main
E/AndroidRuntime( 5092): Process: ca.foo, PID: 5092
E/AndroidRuntime( 5092): java.lang.RuntimeException: Unable to destroy activity {ca.foo/ca.foo.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: com.wiley.wroxaccessories.UsbConnection12$1#42f0be28
E/AndroidRuntime( 5092): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3497)
E/AndroidRuntime( 5092): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3515)
E/AndroidRuntime( 5092): at android.app.ActivityThread.access$1400(ActivityThread.java:135)
E/AndroidRuntime( 5092): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
E/AndroidRuntime( 5092): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 5092): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 5092): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 5092): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5092): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 5092): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 5092): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 5092): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5092): Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.wiley.wroxaccessories.UsbConnection12$1#42f0be28
E/AndroidRuntime( 5092): at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:667)
E/AndroidRuntime( 5092): at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1453)
E/AndroidRuntime( 5092): at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:489)
E/AndroidRuntime( 5092): at com.wiley.wroxaccessories.UsbConnection12.close(UsbConnection12.java:115)
E/AndroidRuntime( 5092): at ca.foo.MainActivity.onDestroy(MainActivity.java:164)
E/AndroidRuntime( 5092): at android.app.Activity.performDestroy(Activity.java:5403)
E/AndroidRuntime( 5092): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
E/AndroidRuntime( 5092): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3484)
E/AndroidRuntime( 5092): ... 11 more
For the IO error that is being thrown,
I came across:
https://code.google.com/p/android/issues/detail?id=20545
An option is writing a function in onPause() ,
but a better way would be: (as mentioned by #9 in the same link) -
use http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
Also, there is a question to properly close the usb accessory connection, which helps in your case
Proper way to close a USB accessory connection
Frankly, as I'm not very familiar with the first of your exceptions, I've tried to research a little over it and what seems the most relevant description is that it's an ICS bug - you can read about it here, but I can't see the relationship between arduino and NFS, though.
The second one looks much more familiar to me. I don't know if it's the only one case which may produce it (probably not), but in my case it was because in the registerReceiver(...) I was passing it two Contexts, and on unregisterReceiver(...) it failed exactly with that exception. The solution was passing getApplicationContext() as context on registering and this exception stopped appearing.
Simply Clear the cache/data the data for that application and restat the device. Hopefully everything will go Normal

Error in running Android's TouchPaint example program

I am just trying out the "TouchPaint" sample provided by Google Android examples at:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html
Created my own AndroidManifest.xml, and I figured that "GraphicsActivity.java" and "PictureLayout.java" are two other java files before I could compiled and create the apk successfully.
After I load into my Android phone, it displayed a blank screen. At this point nothing happened yet, but once I touch the screen, the apps died, and generated the following trace in logcat output:
D/dalvikvm( 4939): GC_CONCURRENT freed 44K, 49% free 2779K/5379K, external 3286K/4104K, paused 4ms+2ms
D/dalvikvm( 365): GC_CONCURRENT freed 1102K, 54% free 3271K/7047K, external 2612K/3262K, paused 4ms+4ms
I/ActivityManager( 266): Displayed com.example.android.apis.graphics/.TouchPaint: +382ms
D/AndroidRuntime( 4939): Shutting down VM
W/dalvikvm( 4939): threadid=1: thread exiting with uncaught exception (group=0x2aac8578)
E/AndroidRuntime( 4939): FATAL EXCEPTION: main
E/AndroidRuntime( 4939): java.lang.NoSuchMethodError: android.view.MotionEvent.getButtonState
E/AndroidRuntime( 4939): at com.example.android.apis.graphics.TouchPaint$PaintView.onTouchOrHoverEvent(TouchPaint.java:346)
E/AndroidRuntime( 4939): at com.example.android.apis.graphics.TouchPaint$PaintView.onTouchEvent(TouchPaint.java:337)
E/AndroidRuntime( 4939): at android.view.View.dispatchTouchEvent(View.java:3952)
E/AndroidRuntime( 4939): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:961)
E/AndroidRuntime( 4939): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:961)
E/AndroidRuntime( 4939): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1711)
E/AndroidRuntime( 4939): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1145)
E/AndroidRuntime( 4939): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
E/AndroidRuntime( 4939): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1695)
E/AndroidRuntime( 4939): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2217)
E/AndroidRuntime( 4939): at android.view.ViewRoot.handleMessage(ViewRoot.java:1901)
E/AndroidRuntime( 4939): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 4939): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 4939): at android.app.ActivityThread.main(ActivityThread.java:3701)
E/AndroidRuntime( 4939): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4939): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 4939): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/AndroidRuntime( 4939): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
E/AndroidRuntime( 4939): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 266): Force finishing activity com.example.android.apis.graphics/.TouchPaint
W/ActivityManager( 266): Activity pause timeout for HistoryRecord{2afed900 com.example.android.apis.graphics/.TouchPaint}
I/InputDispatcher( 266): Application is not responding: Window{2b3f4d00 com.example.android.apis.graphics/com.example.android.apis.graphics.TouchPaint paused=false}. 5002.0ms since event, 5001.8ms since wait started
I/InputDispatcher( 266): Dropping event because the pointer is not down.
I/WindowManager( 266): Input event dispatching timed out sending to com.example.android.apis.graphics/com.example.android.apis.graphics.TouchPaint
W/ActivityManager( 266): Activity destroy timeout for HistoryRecord{2afed900 com.example.android.apis.graphics/.TouchPaint}
D/lights ( 266): set_light_backlight: brightness=20
I/ActivityManager( 266): No longer want com.facebook.katana (pid 4319): hidden #16
W/ActivityManager( 266): Scheduling restart of crashed service com.facebook.katana/.service.UploadManager in 5000ms
I am puzzled over what is the possible cause of crashing?
This method is only available since API Level 14, set minSdkVersion to 14 in the Manifest
public final int getButtonState ()
Since: API Level 14
Gets the state of all buttons that are pressed such as a mouse or stylus button.
Returns
The button state.
I found the answer:
http://developer.android.com/resources/dashboard/platform-versions.html
http://developer.android.com/guide/appendix/api-levels.html
From the web page's table, since I know my phone is using Android 2.3.4, so that max target API for SDK should be 10. So instead of using the TouchPaint.java sample from android-14, I copied the TouchPaint.java from android-10,change the minSDK version to 10 inside my AndroidManifest.xml file:
<uses-sdk android:minSdkVersion="10"/>
Everything works!! Thanks to Rajdeep Dua too!!!

Embedding Google MapView crashes android app

model : zt180
firmware : android 2.1-update1-20101030
kernel : 2.6.32.9 usbandroid #1608
build number zt180-eng 2.1-update1 20101030
google maps : 4.5.1
Various crashes occur when embedding the google maps component into an android application. I'm connecting to a router via Wi-Fi for internet access. The stand-alone google maps app seems to work fine. To re-produce, start the maps app and begin scrolling around.
Will fail within a couple of minutes, occasionally on start-up (in setContentView). Most of the errors are when drawing tiles in google code. Sometimes just an Android SEGV.
NOTE : I've tested the same app on the Android developer phone 2 (os 1.6), and it works fine.
My android app is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="043yBg1m9IiFNKXIhN5LsdeNndw2k7yrw4Ja3xQ"/>
</RelativeLayout>
import com.google.android.maps.MapActivity;
import android.os.Bundle;
public class Maps extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
protected boolean isRouteDisplayed() { return false; }
}
=========================
W/MapActivity( 2745): Recycling dispatcher com.google.googlenav.datarequest.DataRequestDispatcher#45ebcd30
V/MapActivity( 2745): Recycling map object.
I/ActivityManager( 2010): Displayed activity com.brta.android.lite/.Maps: 720 ms (total 720 ms)
I/MapActivity( 2745): Handling network change notification:CONNECTED
E/MapActivity( 2745): Couldn't get connection factory client
D/AndroidRuntime( 2745): Shutting down VM
W/dalvikvm( 2745): threadid=3: thread exiting with uncaught exception (group=0x4001b168)
E/AndroidRuntime( 2745): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 2745): java.lang.IncompatibleClassChangeError: interface not implemented
E/AndroidRuntime( 2745): at com.google.googlenav.map.Map.checkPaintTimeExceeded(Unknown Source)
E/AndroidRuntime( 2745): at com.google.googlenav.map.Map.drawMapBackground(Unknown Source)
E/AndroidRuntime( 2745): at com.google.googlenav.map.Map.drawMap(Unknown Source)
E/AndroidRuntime( 2745): at com.google.android.maps.MapView.drawMap(MapView.java:1048)
E/AndroidRuntime( 2745): at com.google.android.maps.MapView.onDraw(MapView.java:486)
<snip>
I/Process ( 2745): Sending signal. PID: 2745 SIG: 9
I/ActivityManager( 2010): Process com.brta.android.lite (pid 2745) has died.
I/WindowManager( 2010): WIN DEATH: Window{46112878 com.brta.android.lite/com.brta.android.lite.Maps paused=false}
I/UsageStats( 2010): Unexpected resume of org.adw.launcher while already resumed in com.brta.android.lite`
======================================================================
I/MapActivity( 2863): Handling network change notification:CONNECTED
E/MapActivity( 2863): Couldn't get connection factory client
D/dalvikvm( 2863): GC freed 8114 objects / 577376 bytes in 86ms
D/dalvikvm( 2863): GC freed 685 objects / 444384 bytes in 85ms
D/dalvikvm( 2863): GC freed 3458 objects / 259456 bytes in 79ms
I/ActivityManager( 2010): Displayed activity com.brta.android.lite/.Maps: 4407 ms (total 4407 ms)
D/AndroidRuntime( 2863): Shutting down VM
W/dalvikvm( 2863): threadid=3: thread exiting with uncaught exception (group=0x4001b168)
E/AndroidRuntime( 2863): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 2863): java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
E/AndroidRuntime( 2863): at java.util.Vector.elementAt(Vector.java:331)
E/AndroidRuntime( 2863): at com.google.googlenav.map.Map.drawTile(Unknown Source)
E/AndroidRuntime( 2863): at com.google.googlenav.map.Map.drawMapBackground(Unknown Source)
E/AndroidRuntime( 2863): at com.google.googlenav.map.Map.drawMap(Unknown Source)
E/AndroidRuntime( 2863): at com.google.android.maps.MapView.drawMap(MapView.java:1048)
E/AndroidRuntime( 2863): at com.google.android.maps.MapView.onDraw(MapView.java:486)
E/AndroidRuntime( 2863): at android.view.View.draw(View.java:6535)
E/AndroidRuntime( 2863): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
E/AndroidRuntime( 2863): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
<snip>
E/AndroidRuntime( 2863): at dalvik.system.NativeStart.main(Native Method)
I/Process ( 2010): Sending signal. PID: 2863 SIG: 3
I/dalvikvm( 2863): threadid=7: reacting to signal 3
I/dalvikvm( 2863): Wrote stack trace to '/data/anr/traces.txt'
I/Process ( 2863): Sending signal. PID: 2863 SIG: 9
I/WindowManager( 2010): WIN DEATH: Window{460ac708 com.brta.android.lite/com.brta.android.lite.Maps paused=false}
I/ActivityManager( 2010): Process com.brta.android.lite (pid 2863) has died.
I/UsageStats( 2010): Unexpected resume of org.adw.launcher while already resumed in com.brta.android.lite
W/InputManagerService( 2010): Got RemoteException sending setActive(false) notification to pid 2863 uid 10046
Basically, lots of bad things start happening...
The ZT-180 does not have Google Maps, AFAIK.

Exception on ListPreferences

This is my first Android app and I've encountered an exception when trying to use the ListPreference. The application loads along with the preferences... but when i touch the ListPreference entry the applications "stops unexpectedly".
Settings.java
public class Settings extends PreferenceActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.addPreferencesFromResource(R.layout.settings);
}
}
settings.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="chk_enabled"
android:summary="SMS response based on settings"
android:title="Enable"
/>
<ListPreference
android:title="Contacts"
android:summary="Contacs that will be sent SMSs"
android:key="list_contacts"
android:defaultValue="0"
android:entries="#array/list_entries"
android:entryValues="#array/list_values"
/>
</PreferenceScreen>
arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="list_entries">
<item>All</item>
<item>WhiteList</item>
<item>BlackList</item>
</string-array>
<integer-array name="list_values">
<item>0</item>
<item>1</item>
<item>2</item>
</integer-array>
</resources>
This is the logcat output:
D/AndroidRuntime( 3187): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
D/AndroidRuntime( 3187): CheckJNI is OFF
D/AndroidRuntime( 3187): --- registering native functions ---
I/jdwp ( 3187): received file descriptor 16 from ADB
/ddm-heap( 3187): Got feature list request
I/ActivityManager( 86): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=tml.UI.main/.MainActivity }
D/AndroidRuntime( 3187): Shutting down VM
D/dalvikvm( 3187): DestroyJavaVM waiting for non-daemon threads to exit
I/ActivityManager( 86): Start proc tml.UI.main for activity tml.UI.main/.MainActivity: pid=3194 uid=10039 gids={1015}
D/dalvikvm( 3187): DestroyJavaVM shutting VM down
D/dalvikvm( 3187): HeapWorker thread shutting down
D/dalvikvm( 3187): HeapWorker thread has shut down
D/jdwp ( 3187): JDWP shutting down net...
D/jdwp ( 3187): +++ peer disconnected
I/dalvikvm( 3187): Debugger has detached; object registry had 1 entries
D/dalvikvm( 3187): VM cleaning up
D/dalvikvm( 3187): LinearAlloc 0x0 used 676380 of 4194304 (16%)
I/jdwp ( 3194): received file descriptor 10 from ADB
D/ddm-heap( 3194): Got feature list request
W/Resources( 3194): Converting to string: TypedValue{t=0x10/d=0x0 a=-1}
I/ActivityManager( 86): Displayed activity tml.UI.main/.MainActivity: 977 ms (total 977 ms)
D/AndroidRuntime( 3194): Shutting down VM
W/dalvikvm( 3194): threadid=3: thread exiting with uncaught exception (group=0x4001da28)
E/AndroidRuntime( 3194): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 3194): java.lang.NullPointerException
E/AndroidRuntime( 3194): at android.preference.ListPreference.findIndexOfValue(ListPreference.java:169)
E/AndroidRuntime( 3194): at android.preference.ListPreference.getValueIndex(ListPreference.java:178)
E/AndroidRuntime( 3194): at android.preference.ListPreference.onPrepareDialogBuilder(ListPreference.java:190)
E/AndroidRuntime( 3194): at android.preference.DialogPreference.showDialog(DialogPreference.java:291)
E/AndroidRuntime( 3194): at android.preference.DialogPreference.onClick(DialogPreference.java:262)
E/AndroidRuntime( 3194): at android.preference.Preference.performClick(Preference.java:811)
E/AndroidRuntime( 3194): at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:190)
E/AndroidRuntime( 3194): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime( 3194): at android.widget.ListView.performItemClick(ListView.java:3246)
E/AndroidRuntime( 3194): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1635)
E/AndroidRuntime( 3194): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 3194): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 3194): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3194): at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 3194): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3194): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3194): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 3194): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E/AndroidRuntime( 3194): at dalvik.system.NativeStart.main(Native Method)
I/Process ( 86): Sending signal. PID: 3194 SIG: 3
I/dalvikvm( 3194): threadid=7: reacting to signal 3
I/dalvikvm( 3194): Wrote stack trace to '/data/anr/traces.txt'
I/Process ( 3194): Sending signal. PID: 3194 SIG: 9
I/ActivityManager( 86): Process tml.UI.main (pid 3194) has died.
I/WindowManager( 86): WIN DEATH: Window{4341fd00 tml.UI.main/tml.UI.main.MainActivity paused=false}
W/UsageStats( 86): Unexpected resume of com.android.launcher while already resumed in tml.UI.main
W/InputManagerService( 86): Got RemoteException sending setActive(false) notification to pid 3194 uid 10039
I fixed it... I kept on trying and, at the end, it turns out that I cannot use an integer-array as the entryValues Source. I just changed that integer-array to a string-array and got it working.
If there's a way to use integer-array as the source for entryValues please comment.
I've been searching for a similar solution to what you are looking for, agreeing that you should be able to use an Integer array to read from and store an integer result.
A solution to this problem I found was at http://kvance.livejournal.com/1039349.html, which I found to be useful.
It doesn't quite solve the problem the way I was thinking or that way I think you want it to, instead you still specify your initial / selection values with a String array although when the ListPreference saves it back to the SharedPreferences it saves as an Integer instead of a String (doing the conversion when the user selects it), removing the need to have to convert it possibly many times throughout your application when accessing the preference value.

I can`t do any action on new activity

I am new to android. I would like to ask you some question.
When I calling new activity from main activity by commands
Intent myIntent = new Intent(v.getContext(), PolarView.class);
//startActivityForResult(myIntent, 0);
startActivityForResult(myIntent, 0);
finish();
then in new activity I can't do any actions, e.g. such as button click
Both
Button btnSeven = (Button) this.findViewById(R.id.btn7);
btnSeven.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
InputStr = InputStr + "7";
InputViewField.setText(InputStr);
}
});
}
and
public void btn7_click(View v) {
InputStr = InputStr + "7";
InputViewField.setText(InputStr);
}
having defined android:onClick="btn7_click" in activity`s layout
where InputViewField is EditText object
In the first case new activity does not start, in the second case when I press this button, aplication crashes.
could you please help me?
Here is some last peace of logcat after change
StartActivityForResult()
to
StartActivity()
Logcat:
D/MediaScanner( 153): opendir /system/media/ failed, errno: 2
D/MediaScanner( 153): prescan time: 25225ms
D/MediaScanner( 153): scan time: 162ms
D/MediaScanner( 153): postscan time: 48ms
D/dalvikvm( 109): GC freed 1920 objects / 95640 bytes in 160ms
D/MediaScanner( 153): total time: 25435ms
D/MediaScannerService( 153): done scanning volume internal
D/MediaScannerService( 153): start scanning volume external
D/dalvikvm( 52): GREF has increased to 301
I/ActivityManager( 52): Starting activity: Intent { cmp=complex.ComplexCalc/.PolarView }
I/ActivityManager( 52): Displayed activity complex.ComplexCalc/.PolarView: 1414 ms (total 1414 ms)
V/MediaScanner( 153): pruneDeadThumbnailFiles... android.database.sqlite.SQLiteCursor#43bc30b8
V/MediaScanner( 153): /pruneDeadThumbnailFiles... android.database.sqlite.SQLiteCursor#43bc30b8
D/MediaScanner( 153): prescan time: 1509ms
D/MediaScanner( 153): scan time: 405ms
D/MediaScanner( 153): postscan time: 323ms
D/MediaScanner( 153): total time: 2237ms
D/MediaScannerService( 153): done scanning volume external
D/AndroidRuntime( 223): Shutting down VM
W/dalvikvm( 223): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 223): Uncaught handler: thread main exiting due to uncaught exception
D/dalvikvm( 223): GC freed 3456 objects / 221888 bytes in 153ms
E/AndroidRuntime( 223): java.lang.IllegalStateException: Could not execute method of the activity
E/AndroidRuntime( 223): at android.view.View$1.onClick(View.java:2031)
E/AndroidRuntime( 223): at android.view.View.performClick(View.java:2364)
E/AndroidRuntime( 223): at android.view.View.onTouchEvent(View.java:4179)
E/AndroidRuntime( 223): at android.widget.TextView.onTouchEvent(TextView.java:6541)
E/AndroidRuntime( 223): at android.view.View.dispatchTouchEvent(View.java:3709)
E/AndroidRuntime( 223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 223): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
E/AndroidRuntime( 223): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
E/AndroidRuntime( 223): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
E/AndroidRuntime( 223): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
E/AndroidRuntime( 223): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
E/AndroidRuntime( 223): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 223): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 223): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 223): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 223): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 223): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 223): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 223): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 223): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 223): at complex.ComplexCalc.PolarView.btn7_click(PolarView.java:266)
E/AndroidRuntime( 223): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 223): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 223): at android.view.View$1.onClick(View.java:2026)
E/AndroidRuntime( 223): ... 23 more
E/AndroidRuntime( 223): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 223): ... 27 more
I/Process ( 52): Sending signal. PID: 223 SIG: 3
I/dalvikvm( 223): threadid=7: reacting to signal 3
I/dalvikvm( 223): Wrote stack trace to '/data/anr/traces.txt'
I/ARMAssembler( 52): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x46eae8:0x46eba4] in 1562593 ns
I/ARMAssembler( 52): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x46eba8:0x46ed70] in 1903198 ns
I/Process ( 223): Sending signal. PID: 223 SIG: 9
I/ActivityManager( 52): Process complex.ComplexCalc (pid 223) has died.
I/WindowManager( 52): WIN DEATH: Window{43cc3920 complex.ComplexCalc/complex.ComplexCalc.PolarView paused=false}
E/gralloc ( 52): [unregister] handle 0x481778 still locked (state=40000001)
I/UsageStats( 52): Unexpected resume of com.android.launcher while already resumed in complex.ComplexCalc
W/InputManagerService( 52): Got RemoteException sending setActive(false) notification to pid 223 uid 10024
I think part of your problem is that you are using startActivityForResult(..), when in fact you should be using startActivity(..), because your new activity might not be returning anything.
However, without error logs its difficult to tell what is really happening

Categories

Resources