how to show alert after calling the webservice [duplicate] - android

This question already has an answer here:
how to show alert inside an activity group?
(1 answer)
Closed 8 years ago.
In my activity I am calling webservices. So after the webservice returns the result, I have to show an alert. Since alert is UI part, I think inside onPostExecute() I have to write the alert code. But when I do like that error is coming.
Error shown:
12-02 09:59:08.508: ERROR/AndroidRuntime(451): Uncaught handler: thread main exiting
due to uncaught exception
12-02 09:59:08.528: ERROR/AndroidRuntime(451):
android.view.WindowManager$BadTokenException: Unable to add window -- token
android.app.LocalActivityManager$LocalActivityRecord#4378eb50 is not valid; is your
activity running?
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.view.ViewRoot.setView(ViewRoot.java:456)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.view.Window$LocalWindowManager.addView(Window.java:409)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.app.Dialog.show(Dialog.java:238)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.app.AlertDialog$Builder.show(AlertDialog.java:802)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at com.myapp.android.activities.Register$PostCodeTask.onPostExecute(Register.java:291)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at com.myapp.android.activities.Register$PostCodeTask.onPostExecute(Register.java:1)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.os.AsyncTask.finish(AsyncTask.java:416)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.os.AsyncTask.access$300(AsyncTask.java:127)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:428)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.os.Handler.dispatchMessage(Handler.java:99)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
android.os.Looper.loop(Looper.java:123)
android.app.ActivityThread.main(ActivityThread.java:4203)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
java.lang.reflect.Method.invokeNative(Native Method)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
java.lang.reflect.Method.invoke(Method.java:521)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
12-02 09:59:08.528: ERROR/AndroidRuntime(451): at dalvik.system.NativeStart.main(Native
Method)
Can anyone please help to solve my issue. Thanks in advance :)

You need to execute your alert code in UI thread. There are few ways of doing it for example
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(MyActivity.this, "Hello there", Toast.LENGTH_LONG).show();
}
});

Related

Launch Error on Android Application

I keep getting this error:
12-02 17:34:55.648: E/AndroidRuntime(426): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
12-02 17:34:55.648: E/AndroidRuntime(426): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:147)
12-02 17:34:55.648: E/AndroidRuntime(426): at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
12-02 17:34:55.648: E/AndroidRuntime(426): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
I have tried unimporting and reimporting android.support.v7.ActionBarActivity
I hope someone can guide me to what the error is

android random exception when resuming Unable to start activity ComponentInfo android.content.res.Resources$NotFoundException

I have quite strange exception which appears when my app is resumed (after I switch to other apps and then return to mine) although it's not thrown always but only from time to time.
The part where exception is quite simple. I use ViewPager (v4) and have two dialog classes, first child DialogHelp:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState); [line 50]
second the parent PMDialogFragment (extends DialogFragment):
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
app = (PMApplication) getActivity().getApplication();
View view = inflater.inflate(layoutId, container); [line 50]
and below logcat:
12-02 00:48:04.532: E/AndroidRuntime(22292): FATAL EXCEPTION: main
12-02 00:48:04.532: E/AndroidRuntime(22292): java.lang.RuntimeException: Unable to start activity ComponentInfo{pitersoft.pitermemoflashcards/pitermemo.android.gui.activities.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1964)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1989)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.ActivityThread.access$600(ActivityThread.java:126)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1155)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.os.Looper.loop(Looper.java:137)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.ActivityThread.main(ActivityThread.java:4482)
12-02 00:48:04.532: E/AndroidRuntime(22292): at java.lang.reflect.Method.invokeNative(Native Method)
12-02 00:48:04.532: E/AndroidRuntime(22292): at java.lang.reflect.Method.invoke(Method.java:511)
12-02 00:48:04.532: E/AndroidRuntime(22292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
12-02 00:48:04.532: E/AndroidRuntime(22292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
12-02 00:48:04.532: E/AndroidRuntime(22292): at dalvik.system.NativeStart.main(Native Method)
12-02 00:48:04.532: E/AndroidRuntime(22292): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.content.res.Resources.getValue(Resources.java:1041)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2191)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.content.res.Resources.getLayout(Resources.java:880)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-02 00:48:04.532: E/AndroidRuntime(22292): at pitermemo.android.gui.dialogs.PMDialogFragment.onCreateView(PMDialogFragment.java:50)
12-02 00:48:04.532: E/AndroidRuntime(22292): at pitermemo.android.gui.dialogs.DialogHelp.onCreateView(DialogHelp.java:50)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.Activity.performStart(Activity.java:4475)
12-02 00:48:04.532: E/AndroidRuntime(22292): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1937)
12-02 00:48:04.532: E/AndroidRuntime(22292): ... 11 more
I really don't know what causes that and how to solve this. If it was repeated always, it would be much easier.
I'm thinking perhaps it's somehow related with WebView component which likes to make problems. Another suspicious thing is in onResume of main app I run sometimes AsyncTask. But the log doesn't suggest this.
Do you have any suggestions what can cause this? Thanks in advance. (android min sdk 11, run on device with android 4.0.4).

the application myapp(process com.example.package) has stopped unexpectedly please try again

I had so many troubles with my android app. it can't run but now I could make it, unfortunately, I receive the error" the application myapp(process com.example.package) has stopped unexpectedly please try again)
here is my log file
12-02 11:25:11.980: E/MediaPlayer(278): Unable to to create media player
12-02 11:25:12.290: D/MediaPlayer(278): create failed:
12-02 11:25:12.290: D/MediaPlayer(278): java.io.IOException: setDataSourceFD failed.: status=0x80000000
12-02 11:25:12.290: D/MediaPlayer(278): at android.media.MediaPlayer.setDataSource(Native Method)
12-02 11:25:12.290: D/MediaPlayer(278): at android.media.MediaPlayer.create(MediaPlayer.java:645)
12-02 11:25:12.290: D/MediaPlayer(278): at com.mohammed.watzIslam.Mymain.onCreate(Mymain.java:27)
12-02 11:25:12.290: D/MediaPlayer(278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-02 11:25:12.290: D/MediaPlayer(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-02 11:25:12.290: D/MediaPlayer(278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-02 11:25:12.290: D/MediaPlayer(278): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-02 11:25:12.290: D/MediaPlayer(278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-02 11:25:12.290: D/MediaPlayer(278): at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 11:25:12.290: D/MediaPlayer(278): at android.os.Looper.loop(Looper.java:123)
12-02 11:25:12.290: D/MediaPlayer(278): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-02 11:25:12.290: D/MediaPlayer(278): at java.lang.reflect.Method.invokeNative(Native Method)
12-02 11:25:12.290: D/MediaPlayer(278): at java.lang.reflect.Method.invoke(Method.java:521)
12-02 11:25:12.290: D/MediaPlayer(278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-02 11:25:12.290: D/MediaPlayer(278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-02 11:25:12.290: D/MediaPlayer(278): at dalvik.system.NativeStart.main(Native Method)
12-02 11:25:12.290: D/AndroidRuntime(278): Shutting down VM
12-02 11:25:12.290: W/dalvikvm(278): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-02 11:25:12.300: E/AndroidRuntime(278): FATAL EXCEPTION: main
12-02 11:25:12.300: E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mohammed.watzIslam/com.mohammed.watzIslam.Mymain}: java.lang.NullPointerException
12-02 11:25:12.300: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.os.Looper.loop(Looper.java:123)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-02 11:25:12.300: E/AndroidRuntime(278): at java.lang.reflect.Method.invokeNative(Native Method)
12-02 11:25:12.300: E/AndroidRuntime(278): at java.lang.reflect.Method.invoke(Method.java:521)
12-02 11:25:12.300: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-02 11:25:12.300: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-02 11:25:12.300: E/AndroidRuntime(278): at dalvik.system.NativeStart.main(Native Method)
12-02 11:25:12.300: E/AndroidRuntime(278): Caused by: java.lang.NullPointerException
12-02 11:25:12.300: E/AndroidRuntime(278): at com.mohammed.watzIslam.Mymain.onCreate(Mymain.java:28)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-02 11:25:12.300: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-02 11:25:12.300: E/AndroidRuntime(278): ... 11 more
12-02 11:25:11.980: E/MediaPlayer(278): Unable to to create media player
12-02 11:25:12.290: D/MediaPlayer(278): create failed:
12-02 11:25:12.290: D/MediaPlayer(278): java.io.IOException: setDataSourceFD failed.: status=0x80000000
12-02 11:25:12.290: D/MediaPlayer(278): at android.media.MediaPlayer.setDataSource(Native Method)
My guess is that you're trying to load a media file that's not there, or the file name is just incorrect.

Using Sharedpreferences in broadcastreceiver due to error

BroadcastReceiver's code is a separate unit SMSReceiver.java. The Receiver declared in the Manifest with an SMS Receive Intent Filter. So it is "always on". When the application is running or just in the list of last 8 application it's working fine when get incoming SMS. But later, when application is deleted from memory, and only receiver stands by, incoming SMS due to error. The fact that I use in receiver's code Sharedpreferences. When I get some information from received SMS I should save it in preferences for loading by main Activity later.
LogCat shows me a string with error.
public class SmsReceiver extends BroadcastReceiver
{
public static SharedPreferences mStatePrefs;
#Override
public void onReceive(Context context, Intent intent)
{
//... some code
SharedPreferences.Editor ed = mStatePrefs.edit(); //HERE I GET AN EXCEPTION
//... some code
}
}
LogCat log..
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): FATAL EXCEPTION: main
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): java.lang.RuntimeException: Unable to start receiver com.example.android.MyApplication.SmsReceiver: java.lang.NullPointerException
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2034)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at android.app.ActivityThread.access$2400(ActivityThread.java:132)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1098)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at android.os.Looper.loop(Looper.java:143)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at android.app.ActivityThread.main(ActivityThread.java:4268)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at java.lang.reflect.Method.invokeNative(Native Method)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at java.lang.reflect.Method.invoke(Method.java:507)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at dalvik.system.NativeStart.main(Native Method)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): Caused by: java.lang.NullPointerException
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at com.example.android.MyApplication.SmsReceiver.onReceive(SmsReceiver.java:198)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2019)
12-02 22:36:03.887: ERROR/AndroidRuntime(18345): ... 10 more
So it works fine when app is active or in memory. But when the receiver was left alone, the error has occurred. So what I need to do, to fix this problem? It's a block bug for my app, this receiver is main solution, a sense of program. It must work always and save information in preferences.
You never get a SharedPreference instance for mStatePrefs. Looking at just the code you show, mStatePrefs would still be null.
Try:
mStatePrefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor ed = mStatePrefs.edit();

Error swapping / adding an XML Fragment

I have been struggling with the Android 3.0 SDK's fragments concept for a few days now, and thought I'd try StackOverflow....
I have a simple (proof on concept) app:
Here is my main layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:id="#+id/relativeLayout1" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="200dp">
<fragment android:name="com.owentech.simplefragmentswap.staticfragment"
android:id="#+id/fragment1" android:layout_weight="1"
android:layout_height="wrap_content" android:layout_width="fill_parent"/>
</RelativeLayout>
<FrameLayout android:id="#+id/frameLayout1" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_width="match_parent" android:layout_above="#+id/relativeLayout1"></FrameLayout>
</RelativeLayout>
I display one fragment (staticfragment) directly in the XML, this works fine.
With the framelayout I wanted to add an XML fragment (fragment1) on create.
Here is fragment1:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:layout_height="wrap_content" android:id="#+id/button1" android:layout_alignParentTop="true" android:layout_width="match_parent" android:text="Fragment 1"></Button>
</RelativeLayout>
Here is my mainactivity:
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
public class mainActivity extends FragmentActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create new fragment and transaction
Fragment newFragment = new fragment1();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
//transaction.replace(R.id.frameLayout1, newFragment);
transaction.add(R.id.frameLayout1, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
}
This causes a force close on start.
Here is the logcat:
05-18 09:49:23.073: INFO/ActivityManager(71): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.owentech.simplefragmentswap/.mainActivity }
05-18 09:49:23.313: INFO/ActivityManager(71): Start proc com.owentech.simplefragmentswap for activity com.owentech.simplefragmentswap/.mainActivity: pid=451 uid=10036 gids={1015}
05-18 09:49:23.324: DEBUG/AndroidRuntime(445): Shutting down VM
05-18 09:49:23.333: DEBUG/dalvikvm(445): Debugger has detached; object registry had 1 entries
05-18 09:49:23.404: INFO/AndroidRuntime(445): NOTE: attach of thread 'Binder Thread #3' failed
05-18 09:49:24.433: DEBUG/AndroidRuntime(451): Shutting down VM
05-18 09:49:24.433: WARN/dalvikvm(451): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): FATAL EXCEPTION: main
**05-18 09:49:24.473: ERROR/AndroidRuntime(451): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.owentech.simplefragmentswap/com.owentech.simplefragmentswap.mainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.**
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.os.Looper.loop(Looper.java:123)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at java.lang.reflect.Method.invoke(Method.java:521)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at dalvik.system.NativeStart.main(Native Method)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.view.ViewGroup.addView(ViewGroup.java:1865)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.view.ViewGroup.addView(ViewGroup.java:1822)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.view.ViewGroup.addView(ViewGroup.java:1802)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:743)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:933)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:916)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.support.v4.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1587)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:500)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.Activity.performStart(Activity.java:3781)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
05-18 09:49:24.473: ERROR/AndroidRuntime(451): ... 11 more
05-18 09:49:24.494: WARN/ActivityManager(71): Force finishing activity com.owentech.simplefragmentswap/.mainActivity
Does anybody know what I am doing wrong, as I have taken the code directly from developer.android.com
Thanks
Sorry, found the answer. When I inflated the view in my fragment1.java it was attached to root. changed the last flag to false, now ok.

Categories

Resources