Android: OnClickListener throws NullPointerException
<p>I have two Activities. In my main Activity I am creating an intent to start the other one:</p>

<pre><code>Intent intent = new Intent(context, Settings.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
</code></pre>

<p>and here is the code for the second Activity that should start:</p>

<pre><code>public class Settings extends Activity {

    Button settingsBack;
    //Some other layout resources
    final Context context = this;   //Creating reference to this Activity Context

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help);

        //References to layout resources
        settingsBack = (Button) findViewById(R.id.settingsBack);
        //...
        //-----

        //Assigning listeners to Buttons
        settingsBack.setOnClickListener(listenerBack);
        //-----
    }

    //Button listeners definitions
    final OnClickListener listenerBack = new OnClickListener() {

        public void onClick(View v) {
            finish();
        }

    };    
    //-----

}
</code></pre>

<p>But when this second Activity should start, I get a NullPointerException at the line, where I assign Listener to the Button. I tried to clean the project in case the R file hasnt generated properly but it didnt solve the problem. The second Activity is declared in manifest file:</p>

<pre><code>&lt;activity android:name=".Settings" android:label="@string/app_name"&gt;&lt;/activity&gt;
</code></pre>

<p>Im sure its just a simple little problem somewhere but I just cant find it :( Thanks for your help!</p>
