I am using code to populate an EditText view with a string from an array. I then use the .setSelection() function to move the cursor to the end of the view to more easily allow the user to append characters to the string. This works well for all strings of 8 characters or less. However, if the string from the array is greater than 8 characters I am receiving the following error message:
java.lang.IndexOutOfBoundsException: setSpan (9 ... 9) ends beyond length 8
Here is the code:
TransactionDataView = (EditText) findViewById(R.id.etTransactionData);
TransactionDataView.setText(TransactionData[TransactionDataIndex]);
TransactionDataView.setSelection(TransactionData[TransactionDataIndex].length());
From the LogCat I can see what the array subscript is, the string value and the length of the string. Immediately after trying to set the selection I receive the IndexOutOfBoundsException.
06-14 10:18:52.244: D/DataEntry(706): TransactionDataIndex = 0
06-14 10:18:52.244: D/DataEntry(706): TransactionData = 123456789
06-14 10:18:52.244: D/DataEntry(706): TransactionData.Length = 9
06-14 10:18:52.244: W/dalvikvm(706): threadid=1: thread exiting with uncaught exception (group=0x42065438)
06-14 10:18:52.264: E/AndroidRuntime(706): FATAL EXCEPTION: main
06-14 10:18:52.264: E/AndroidRuntime(706): java.lang.IllegalStateException: Could not execute method of the activity
06-14 10:18:52.264: E/AndroidRuntime(706): at android.view.View$1.onClick(View.java:3674)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.view.View.performClick(View.java:4198)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.view.View$PerformClick.run(View.java:17164)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.os.Handler.handleCallback(Handler.java:615)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.os.Looper.loop(Looper.java:137)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.app.ActivityThread.main(ActivityThread.java:4918)
06-14 10:18:52.264: E/AndroidRuntime(706): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 10:18:52.264: E/AndroidRuntime(706): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 10:18:52.264: E/AndroidRuntime(706): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
06-14 10:18:52.264: E/AndroidRuntime(706): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
06-14 10:18:52.264: E/AndroidRuntime(706): at dalvik.system.NativeStart.main(Native Method)
06-14 10:18:52.264: E/AndroidRuntime(706): Caused by: java.lang.reflect.InvocationTargetException
06-14 10:18:52.264: E/AndroidRuntime(706): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 10:18:52.264: E/AndroidRuntime(706): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.view.View$1.onClick(View.java:3669)
06-14 10:18:52.264: E/AndroidRuntime(706): ... 11 more
06-14 10:18:52.264: E/AndroidRuntime(706): Caused by: java.lang.IndexOutOfBoundsException: setSpan (9 ... 9) ends beyond length 8
06-14 10:18:52.264: E/AndroidRuntime(706): at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1016)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.text.Selection.setSelection(Selection.java:104)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.text.Selection.setSelection(Selection.java:115)
06-14 10:18:52.264: E/AndroidRuntime(706): at android.widget.EditText.setSelection(EditText.java:108)
06-14 10:18:52.264: E/AndroidRuntime(706): at com.worldgiftcard.mobileterminal.DataEntry.onClick(DataEntry.java:152)
06-14 10:18:52.264: E/AndroidRuntime(706): ... 14 more
Has anyone else encountered this? Is this a bug in the Android code? Can anyone suggest a work around?
Any assistance would be appreciated. Thanks.
Try changing
TransactionDataView.setSelection(TransactionData[TransactionDataIndex].length());
to
TransactionDataView.setSelection(TransactionDataView.getText().length());
In your IndexOutOfBoundsException, the length at the end (8) is not the length of the value of the EditText but is its android:maxLength attribute value.
In your case, this value is implicitely or explicitely set to 8, hence the reason for your exception.
You need to make sure you don't setSelection() beyond the maxLength of your EditText.
Rgds.
Related
I try to run iperf server and client in my android device so i develop an app using exec() and it is working fine for ls, ping etc. command but when i try to run iperf -s i got error, Here is the code and i added internet permission in manifest file. Help will appreciate
What will be the working directory and environment for iperf command??
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
}
I got following Error
06-14 13:14:01.023: W/System.err(1465): java.io.IOException: Error running exec(). Command: [iperf, -s] Working Directory: null Environment: null
06-14 13:14:01.033: W/System.err(1465): at java.lang.ProcessManager.exec(ProcessManager.java:211)
06-14 13:14:01.033: W/System.err(1465): at java.lang.Runtime.exec(Runtime.java:173)
06-14 13:14:01.053: W/System.err(1465): at java.lang.Runtime.exec(Runtime.java:246)
06-14 13:14:01.053: W/System.err(1465): at java.lang.Runtime.exec(Runtime.java:189)
06-14 13:14:01.053: W/System.err(1465): at com.learn2crack.androidshell.ShellExecuter.Executer(ShellExecuter.java:20)
06-14 13:14:01.053: W/System.err(1465): at com.learn2crack.androidshell.MainActivity$1.onClick(MainActivity.java:33)
06-14 13:14:01.063: W/System.err(1465): at android.view.View.performClick(View.java:4438)
06-14 13:14:01.063: W/System.err(1465): at android.view.View$PerformClick.run(View.java:18422)
06-14 13:14:01.063: W/System.err(1465): at android.os.Handler.handleCallback(Handler.java:733)
06-14 13:14:01.063: W/System.err(1465): at android.os.Handler.dispatchMessage(Handler.java:95)
06-14 13:14:01.063: W/System.err(1465): at android.os.Looper.loop(Looper.java:136)
06-14 13:14:01.073: W/System.err(1465): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-14 13:14:01.073: W/System.err(1465): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 13:14:01.073: W/System.err(1465): at java.lang.reflect.Method.invoke(Method.java:515)
06-14 13:14:01.083: W/System.err(1465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-14 13:14:01.083: W/System.err(1465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-14 13:14:01.103: W/System.err(1465): at dalvik.system.NativeStart.main(Native Method)
06-14 13:14:01.113: W/System.err(1465): Caused by: java.io.IOException: Permission denied
06-14 13:14:01.113: W/System.err(1465): at java.lang.ProcessManager.exec(Native Method)
06-14 13:14:01.113: W/System.err(1465): at java.lang.ProcessManager.exec(ProcessManager.java:209)
06-14 13:14:01.123: W/System.err(1465): ... 16 more
Sound a permissions problem check your logcat line:
Caused by: java.io.IOException: Permission denied
Maybe you can try execute a binary iperf in a external sd card? try to add permissions to read/write external storage.
when I import the viewpagerindicator project library into my application that works without the support library, it crashes on launch. I've tried it with more than one application with the same results. Here is the logcat output:
06-14 17:19:02.351: E/AndroidRuntime(589): FATAL EXCEPTION: main
06-14 17:19:02.351: E/AndroidRuntime(589): Process: com.example.android.navigationdrawerexample, PID: 589
06-14 17:19:02.351: E/AndroidRuntime(589): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.android.navigationdrawerexample.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.navigationdrawerexample-9.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.navigationdrawerexample-9, /vendor/lib, /system/lib]]
06-14 17:19:02.351: E/AndroidRuntime(589): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.app.ActivityThread.access$900(ActivityThread.java:161)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.os.Handler.dispatchMessage(Handler.java:102)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.os.Looper.loop(Looper.java:157)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.app.ActivityThread.main(ActivityThread.java:5356)
06-14 17:19:02.351: E/AndroidRuntime(589): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 17:19:02.351: E/AndroidRuntime(589): at java.lang.reflect.Method.invoke(Method.java:515)
06-14 17:19:02.351: E/AndroidRuntime(589): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
06-14 17:19:02.351: E/AndroidRuntime(589): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
06-14 17:19:02.351: E/AndroidRuntime(589): at dalvik.system.NativeStart.main(Native Method)
06-14 17:19:02.351: E/AndroidRuntime(589): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.navigationdrawerexample.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.navigationdrawerexample-9.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.navigationdrawerexample-9, /vendor/lib, /system/lib]]
06-14 17:19:02.351: E/AndroidRuntime(589): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
06-14 17:19:02.351: E/AndroidRuntime(589): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
06-14 17:19:02.351: E/AndroidRuntime(589): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
06-14 17:19:02.351: E/AndroidRuntime(589): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
06-14 17:19:02.351: E/AndroidRuntime(589): ... 11 more
So it turns out that the problem was that all of my android-support-v4.jar library files were different. So all I did was copied the latest v4 .jar files into the "libs" folder of both my project and library, added it to the build path, and voilĂ no more crashes!
I have a problem with my program... i want to do a simple seekbar that on change a toast appear with its value.
This is my code:
SeekBar seek = (SeekBar) findViewById(R.id.seekBar1);
seek.setOnSeekBarChangeListener( new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Toast.makeText(getApplicationContext(), progress, Toast.LENGTH_SHORT).show();
}
public void onStartTrackingTouch(SeekBar arg0) {
}
public void onStopTrackingTouch(SeekBar arg0) {
}
});
And this is my error (log):
06-14 22:18:16.330: E/AndroidRuntime(991): FATAL EXCEPTION: main
06-14 22:18:16.330: E/AndroidRuntime(991): android.content.res.Resources$NotFoundException: String resource ID #0x1
06-14 22:18:16.330: E/AndroidRuntime(991): at android.content.res.Resources.getText(Resources.java:229)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.widget.Toast.makeText(Toast.java:265)
06-14 22:18:16.330: E/AndroidRuntime(991): at com.neneinc.shakemute.MainActivity$2.onProgressChanged(MainActivity.java:48)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.widget.SeekBar.onProgressRefresh(SeekBar.java:91)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:660)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.widget.ProgressBar.refreshProgress(ProgressBar.java:672)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.widget.ProgressBar.setProgress(ProgressBar.java:719)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.widget.AbsSeekBar.trackTouchEvent(AbsSeekBar.java:424)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:362)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.View.dispatchTouchEvent(View.java:7127)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
06-14 22:18:16.330: E/AndroidRuntime(991): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
06-14 22:18:16.330: E/AndroidRuntime(991): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.View.dispatchPointerEvent(View.java:7307)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:163)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4205)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4245)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.Choreographer.doFrame(Choreographer.java:523)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.os.Handler.handleCallback(Handler.java:615)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.os.Looper.loop(Looper.java:137)
06-14 22:18:16.330: E/AndroidRuntime(991): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-14 22:18:16.330: E/AndroidRuntime(991): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 22:18:16.330: E/AndroidRuntime(991): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 22:18:16.330: E/AndroidRuntime(991): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-14 22:18:16.330: E/AndroidRuntime(991): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-14 22:18:16.330: E/AndroidRuntime(991): at dalvik.system.NativeStart.main(Native Method)
Don't pass the progress variable directly to makeText(Context, int, int) because that version of the method expects a resource id (an int value corresponding to an entry in the R autogenerated file). Pass String.valueOf(progress) instead, to convert it to a String and call makeText(Context, String, int). In other words, replace this:
Toast.makeText(getApplicationContext(), progress, Toast.LENGTH_SHORT).show();
with this:
Toast.makeText(getApplicationContext(), String.valueOf(progress), Toast.LENGTH_SHORT).show();
I can't find following error in my code. It looks like the problem is in the asynctask onpostexecute.
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:672)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:368)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:160)
at android.app.Dialog.dismissDialog(Dialog.java:319)
at android.app.Dialog.dismiss(Dialog.java:302)
at www.mobilezar.mn.Advertisements$InitialLoading.onPostExecute(Advertisements.java:216)
at www.mobilezar.mn.Advertisements$InitialLoading.onPostExecute(Advertisements.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
06-14 22:13:33.992: ERROR/AndroidRuntime(331): Uncaught handler: thread main exiting due to uncaught exception
06-14 22:13:34.031: ERROR/AndroidRuntime(331): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.HelloMap}: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.maps.MapView
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.os.Looper.loop(Looper.java:123)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Method.invoke(Method.java:521)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at dalvik.system.NativeStart.main(Native Method)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.maps.MapView
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.Activity.setContentView(Activity.java:1622)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.example.HelloMap.onCreate(HelloMap.java:16)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): ... 11 more
06-14 22:13:34.031: ERROR/AndroidRuntime(331): Caused by: java.lang.reflect.InvocationTargetException
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.google.android.maps.MapView.<init>(MapView.java:237)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Constructor.constructNative(Native Method)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): ... 21 more
06-14 22:13:34.031: ERROR/AndroidRuntime(331): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity.
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.google.android.maps.MapView.<init>(MapView.java:281)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.google.android.maps.MapView.<init>(MapView.java:254)
06-14 22:13:34.031: ERROR/AndroidRuntime(331): ... 25 more
I had done all configuration.
Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name="com.example.HelloMap"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and my layout file main.xml is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
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="*************"
/>
</RelativeLayout>
And my Hellomap.java
public class HelloMap extends Activity {
LinearLayout linearLayout;
MapView mapView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
protected boolean isRouteDisplayed() {
return false;
}
}
Something I am missing I guess, or maybe the issue is with 2.1 Google API?
i got my answere myself
just see the exception log
last lines
MapViews can only be created inside instances of MapActivity. 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.google.android.maps.MapView.(MapView.java:281) 06-14 22:13:34.031:
that means you need to extend your activity with MapActivity not Activity i guess most of you know but i got to know now
:)
I had this problem and solved it by the following 2 steps:
1) Put the following line in the application (important) element of AndroidManifest.xml file.
<uses-library android:name="com.google.android.maps" />
2) extend MapActivity instead of Activity.
enjoy!
Here i change Activity to MapActivity.
So Instead of
public class HelloMap extends Activity {
change it to
public class HelloMap extends MapActivity {
If you are new in using google maps and you have set the xml and activity and you got this type of error, then it means that you have't extend your class from MapsActivity, so extend your class from mapsactivity, it will start working !
//wrong usage of activity
public class A extends Actvitiy
{
}
//correct usage
public class A extedns MapsActivity {
//your all program...
}