Android app and java activities, issues with onCreate() method and XML

I am trying use the onClick() function in an activity for an android app. So far I have:

public class Activity2 extends Activity implements OnClickListener {

    private ImageButton closeButton;

    public void onCreate(Bundle savedInstanceState){

        Button myButton = (Button) findViewById(;

        this.closeButton = (ImageButton)this.findViewById(;
        this.closeButton.setOnClickListener(new OnClickListener(){
            public void onClick(View v){

    public void onClick(View v) {
        // TODO Auto-generated method stub
        TextView lowerText = (TextView) findViewById(;
        EditText boxText = (EditText) findViewById(;


This is just a stripped down version of my project. When I enter my app as usual in the emualtor, everything works fine. When I click the button to open up this particular activity, everything crashes. I assume the issue lies within the onClick() method. This code was sent to me by my project partner without the XML files so I think thats where the problem lies.

here is my basic XML file that I thought should work:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:layout_width="match_parent" android:layout_height="match_parent"

    <Button android:id="@+id/wowButton" android:layout_width="fill_parent"
        android:layout_height="200dp" android:text="WoW" android:typeface="sans"
        android:background="@drawable/btn_default_normal_red" />




While very basic, I though it should work. Thanks for your help.


you instantiate an ImageButton through this.closeButton = (ImageButton)this.findViewById(; But you don't declare it in the xml file. That's why it's null and throws a NullPointer Exception.

Need Your Help

How to make footable work with handlebar

javascript handlebars.js footable

The code I am working with is using handlebar.js to create tables. Now I want to make it responsive using footable. However, footable does not work... probably it does not recognize the table headers

System Error 183 from print call (ERROR_ALREADY_EXISTS)

c++ windows printing system-error

I am trying to get a test page printed from the Windows Driver Kit (WDK) 8.1 Samples (the bitmap sample). Since I did not get any print output, I placed a "GetLastError" call after each call to

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.