Question: I am trying to prevent an instance from throwing an exception if a method that does not exist for the instance is called. I have tried the following:

```
class myClass(object):
    def __init__(self):
        pass
    def __getattr__(self,name):
        print "Warning - method {0} does not exist for this instance".format(name)

o = myClass()
var = o.someNonExistantFunction()

```

The problem is that I get the following error:

```
TypeError: 'NoneType' object is not callable

```

The two things I want to make sure of doing is:

1. Return `None` as my code can deal with variables being set to `None`
2. Perform a function (printing a warning message)

What is the cleanest way to do this?

Answer: 
This is called "Action Bar" you can get it nativly starting from [Android 3.0](http://developer.android.com/guide/topics/ui/actionbar.html) or grab code to do it on earlier versions of android [here.](https://stackoverflow.com/questions/2900509/android-action-bar-like-twitter-sample)
1. Create a new project and name your main activity "MyActivity"
2. Go to res - drawable and create a new xml file and call it "custom\_title\_background" and put the following code:

```
<item android:top="20dp">
    <shape android:shape="rectangle">
        <gradient android:angle="90" android:endcolor="#9eacbf" android:startcolor="#8296af">
    </gradient></shape>
</item>

```

This drawable will be used to set the background from custom\_title\_bar (from step 3) and to set the windowTitleBackgroundStyle from custom\_title\_style (from step 4)

1. Go to res-layout and create a new xml and name it "custom\_title\_bar". Here you will create a layout with a text view like in the following code:

```
<TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="16sp"
          android:textColor="@android:color/white"
          android:textStyle="bold"
          android:id="@+id/custom_title_text"
          android:layout_centerInParent="true"
          android:shadowColor="@android:color/black"
          android:shadowRadius="3"/>

```
2. Go to res - values and create a new xml file and call it custom\_title\_style. Here you will create a new theme by overriding the existing one. The name of the style "custom\_title\_theme" from below will be used into the manifest file to "activate" the new theme.

 40dp
 @drawable/custom\_title\_background
3. Now go to the AndroidManifest.xml file and put the new theme in the application tag.

?
1

1. And at this last step, you have to go to the MyActivity class and put the following code:

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;

public class MyActivity extends Activity {

```
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //this must be called BEFORE setContentView
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.main);

    //this must bew called AFTER setContentView
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);

    //set the title
    TextView textView = (TextView)findViewById(R.id.custom_title_text);
    textView.setText("Custom Title");
}

```

}