Error SeekBar Android - android

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();

Related

NetHttpClient and SocketTimeoutException

I have an android app that is working through wifi and connect only to a local server. Normally the internet must be very fast and everything must work fine, however often i have some SocketTimeoutException :
06-14 01:40:38.141: W/System.err(30529): java.net.SocketTimeoutException
06-14 01:40:38.146: W/System.err(30529): at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
06-14 01:40:38.146: W/System.err(30529): at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
06-14 01:40:38.146: W/System.err(30529): at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
06-14 01:40:38.146: W/System.err(30529): at com.android.okio.Okio$2.read(Okio.java:116)
06-14 01:40:38.146: W/System.err(30529): at com.android.okio.RealBufferedSource.indexOf(RealBufferedSource.java:150)
06-14 01:40:38.146: W/System.err(30529): at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:97)
06-14 01:40:38.146: W/System.err(30529): at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:202)
06-14 01:40:38.146: W/System.err(30529): at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:119)
06-14 01:40:38.146: W/System.err(30529): at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:798)
06-14 01:40:38.146: W/System.err(30529): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:405)
06-14 01:40:38.146: W/System.err(30529): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:349)
06-14 01:40:38.146: W/System.err(30529): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getHeaderFieldKey(HttpURLConnectionImpl.java:174)
I can't understand as the server is local and connected directly to the wifi rooter. When i see on the log on the server when i have a SocketTimeoutException then i can see that no request reach the server.
This SocketTimeoutException is very random, sometime one every hours, sometime more sometime less. sometime i don't have SocketTimeoutException but the connection is very slow to establish.
Any idea what could be the reason or how can i debug/find the problem ?

Is it possible to open new activity from a fragment without trigger button?

This is my code to open new activity from a fragment by using a button.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.hello_world, container, false);
Button newActivity = (Button) v.findViewById(R.id.click);
newActivity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
goToActivity();
}
});
return v;
}
public void goToActivity(){
Intent intent = new Intent(getActivity(), HomeActivity.class);
startActivity(intent);
getActivity().finish();
}
Is it possible to open new activity from a fragment without a trigger button?? Because I have facing a lot of error when open new activity and close fragment activity directly like this :
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.hello_world, container, false);
goToActivity();
return v;
}
public void goToActivity(){
Intent intent = new Intent(getActivity(), HomeActivity.class);
startActivity(intent);
getActivity().finish();
}
EDIT :
Adding error log
06-14 11:52:45.394: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41b682e0 that was originally added here
06-14 11:52:45.394: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41b682e0 that was originally added here
06-14 11:52:45.394: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.394: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.394: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.394: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.394: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.394: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.394: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.394: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.394: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.394: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.394: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.394: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.394: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.394: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.394: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.394: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.394: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.394: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.394: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.394: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.394: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.394: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.394: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.394: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.404: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41a37398 that was originally added here
06-14 11:52:45.404: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41a37398 that was originally added here
06-14 11:52:45.404: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.404: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.404: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.404: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.404: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.404: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.404: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.404: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.404: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.404: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.404: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.404: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.404: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.404: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.404: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.404: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.404: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.404: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.404: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.404: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.404: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.404: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.404: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.404: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.414: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bd4ed8 that was originally added here
06-14 11:52:45.414: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bd4ed8 that was originally added here
06-14 11:52:45.414: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.414: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.414: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.414: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.414: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.414: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.414: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.414: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.414: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.414: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.414: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.414: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.414: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.414: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.414: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.414: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.414: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.414: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.414: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.414: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.414: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.414: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.414: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.414: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.424: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bbadd0 that was originally added here
06-14 11:52:45.424: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bbadd0 that was originally added here
06-14 11:52:45.424: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.424: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.424: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.424: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.424: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.424: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.424: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.424: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.424: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.424: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.424: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.424: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.424: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.424: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.424: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.424: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.424: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.424: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.424: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.424: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.424: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.424: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.424: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.424: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.434: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41c2cf80 that was originally added here
06-14 11:52:45.434: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41c2cf80 that was originally added here
06-14 11:52:45.434: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.434: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.434: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.434: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.434: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.434: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.434: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.434: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.434: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.434: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.434: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.434: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.434: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.434: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.434: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.434: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.434: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.434: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.434: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.434: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.434: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.434: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.434: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.434: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.444: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41c00460 that was originally added here
06-14 11:52:45.444: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41c00460 that was originally added here
06-14 11:52:45.444: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.444: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.444: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.444: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.444: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.444: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.444: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.444: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.444: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41cd3e60 that was originally added here
06-14 11:52:45.444: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41cd3e60 that was originally added here
06-14 11:52:45.444: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.444: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.444: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.444: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.444: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.444: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.444: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.444: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.444: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.444: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.444: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.464: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41ce2fa8 that was originally added here
06-14 11:52:45.464: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41ce2fa8 that was originally added here
06-14 11:52:45.464: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.464: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.464: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.Looper.loop(Looper.java:137)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.ActivityThread.main(ActivityThread.java:4794)
06-14 11:52:45.464: E/WindowManager(3501): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:52:45.464: E/WindowManager(3501): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:52:45.464: E/WindowManager(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-14 11:52:45.464: E/WindowManager(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-14 11:52:45.464: E/WindowManager(3501): at dalvik.system.NativeStart.main(Native Method)
06-14 11:52:45.464: E/WindowManager(3501): Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41c66798 that was originally added here
06-14 11:52:45.464: E/WindowManager(3501): android.view.WindowLeaked: Activity com.arbalest.example.NewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41c66798 that was originally added here
06-14 11:52:45.464: E/WindowManager(3501): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-14 11:52:45.464: E/WindowManager(3501): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.Dialog.show(Dialog.java:277)
06-14 11:52:45.464: E/WindowManager(3501): at com.arbalest.example.HomeFragment$LoadPanoramaJSON.onPreExecute(HomeFragment.java:95)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-14 11:52:45.464: E/WindowManager(3501): at com.arbalest.example.HomeFragment.onCreateView(HomeFragment.java:75)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-14 11:52:45.464: E/WindowManager(3501): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.Handler.handleCallback(Handler.java:615)
06-14 11:52:45.464: E/WindowManager(3501): at android.os.Handler.dispatchMessage(Handler.java:92)
..and a lot more..
First, you do not need to call .finish() on your activity in this way. The android Activity lifecycle handles this for you automatically.
When you start a new activity with startActivity(intent) the previous activity will automatically have it's lifecycle methods called (initially onPause(), then onStop() etc).
Secondly, a Fragment is displayed by an Activity. Why would you want a Fragment to start a different Activity as soon as the Fragment's view is created? I think you may need to read further about the Fragment and Activity lifecycles.
Additional:
When you start a new activity, the previous activity gets added to the backstack. You can think of the backstack as a history for the activities in your app. Each time you hit the back button, you go back in the app's activity history. You can stop an activity from being added to the backstack by setting android:noHistory=true" for that particular activity in your AndroidManifest.xml file.
<activity
android:name="xxx.xxxxxxx.xxxxxxx.MyActivity"
android:label="#string/app_name"
android:noHistory="true"
android:configChanges="orientation"
android:screenOrientation="portrait"/>
Try calling the goToActivity() method from within onResume().

EditText setSelection Not Working for Positions Greater Than 8

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.

Set header to listview from layout

everybody!
I got such situation: I have a layout with some views and a listView. A question is: is it possible to take those views (from the layout where listview is situated) and set them as a header to this listview?
By now I tried:
LinearLayout header = (LinearLayout)getView().findViewById(R.id.header);
listView.addHeaderView(header, null, true);
This gives me an error:
ERROR/AndroidRuntime(18913): FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
at android.widget.ListView.clearRecycledState(ListView.java:553)
at android.widget.ListView.resetList(ListView.java:539)
at android.widget.ListView.layoutChildren(ListView.java:1477)
at android.widget.AbsListView.onLayout(AbsListView.java:1407)
at android.view.View.layout(View.java:7314)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
at android.view.View.layout(View.java:7314)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7314)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
at android.view.View.layout(View.java:7314)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
at android.view.View.layout(View.java:7314)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7314)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
at android.view.View.layout(View.java:7314)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7314)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1180)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1900)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)

android hellomap example giving exception

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...
}

Categories

Resources