Force Close when i try to make a phone call - android

I am trying to make a phone call on a list item click.
Here is my code for the onclick listener:
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:5173237929"));
startActivity(intent);
}
});
And here is the permission i have in my manifest:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Why this is not working is beyond me.... Im creating the intent, and starting it, and then it force closes when i test it??? I feel like you guys on stack can solve this no prob =)
Edit:
[2011-08-27 09:43:00 - HelloListView] ------------------------------
[2011-08-27 09:43:00 - HelloListView] Android Launch!
[2011-08-27 09:43:00 - HelloListView] adb is running normally.
[2011-08-27 09:43:00 - HelloListView] Performing com.hlv.kk.HelloListView activity launch
[2011-08-27 09:43:04 - HelloListView] WARNING: Application does not specify an API levelrequirement!
[2011-08-27 09:43:04 - HelloListView] Device API version is 8 (Android 2.2.2)
[2011-08-27 09:43:05 - HelloListView] Application already deployed. No need to reinstall.
[2011-08-27 09:43:05 - HelloListView] Starting activity com.hlv.kk.HelloListView on device 04036CA51900D00F
[2011-08-27 09:43:05 - HelloListView] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.hlv.kk/.HelloListView }
Edit #2:
09-02 20:25:06.874: INFO/ActivityManager(6146): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
09-02 20:25:07.030: INFO/ActivityManager(6146): Starting activity: Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster }
09-02 20:25:07.045: WARN/ActivityManager(6146): Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{44a5f890 8386:com.hlv.kk/10051} (pid=8386, uid=10051) requires android.permission.CALL_PHONE
09-02 20:25:07.061: DEBUG/AndroidRuntime(8386): Shutting down VM
09-02 20:25:07.061: WARN/dalvikvm(8386): threadid=1: thread exiting with uncaught exception (group=0x4001d7e0)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): FATAL EXCEPTION: main
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): java.lang.RuntimeException: Unable to start activity ComponentInfo{android/com.android.internal.app.ChooserActivity}: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{44a5f890 8386:com.hlv.kk/10051} (pid=8386, uid=10051) requires android.permission.CALL_PHONE
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.os.Looper.loop(Looper.java:123)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at java.lang.reflect.Method.invoke(Method.java:521)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at dalvik.system.NativeStart.main(Native Method)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{44a5f890 8386:com.hlv.kk/10051} (pid=8386, uid=10051) requires android.permission.CALL_PHONE
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.os.Parcel.readException(Parcel.java:1247)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.os.Parcel.readException(Parcel.java:1235)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.Activity.startActivityForResult(Activity.java:2817)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.Activity.startActivity(Activity.java:2923)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:95)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:54)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-02 20:25:07.100: ERROR/AndroidRuntime(8386): ... 11 more
09-02 20:25:07.147: WARN/ActivityManager(6146): Force finishing activity android/com.android.internal.app.ChooserActivity
09-02 20:25:07.147: WARN/ActivityManager(6146): Force finishing activity com.hlv.kk/.HelloListView
09-02 20:25:07.647: WARN/ActivityManager(6146): Activity pause timeout for HistoryRecord{44ad1490 android/com.android.internal.app.ChooserActivity}
09-02 20:25:07.819: INFO/ActivityManager(6146): No longer want com.google.android.gallery3d (pid 8199): hidden #16
09-02 20:25:10.210: INFO/Process(8386): Sending signal. PID: 8386 SIG: 9
09-02 20:25:10.217: INFO/ActivityManager(6146): Process com.hlv.kk (pid 8386) has died.
09-02 20:25:10.217: INFO/WindowManager(6146): WIN DEATH: Window{44a05de8 com.hlv.kk/com.hlv.kk.HelloListView paused=false}
09-02 20:25:10.264: WARN/InputManagerService(6146): Got RemoteException sending setActive(false) notification to pid 8386 uid 10051
09-02 20:25:12.092: INFO/WindowManager(6146): Setting rotation to 3, animFlags=0
09-02 20:25:12.116: INFO/ActivityManager(6146): Config changed: { scale=1.0 imsi=310/4 loc=en_US touch=3 keys=2/1/2 nav=2/2 orien=2 layout=34 uiMode=17 seq=45}
09-02 20:25:12.163: INFO/UsageStats(6146): Unexpected resume of com.android.launcher while already resumed in com.android.launcher
09-02 20:25:13.186: DEBUG/dalvikvm(6224): GC_EXPLICIT freed 11518 objects / 579136 bytes in 69ms

I forgot to add the permission =/
My mistake lol
But for ppl who stumble on this page, if your having these same problems make sure you have added:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
To your manifest file right above the closing manifest tag
</manifest>
At the end of your manifest file
Sorry everybody else for wasting ur time

Try this one:
startActivity(Intent.createChooser(intent, "phone"));
instead of startActivity(intent)
EDIT:
Just a guess, but make sure that your permission is outside of the application tag:
<uses-permission android:name="android.permission.CALL_PHONE" />
<application ......

Related

pointing the error message in the following log snippet

Ok below here is what my log generates when I try to run my application . The application fails unexpectedly and does not even start
09-02 04:28:51.856: D/dalvikvm(781): GC_FOR_ALLOC freed 66K, 7% free 2542K/2728K, paused 51ms, total 66ms
09-02 04:28:51.866: I/dalvikvm-heap(781): Grow heap (frag case) to 3.181MB for 614500-byte allocation
09-02 04:28:51.936: D/dalvikvm(781): GC_FOR_ALLOC freed <1K, 6% free 3142K/3332K, paused 67ms, total 67ms
09-02 04:28:52.406: W/SoundPool(781): sample 1 not READY
09-02 04:28:53.116: D/gralloc_goldfish(781): Emulator without GPU emulation detected.
09-02 04:28:53.376: I/Choreographer(781): Skipped 33 frames! The application may be doing too much work on its main thread.
09-02 04:29:22.606: E/AudioTrack(781): Could not get audio output for stream type 3
09-02 04:29:22.606: E/SoundPool(781): Error creating AudioTrack
09-02 04:29:22.756: D/dalvikvm(781): GC_FOR_ALLOC freed 30K, 5% free 3523K/3672K, paused 19ms, total 21ms
09-02 04:29:22.756: I/dalvikvm-heap(781): Grow heap (frag case) to 4.159MB for 635812-byte allocation
09-02 04:29:22.856: D/dalvikvm(781): GC_FOR_ALLOC freed 1K, 4% free 4143K/4296K, paused 97ms, total 97ms
09-02 04:29:22.966: I/Choreographer(781): Skipped 91 frames! The application may be doing too much work on its main thread.
09-02 04:29:23.206: I/Choreographer(781): Skipped 55 frames! The application may be doing too much work on its main thread.
09-02 04:29:23.375: I/Choreographer(781): Skipped 35 frames! The application may be doing too much work on its main thread.
09-02 04:29:23.776: I/Choreographer(781): Skipped 79 frames! The application may be doing too much work on its main thread.
09-02 04:29:28.016: D/dalvikvm(781): GC_FOR_ALLOC freed 108K, 5% free 4436K/4664K, paused 111ms, total 133ms
09-02 04:29:28.045: I/dalvikvm-heap(781): Grow heap (frag case) to 5.030MB for 614500-byte allocation
09-02 04:29:28.096: D/dalvikvm(781): GC_FOR_ALLOC freed 1K, 5% free 5034K/5268K, paused 55ms, total 56ms
09-02 04:29:28.235: W/SoundPool(781): sample 1 not READY
09-02 04:29:28.785: I/Choreographer(781): Skipped 50 frames! The application may be doing too much work on its main thread.
09-02 04:29:31.626: E/AudioTrack(781): Could not get audio output for stream type 3
09-02 04:29:31.626: E/SoundPool(781): Error creating AudioTrack
09-02 04:29:31.746: E/SlaveBlueTooth(781): +++ ON CREATE +++
09-02 04:29:31.766: W/System.err(781): java.io.IOException: open failed: EROFS (Read-only file system)
09-02 04:29:31.776: W/System.err(781): at java.io.File.createNewFile(File.java:948)
09-02 04:29:31.785: W/System.err(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:118)
09-02 04:29:31.796: W/System.err(781): at android.app.Activity.performCreate(Activity.java:5133)
09-02 04:29:31.796: W/System.err(781): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-02 04:29:31.796: W/System.err(781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-02 04:29:31.816: W/System.err(781): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-02 04:29:31.816: W/System.err(781): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-02 04:29:31.816: W/System.err(781): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-02 04:29:31.826: W/System.err(781): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 04:29:31.826: W/System.err(781): at android.os.Looper.loop(Looper.java:137)
09-02 04:29:31.826: W/System.err(781): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-02 04:29:31.836: W/System.err(781): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 04:29:31.836: W/System.err(781): at java.lang.reflect.Method.invoke(Method.java:525)
09-02 04:29:31.846: W/System.err(781): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-02 04:29:31.846: W/System.err(781): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-02 04:29:31.856: W/System.err(781): at dalvik.system.NativeStart.main(Native Method)
09-02 04:29:31.856: W/System.err(781): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
09-02 04:29:31.876: W/System.err(781): at libcore.io.Posix.open(Native Method)
09-02 04:29:31.886: W/System.err(781): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
09-02 04:29:31.886: W/System.err(781): at java.io.File.createNewFile(File.java:941)
09-02 04:29:31.896: W/System.err(781): ... 15 more
09-02 04:29:32.016: D/AndroidRuntime(781): Shutting down VM
09-02 04:29:32.016: W/dalvikvm(781): threadid=1: thread exiting with uncaught exception (group=0x41465700)
09-02 04:29:32.066: E/AndroidRuntime(781): FATAL EXCEPTION: main
09-02 04:29:32.066: E/AndroidRuntime(781): java.lang.RuntimeException: Unable to start activity ComponentInfo{hellog.diwesh.NugaBest/helog.diwesh.NugaBest.BTSmartSlavemodule}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.os.Looper.loop(Looper.java:137)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-02 04:29:32.066: E/AndroidRuntime(781): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 04:29:32.066: E/AndroidRuntime(781): at java.lang.reflect.Method.invoke(Method.java:525)
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-02 04:29:32.066: E/AndroidRuntime(781): at dalvik.system.NativeStart.main(Native Method)
09-02 04:29:32.066: E/AndroidRuntime(781): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Activity.requestWindowFeature(Activity.java:3264)
09-02 04:29:32.066: E/AndroidRuntime(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:141)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Activity.performCreate(Activity.java:5133)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-02 04:29:32.066: E/AndroidRuntime(781): ... 11 more
This is the error from your LogCat :
FATAL EXCEPTION: main
09-02 04:29:32.066: E/AndroidRuntime(781): java.lang.RuntimeException: Unable to start activity ComponentInfo{hellog.diwesh.NugaBest/helog.diwesh.NugaBest.BTSmartSlavemodule}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
Multiple issues here:
09-02 04:29:31.766: W/System.err(781): java.io.IOException: open failed: EROFS (Read-only file system)
09-02 04:29:31.776: W/System.err(781): at java.io.File.createNewFile(File.java:948)
09-02 04:29:31.785: W/System.err(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:118)
In BTSmartSlavemodule.java line 118 you're trying to create a new file on a read-only file system.
09-02 04:29:32.066: E/AndroidRuntime(781): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Activity.requestWindowFeature(Activity.java:3264)
09-02 04:29:32.066: E/AndroidRuntime(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:141)
On line 141 of the same file you're trying to call requestWindowFeature() after calling setContentView(). You need to set window features before setContentView().
You call requestFeature() not in right place... try to call this method before setContentView(R.layout.activity)
The cause of this error is :
09-02 04:29:32.066: E/AndroidRuntime(781): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
And this cause happened at :
09-02 04:29:31.785: W/System.err(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:118)
Where you put code .requestWindowFeature(). To avoid this cause you must put this code before setContentView(R.layout.your_layout);
I think you are trying to create file on sdcard but you don't have specified permission to write external storage in manifest file
Add this line to manifest.xml file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Android app stops unexpectedly

I wrote a program for android which connects to internet.
I got the following error:
The application has stopped unexpectedly.Please try again..
What's the problem?
Log cat in Eclipse is as follows:
09-02 12:43:42.421: W/dalvikvm(12362): threadid=1: thread exiting with uncaught exception (group=0x40018578)
09-02 12:43:42.437: E/AndroidRuntime(12362): FATAL EXCEPTION: main
09-02 12:43:42.437: E/AndroidRuntime(12362): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.networkusage/com.example.networkusage.NetworkActivity}: java.lang.ClassNotFoundException: com.example.networkusage.NetworkActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.networkusage-1.apk]
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.os.Looper.loop(Looper.java:130)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.reflect.Method.invoke(Method.java:507)
09-02 12:43:42.437: E/AndroidRuntime(12362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-02 12:43:42.437: E/AndroidRuntime(12362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-02 12:43:42.437: E/AndroidRuntime(12362): at dalvik.system.NativeStart.main(Native Method)
09-02 12:43:42.437: E/AndroidRuntime(12362): Caused by: java.lang.ClassNotFoundException: com.example.networkusage.NetworkActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.networkusage-1.apk]
09-02 12:43:42.437: E/AndroidRuntime(12362): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
09-02 12:43:42.437: E/AndroidRuntime(12362): ... 11 more
Found that my package name is:
com.example.android.networkusage
and on the manifest is as:
android:name="com.example.networkusage.NetworkActivity"
so changed the manifest to:
android:name="com.example.android.networkusage.NetworkActivity"
Looks like your com.example.networkusage.NetworkActivity class is missing.
If it is declared in an external library, add that jar file to the "libs" folder and add it to the build path and then build your project again.
Don't forget to clean it too!

Draw differents strings on markers on a map

I drew some markers (from one drawable) on a mapview but I would like to display a different number on each marker.
Numbers are stored into an array. I made a function to write text above drawable and here is what I did :
List<Overlay> mapOverlays = mapView.getOverlays();
GeoPoint geoPoint = null;
Drawable marker;
int size = addresses.length;
marker = writeOnDrawable(R.drawable.marker, "10");//my number to write here
itemizedOverlay = new ItemizedOverlay(marker, mapView);
for(int i = 0; i < size; i++) {
geoPoint = new GeoPoint((int) (latitudes[i] * 1E6), (int) (longitudes[i] * 1E6));
itemizedOverlay.addOverlay(new OverlayItem(geoPoint, addresses[i], ""));
}
mapOverlays.add(itemizedOverlay);
However, in this code, I am displaying the same number for all the markers and I would like to use my array of number to display a different number for each of them.
Does this mean I have to use as many ItemizedOverlay as I have numbers?
Or do you have any suggestions?
I finally got it work by using several ItemizedOverlay.
I put this at the beginning of the for loop:
itemizedOverlay = new ItemizedOverlay(marker, mapView);
and this as well at the end:
mapOverlays.add(itemizedOverlay);
Everything worked fine on my device (GN) until I tested it on the VM where I got this:
09-02 09:36:56.335: E/dalvikvm-heap(231): 20424-byte external allocation too large for this process.
09-02 09:36:56.335: E/(231): VM won't let us allocate 20424 bytes
09-02 09:36:56.335: W/dalvikvm(231): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
09-02 09:36:56.335: E/AndroidRuntime(231): Uncaught handler: thread main exiting due to uncaught exception
09-02 09:36:56.386: E/AndroidRuntime(231): android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonOverlayView.setupView(BalloonOverlayView.java:79)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonOverlayView.<init>(BalloonOverlayView.java:58)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay.createBalloonOverlayView(BalloonItemizedOverlay.java:151)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay.createAndDisplayBalloonOverlay(BalloonItemizedOverlay.java:284)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay.onTap(BalloonItemizedOverlay.java:126)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:346)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:506)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.MapView.onTouchEvent(MapView.java:628)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.maps.TapControlledMapView.onTouchEvent(TapControlledMapView.java:62)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.View.dispatchTouchEvent(View.java:3672)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:850)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.os.Looper.loop(Looper.java:123)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.app.ActivityThread.main(ActivityThread.java:4203)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Method.invoke(Method.java:521)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
09-02 09:36:56.386: E/AndroidRuntime(231): at dalvik.system.NativeStart.main(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): Caused by: java.lang.reflect.InvocationTargetException
09-02 09:36:56.386: E/AndroidRuntime(231): at android.widget.LinearLayout.<init>(LinearLayout.java:92)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Constructor.constructNative(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
09-02 09:36:56.386: E/AndroidRuntime(231): ... 35 more
09-02 09:36:56.386: E/AndroidRuntime(231): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:439)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:322)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:688)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.Resources.loadDrawable(Resources.java:1710)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.Resources.getDrawable(Resources.java:585)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:146)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:779)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:720)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.Resources.loadDrawable(Resources.java:1695)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view
As I feared, it takes a lot of memory... is there a way to avoid this?
Do you think this will also happen on low memory devices?

Socket client program error

After the program running,click the send button,then pop-up dialog said the program has already exited。
I don‘t know what is the problem,how can I fix it?
Is there anybody has the same issue,can you help me?
package com.secion9.clienttest;
import android.os.Bundle;
import android.app.Activity;
import android.widget.*;
import java.net.Socket;
import java.io.IOException;
import java.io.OutputStream;
import android.view.View;
import android.view.View.OnClickListener;
public class ClientActivity extends Activity {
Button btSend;
EditText etMsg;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_client);
btSend=(Button)this.findViewById(R.id.button1);
etMsg=(EditText)this.findViewById(R.id.EditText1);
btSend.setOnClickListener(
new OnClickListener(){
public void onClick(View v)
{
try
{
Socket socket=new Socket("127.0.0.1",5050);
OutputStream outputStream=socket.getOutputStream();
byte[] buffer=etMsg.getText().toString().getBytes();
outputStream.write(buffer);
outputStream.flush();
}
catch(IOException e)
{
e.printStackTrace();
}
}
});
}
}
logcat
09-02 08:24:31.189: E/Trace(627): error opening trace file: No such file or directory (2)
09-02 08:24:32.259: D/gralloc_goldfish(627): Emulator without GPU emulation detected.
09-02 08:24:32.598: I/Choreographer(627): Skipped 40 frames! The application may be doing too much work on its main thread.
09-02 08:25:04.471: D/AndroidRuntime(627): Shutting down VM
09-02 08:25:04.471: W/dalvikvm(627): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-02 08:25:04.539: E/AndroidRuntime(627): FATAL EXCEPTION: main
09-02 08:25:04.539: E/AndroidRuntime(627): android.os.NetworkOnMainThreadException
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
09-02 08:25:04.539: E/AndroidRuntime(627): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
09-02 08:25:04.539: E/AndroidRuntime(627): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
09-02 08:25:04.539: E/AndroidRuntime(627): at libcore.io.IoBridge.connect(IoBridge.java:112)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.startupSocket(Socket.java:566)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.tryAllAddresses(Socket.java:127)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.<init>(Socket.java:177)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.<init>(Socket.java:149)
09-02 08:25:04.539: E/AndroidRuntime(627): at com.secion9.clienttest.ClientActivity$1.onClick(ClientActivity.java:31)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.view.View.performClick(View.java:4084)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.view.View$PerformClick.run(View.java:16966)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.Handler.handleCallback(Handler.java:615)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.Handler.dispatchMessage(Handler.java:92)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.Looper.loop(Looper.java:137)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.lang.reflect.Method.invoke(Method.java:511)
09-02 08:25:04.539: E/AndroidRuntime(627): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-02 08:25:04.539: E/AndroidRuntime(627): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-02 08:25:04.539: E/AndroidRuntime(627): at dalvik.system.NativeStart.main(Native Method)
09-02 08:25:07.079: I/Process(627): Sending signal. PID: 627 SIG: 9
It sounds like you're doing networking on the main thread. That's a no-no:
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
SOLUTION:
Modify your app so that it spawns off a thread or async task to do the network I/O.
Here's a good link that discusses how:
http://www.vogella.com/articles/AndroidPerformance/article.html
Have put in AndroidManifest.xml Internet permission?
Regards,
Skipped 40 frames! The application may be doing too much work on its main thread.
and
NetworkOnMainThreadException
Are there to tell you that you're blocking the main thread, which causes and ANR and the app can get killed :)
Try to implement your network stuff on a background thread, or with an AsyncTask
According to the documentation at [Android Developers][1]:
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.
So you need to target a lower SDK or make a new thread for handling networks connections.

Android call problem

I am using the codes below but my app force closes independently which one use. These are from several examples found on the net but none of them is working:
The semes2 variable is a phone number retrieved from the ContactsContract and is not null (verified by Toast msg).
Uri uri = Uri.fromParts("tel", semes2, null);
Intent callIntent = new Intent(Intent.ACTION_CALL, uri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
or
Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:6365551212"));
startActivity(dialIntent);
or
Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + semes2));
dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialIntent);
In the manifest i have <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
What am i missing?
Edit: logcat:
05-24 05:46:17.404: ERROR/AndroidRuntime(272): FATAL EXCEPTION: main
05-24 05:46:17.404: ERROR/AndroidRuntime(272): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel://+36301111111 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43f8e500 272:com.bfarago.nevnap/10048} (pid=272, uid=10048) requires android.permission.CALL_PHONE
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Parcel.readException(Parcel.java:1247)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Parcel.readException(Parcel.java:1235)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.Activity.startActivityForResult(Activity.java:2817)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.Activity.startActivity(Activity.java:2923)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.bfarago.nevnap.MainActivity$1$1$1.onClick(MainActivity.java:1363)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.widget.ListView.performItemClick(ListView.java:3382)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Handler.handleCallback(Handler.java:587)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Looper.loop(Looper.java:123)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at java.lang.reflect.Method.invoke(Method.java:521)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at dalvik.system.NativeStart.main(Native Method)
05-24 05:46:17.564: WARN/ActivityManager(58): Force finishing activity com.bfarago.nevnap/.MainActivity
05-24 05:46:18.224: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44011768 com.bfarago.nevnap/.MainActivity}
05-24 05:46:19.754: INFO/Process(272): Sending signal. PID: 272 SIG: 9
05-24 05:46:19.816: INFO/ActivityManager(58): Process com.bfarago.nevnap (pid 272) has died.
05-24 05:46:19.844: WARN/ActivityManager(58): Scheduling restart of crashed service com.bfarago.nevnap/.UpdateService in 5000ms
05-24 05:46:19.864: INFO/WindowManager(58): WIN DEATH: Window{43fac220 com.bfarago.nevnap/com.bfarago.nevnap.MainActivity paused=false}
05-24 05:46:19.864: INFO/WindowManager(58): WIN DEATH: Window{440383a8 com.bfarago.nevnap/com.bfarago.nevnap.MainActivity paused=false}
05-24 05:46:19.954: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 272 uid 10048
05-24 05:46:21.110: WARN/NotificationService(58): Object died trying to hide notification android.app.ITransientNotification$Stub$Proxy#43edd2c0 in package com.bfarago.nevnap
05-24 05:46:21.114: WARN/ActivityManager(58): setProcessForeground called on unknown pid: 272
05-24 05:46:24.944: INFO/ActivityManager(58): Start proc com.bfarago.nevnap for service com.bfarago.nevnap/.UpdateService: pid=286 uid=10048 gids={1015}
05-24 05:46:29.200: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44011768 com.bfarago.nevnap/.MainActivity}
05-24 05:46:30.605: DEBUG/dalvikvm(162): GC_EXPLICIT freed 2438 objects / 143352 bytes in 192ms
Found the solution. Instead of ACTION_CALL i should have used ACTION_DIAL. I can also remove the // after tel:, it doesn't matter. So e.g.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + semes2));
startActivity(intent);
However, the 2nd example is still force closes even though it has ACTION DIAL.
You should include the following permission android.permission.CALL_PHONE in your android manifest file :
<uses-permission android:name="android.permission.CALL_PHONE"/>

Categories

Resources