android: java.lang.IllegalStateException: The specified child already has a parent.

I had quite a problem with fragments and the FragmentManager recently. The problem was the following stacktrace, which came when I tried to launch the application:

08-29 18:10:19.761: E/AndroidRuntime(17159): java.lang.RuntimeException: Unable to start activity ComponentInfo{packagename.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at$700(

08-29 18:10:19.761: E/AndroidRuntime(17159): at$H.handleMessage(

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.os.Handler.dispatchMessage(

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.os.Looper.loop(

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at java.lang.reflect.Method.invokeNative(Native Method)

08-29 18:10:19.761: E/AndroidRuntime(17159): at java.lang.reflect.Method.invoke(

08-29 18:10:19.761: E/AndroidRuntime(17159): at$

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at dalvik.system.NativeStart.main(Native Method)

08-29 18:10:19.761: E/AndroidRuntime(17159): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addViewInner(

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addView(

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addView(

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addView(

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): at

08-29 18:10:19.761: E/AndroidRuntime(17159): ... 11 more

The problem was the Fragment itself. You actually need to use a different constructor for the inflate method. I forgot to set attachToRoot to “false”, this should fix the problem:

View view = inflater.inflate(R.layout.fragment_graph, container, false);

various android ui things


I just finished a small android project this morning. Yesterday evening I came across the code of someone on GitHub who had built a small duel game about Harry Potter. This was java application and you can play this in the console. So I then forked the repo and created the android application for it. You can find my project here:

The application is completely playable but I won’t publish the application to the play store as the game code isn’t from myself. But feel free to check the code out and try it yourself.

Now I learned some nice small things while writing the application. For example, you can append text to a TextView with the following command. So you don’t need to get and set the text manually.

textView.append("yay !");

Another thing is, how to make a TextView scrollable. I added the following lines to the xml layout of the TextView:



and in the java code you need to use the following line:


To display a Progressbar from right to left is very easy. Just use the following code:


This then can look like that:


android-square-progressbar v.1.2.0


After the summer holidays I ‘m publishing the next major version of the android-square-progressbar library. This isn’t actually a really big major version to the library itself, but the example application has changed very much. I’m now using the Navigation Drawer ( and a new Holo-Theme.

Navigation Drawer

Screenshot_2013-08-11-11-35-33With the navigation drawer I was able to move all the customisation things to another layer which is still easy to access. In the Navigation Drawer you can now choose the colour, activate the new opacity style, choose another image or visit the github page right from the app.

The Navigation Drawer is really easy to use and I created a small repository on Github where I’m hosting a basic version of an application which already contains a full configured Navigation Drawer. It still needs some fine tuning, so maybe check it out here later this month: BaseNavigationDrawer (GitHub). I will use this in future projects with Navigation Drawer’s.

The only thing I miss is the possibility to set a Style (like to it. I haven’t found a possibility to do this. But I think this is supposed to be so, as you shouldn’t but any form widgets in there like CheckBoxes or Buttons.

This is now the second application where I am using the Navigation Drawer as the main navigation possibility and I can only recommend it. The other one was the “Current and Voltage” application here.


Back to the new things the library can do now. As you see in the next image you can now activate the opacity. This will let the image disappear if the progress is 0, but I will appear more and more when the progress gets higher. When it reaches 100% then the images is shown normally. This can be a nice way to display the progress even more.



You can set the opacity to the squareProgressBar with the following command:


The road ahead

This is now the 4th update of the library and I want to bring a next one to you in september. I want to focus on these things:

  • OpenGL
  • Handling of bigger images
  • Some progressbar features

If you have any ideas of how I can improve the library, just comment or message me.

You can find the application and the source here:

Play Store :

Github :

android-square-progressbar v.1.1.0


Finally the new version of the android-square-progressbar is now available.  This version has some major features like:

  • custom width of the progressbar
  • easy methods to set the colours (holo-colours, hexcoloursand RGB)
  • better algorithm
  • new example app

In the new example app I made some bigger changes. First of all the pictures are now completely different, because I don’t want to run into any copyright problems. Another big change are the new 2 elements where you can set the width of the progressbar and the colour.

You now can simply set the colour of the bar with the following code:




This is really helpful and a better way to set the colour as in the first version. In the app you can choose the colour like that:


 Actually the new major feature is the possibility to set the width of the progressbar. I recommend to set it between 3 and 20 dp.


Here are some examples:


Another big improvement is the new algorithm. It is now working properly and it handles the width quite well.

Play Store :

Github :

“Strom und Spannung” version 1.1.0 release

I’m finally releasing a new version of the “Strom und Spannung”‘s app this evening. Finally I managed to make a complete translation of the app. I had to guess a lot of the tecnical words, but I think it’s alright. If you find something, please tell me :).

Some other new features are:

  • Much better unified UI
  • Calculation of the resistance when the temperature changes
  • Many user enhancements

You can get the newest version here:

Recording to my awkward roadmap, there will be a small update in a week or so for bugfixes. But the new major update won’t hit the play store until mid august. I’ve got some big topics I want to include into the app and make it available to tablets. But let’s see :).

At this point I really want to recommend the lint markers. You can right click on your android project and choose the following sub menu:Screen Shot 2013-06-10 at 21.16.08
This will show you parts of your code that you can improve. This really helps to keep your code clean and avoid some UI-Bugs.

“Strom und Spannung v1.0” release today


This morning I finally released my calculation application about current and voltage. I know there are a lot of other applications that can do this too, but I wanted to publish the application. I think the application is very basic but okay. Another thing is, that I developed the whole application in German.

A lot of things changed since I last published an application, and the tutorial got even longer:

The main reason I developed the app was that I wanted to work with the new Navigation Drawer. Take a look at it in the following screen:

device-2013-05-26-100047This Navigation Drawer replaces my former tab-layout perfectly. And it’s really easy to implement. Take a look at the following sites:

But a least there is one good thing, the code of my app  is opensource, so you can check it out yourself and feel free to download the app in the play store.


I finally finished my first android library this night. The idea behind the android-square-progressbar library is that you can display a ProgressBar which surrounds a picture. This could be helpful if you don’t have  space for a normal ProgressBar or so.

You can find my github project here, this includes the actual library and an example app:

You can download the library here:

And the example app here:

At the moment it has the possibility to set different colors. But in the future I see more features like thickness of the ProgressBar and some design things to. The library supports more or less all different shapes of images, as demonstrated in the example app.

Here are some examples how it could look like.

one two

To add this to a project, simply add the following part to your XML-Layout:

android:layout_centerHorizontal="true" />

You then can access it from the java code like that:

SquareProgressBar subi = (SquareProgressBar) findViewById(;

Android CardsUILib

I recently searched for a Google Now Card library and I found CardsUILib. But I wanted a card with a picture, so I can use it in my quiz app. So I edited the whole library a bit and the result is that:

It’s a great library with a lot of potential. I did a pull request for a picture card. You can find the library here:

The edit was real easy, I created a new XML-File:


android:padding="8dp" >

android:src="@drawable/url1" />

android:text="text text" />


And the Java class looked like that:

public class MyImageCard extends Card {

public MyImageCard(String title, int image){
 super(title, image);

public View getCardContent(Context context) {
 View view = LayoutInflater.from(context).inflate(R.layout.card_picture, null);
 ((TextView) view.findViewById(;
 ((ImageView) view.findViewById(;

return view;

As you see, the changes I made were real simple as you saw. But there were more in the library code. There I just added an Integer for the DrawableRessource.