java.lang.IndexOutOfBoundsException: Invalid index x, size is y - android

I have an activity where there are 2 spinners. I fill the spinners with lists taken from an xml file like this one :
<outil id="1" name="Décompacteur">
<travail id="1">Travail au sol</travail>
<travail id="1001">Autre</travail>
</outil>
<outil id="2" name="Cultivateur">
<travail id="3">Travail au sol</travail>
<travail id="1002">Autre</travail>
</outil>
In another activity, I can change the file from which I build the lists.
My problem is : I select a tool (outil) at the end of a long list of tools, for example position = 6. Then I change the file, and the tool list now has only 4 items. I set a new adapter :
listNameOutil = getOutilNameList(listOutilObject);
adapterOutil = new ArrayAdapter<String>(this, R.layout.spinners_base, listNameOutil);
adapterOutil.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_outil.setAdapter(adapterOutil);
But I still get an error, and I don't know where it comes from provided there is no "caused by" in the stack trace... Please note that I also do a spinner_outil.setSelection(positionSaved);. At first, I was trying to catch the exception on this line but it seems that it's not this line which is the problem.
Any ideas to solve this?
Here is the Stack trace :
06-27 14:46:01.811: W/dalvikvm(20824): threadid=1: thread exiting with uncaught exception (group=0x40d0c930)
06-27 14:46:01.821: E/AndroidRuntime(20824): FATAL EXCEPTION: main
06-27 14:46:01.821: E/AndroidRuntime(20824): java.lang.IndexOutOfBoundsException: Invalid index 6, size is 4
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.util.ArrayList.get(ArrayList.java:304)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:337)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:390)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.Spinner.makeAndAddView(Spinner.java:546)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.Spinner.layout(Spinner.java:495)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.Spinner.onLayout(Spinner.java:459)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer.doFrame(Choreographer.java:532)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.os.Handler.handleCallback(Handler.java:725)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.os.Handler.dispatchMessage(Handler.java:92)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.os.Looper.loop(Looper.java:137)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.lang.reflect.Method.invoke(Method.java:511)
06-27 14:46:01.821: E/AndroidRuntime(20824): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-27 14:46:01.821: E/AndroidRuntime(20824): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-27 14:46:01.821: E/AndroidRuntime(20824): at dalvik.system.NativeStart.main(Native Method)
EDIT :
In the on Start, I bind to my service. Then, in onServiceConnected, I ask the service for configuration informations :
try {
remoteServiceMain.requeteLireConfig();
} catch (RemoteException e) {
e.printStackTrace();
}
Then, still in the onServiceConnected, I define the layout :
spinner_outil = (Spinner) findViewById(R.id.spinner_outil_layout);
spinner_outil.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
}
}
Then onServiceConnected is finished. Please note that I get the last log before error there.
REDDIT :
I do setSelection(positionSaved); after spinner_outil.setAdapter(adapterOutil);, and I set positionSaved when I get the answer from the service after calling :
try {
remoteServiceMain.requeteLireConfig();
} catch (RemoteException e) {
e.printStackTrace();
}
positionSaved is sent by the Service, which takes it from a Configuration File. positionSaved is saved evrytime the user clicks on an Item of the spinner. The reason why I get it from the service and not directly from the File is that I use the same method for other things

Related

Error creating Typeface

When I try to create a new Typeface using this piece of code on my Product class (custom class, has getView() method to populate a ListView)
Typeface tf = Typeface.createFromAsset(context.getApplicationContext().getAssets(), "fonts/cambriab.ttf");
I get the following stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:175)
at android.graphics.Typeface.createFromAsset(Typeface.java:149)
at com.darkraven.shoppinglist.Category.getView(Category.java:133)
at com.darkraven.shoppinglist.ProductListAdapter.getView(ProductListAdapter.java:40)
at android.widget.AbsListView.obtainView(AbsListView.java:2179)
at android.widget.ListView.makeAndAddView(ListView.java:1840)
at android.widget.ListView.fillDown(ListView.java:675)
at android.widget.ListView.fillFromTop(ListView.java:736)
at android.widget.ListView.layoutChildren(ListView.java:1641)
at android.widget.AbsListView.onLayout(AbsListView.java:2014)
at android.view.View.layout(View.java:14290)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
at android.view.View.layout(View.java:14290)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14290)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
at android.view.View.layout(View.java:14290)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14290)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
context is the main Activity.
If you have your ttf file placed in fonts folder in the assets , even the below code will work, or I can say it works for me ::
Typeface helveticaMedCond = Typefaces.get(getApplicationContext(), "fonts/Helvetica 67 Medium #2BD9AB.TTF");
before that cross verify whether you are using the same font name that is placed in the fonts folder or not.

Android Application crashes when trying to start new activity

I'm trying to start a new Activity, android. this is creating following error.
Note: i have updated the new activity in manifest
Logcat
06-27 18:00:39.543: D/AndroidRuntime(908): Shutting down VM
06-27 18:00:39.543: W/dalvikvm(908): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-27 18:00:39.563: E/AndroidRuntime(908): FATAL EXCEPTION: main
06-27 18:00:39.563: E/AndroidRuntime(908): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dipl.smpm.smpm/com.dipl.smpm.smpm.UpdateTask}: android.view.InflateException: Binary XML file line #15: Error inflating class button
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.os.Looper.loop(Looper.java:123)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.reflect.Method.invoke(Method.java:521)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-27 18:00:39.563: E/AndroidRuntime(908): at dalvik.system.NativeStart.main(Native Method)
06-27 18:00:39.563: E/AndroidRuntime(908): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class button
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.Activity.setContentView(Activity.java:1647)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.dipl.smpm.smpm.UpdateTask.onCreate(UpdateTask.java:11)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-27 18:00:39.563: E/AndroidRuntime(908): ... 11 more
06-27 18:00:39.563: E/AndroidRuntime(908): Caused by: java.lang.ClassNotFoundException: android.view.button in loader dalvik.system.PathClassLoader[/data/app/com.dipl.smpm.smpm-2.apk]
06-27 18:00:39.563: E/AndroidRuntime(908): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
It seems that You have defined Your Button inside the xml layout as
<button
android:layout_width="fill_parent"
..........
/>
but You have to write a capital b
<Button
android:layout_width="fill_parent"
............
/>
This is what the line says inside Error Message
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class button <--- You wrote button, but it has to be Button

How would I add points to a Google map view while still allowing the user to interact with the map?

I have a thread that receives map points which are sent from a server, and these points are added to the MapView. This works fine but if I interact with the MapView (eg. zoom in, pan, etc) I get a ConcurrentModificationException, so how can I allow access to the user while adding points to the MapView?
02-20 01:44:26.566: E/AndroidRuntime(9448): FATAL EXCEPTION: main
02-20 01:44:26.566: E/AndroidRuntime(9448): java.util.ConcurrentModificationException
02-20 01:44:26.566: E/AndroidRuntime(9448): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569)
02-20 01:44:26.566: E/AndroidRuntime(9448): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
02-20 01:44:26.566: E/AndroidRuntime(9448): at com.google.android.maps.MapView.onDraw(MapView.java:532)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.View.draw(View.java:13707)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.View.draw(View.java:13591)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.View.draw(View.java:13589)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.View.draw(View.java:13589)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.View.draw(View.java:13589)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.View.draw(View.java:13710)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.widget.FrameLayout.draw(FrameLayout.java:467)
02-20 01:44:26.566: E/AndroidRuntime(9448): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.Choreographer.doFrame(Choreographer.java:532)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.os.Handler.handleCallback(Handler.java:725)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.os.Handler.dispatchMessage(Handler.java:92)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.os.Looper.loop(Looper.java:137)
02-20 01:44:26.566: E/AndroidRuntime(9448): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-20 01:44:26.566: E/AndroidRuntime(9448): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 01:44:26.566: E/AndroidRuntime(9448): at java.lang.reflect.Method.invoke(Method.java:511)
02-20 01:44:26.566: E/AndroidRuntime(9448): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-20 01:44:26.566: E/AndroidRuntime(9448): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-20 01:44:26.566: E/AndroidRuntime(9448): at dalvik.system.NativeStart.main(Native Method)
Have you tried using the new maps api? Personally I found it much easier to use and easy to change from the old API to the new one.
Link: https://developers.google.com/maps/documentation/android/
One thing that I found particularly improved is the drawing on the map. No more messing with lots of overflows and so on.
Example of adding pins using the new API is:
final GoogleMap map = this.getMap();
final MarkerOptions marker = new MarkerOptions();
marker.position(latlng);
marker.draggable(false);
marker.icon(BitmapDescriptorFactory.fromResource(drawable));
map.addMarker(marker);
While it's appropriate to receive the points from the server in a background thread, you should actually add/update the points in the UI thread. This should prevent any concurrent modification issues. And as long as the addition/updating process isn't too heavy, it shouldn't interfere with the user experience significantly.
I have tried to extract and sanitize some of my old code that uses the old api.
The highlights are:
Create an overlay that is not yet on the map
Drawing and otherwise preparing the overlay
Adding the overlay to the map
Forcing the map to redraw
Add this method to your activity
// check if overlay we are adding was already added
final List<Overlay> listOfOverlays = this.mMapView.getOverlays();
if ((this.mPinsOverlay != null) && listOfOverlays.contains(this.mPinsOverlay))
{
listOfOverlays.remove(this.mPickupOverlay);
}
// create overlay
this.mPinsOverlay = new PinsOverlay();
// add overlay to map
listOfOverlays.add(this.mPinsOverlay);
// force map to redraw
this.mMapView.postInvalidate();
Custom Overlay class, not needed but keeps things neat.
public class PinsOverlay extends Overlay
{
public PinsOverlay()
{
super();
}
#Override
public boolean draw(final Canvas canvas, final MapView mapView, final boolean shadow, final long when)
{
super.draw(canvas, mapView, shadow);
// draw your pins here
return true;
}
}

Problem sending port-directed Data SMS on HTC EVO 4G

I am trying to send and receive port-directed SMS from an HTC EVO 4G to itself using SmsManager.sendDataMessage() and the device is giving a NullPointerException quite deep in the OS.
Here is the code that kicks off the exception:
manager.sendDataMessage(phonenumber, null, (short) 8091, data,piSend, piDelivered);
I think I have the appropriate permissions declared in the manifest:
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
Here's the stack trace I'm getting:
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): FATAL EXCEPTION: main
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): java.lang.NullPointerException
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Parcel.readException(Parcel.java:1328)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Parcel.readException(Parcel.java:1276)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.android.internal.telephony.ISms$Stub$Proxy.sen dData(ISms.java:682)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.telephony.SmsManager.sendDataMessage(SmsMa nager.java:546)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.varma.samples.smsdemo.MainActivity.sendSms(Mai nActivity.java:66)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.varma.samples.smsdemo.MainActivity.access$0(Ma inActivity.java:50)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.varma.samples.smsdemo.MainActivity$1.onClick(M ainActivity.java:98)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.view.View.performClick(View.java:2532)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.view.View$PerformClick.run(View.java:9293)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Handler.handleCallback(Handler.java:587 )
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Handler.dispatchMessage(Handler.java:92 )
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Looper.loop(Looper.java:143)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.app.ActivityThread.main(ActivityThread.jav a:4263)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at java.lang.reflect.Method.invoke(Method.java:507)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:839)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:597)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at dalvik.system.NativeStart.main(Native Method)
If anybody wants to try it out for themselves, I am using the example provided here in the SMSDemo project.
Can anybody help me out with this?
EDIT :
I have just put together a sample J2ME MIDlet to see if I can get it to work as well and it also fails. Does anybody remember any information about port-directed SMS? Is it handled differently on different networks? Is it all just outdated and I need to get with the times? Or is it something that I might be doing?
In case SMS is network dependent, I'm using Sprint devices but I'm developing in Canada, so I think they are roaming on Telus.

Memory leaks in android

I am developing an application that deals with storing lot of images in cache, I frequently encounter error like - out of memory. Can anyone suggest a way to deal with this issue
Error Log
Report of logcat :
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): FATAL EXCEPTION: main
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:450)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.content.res.Resources.loadDrawable(Resources.java:1709)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.content.res.Resources.getDrawable(Resources.java:581)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.view.View.setBackgroundResource(View.java:7533)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at com.lht.icruise.activity.shipdetails.ShipDetailsActivity.onCreate(ShipDetailsActivity.java:99)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.os.Looper.loop(Looper.java:123)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.main(ActivityThread.java:3647)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at java.lang.reflect.Method.invoke(Method.java:507)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at dalvik.system.NativeStart.main(Native Method)
If you using large bitmaps, recycling the bitmaps to free up memory using recycle() method on bitmap when that bitmap no more used, might help you.
Check if this answer helps you: Strange out of memory issue while loading an image to a Bitmap object

Categories

Resources