Sunday, January 1, 2012

[android-developers] Null Pointer Exception

Hi, Happy new year to all......

I am writing a code for simple navigation between different pages in
android application. I created a Button and then on Click event i am
setting my ContentView. i have written same code for 2 buttons working
fine. but when i am writing click event for 3rd button and it
navigates to a page named "encrpyt_file.xml". its not working. its
giving Null pointer exception. please check the code.

btnEncFile = (Button)findViewById(R.id.btnEncFile);

// at this line btnEncFile value is coming Null, i checked it using
breakpoints so it is giving NullPointerException

btnEncFile.setOnClickListener(new View.OnClickListener()
{

public void onClick(View v)
{
setContentView(R.layout.encrypt_file);
}
});

why this exception is coming, i have written the this code many times
in my applications but this time i can't understand why its giving
null pointer.

please suggest me something if i am missing out something?

2- "encrypt_file.xml"

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btnEncFile"
android:layout_width="match_parent"
android:layout_height="50dp"
android:drawableLeft="@drawable/icon"
android:text="Encrypt File"/>

</AbsoluteLayout>

Thanks
Chandra Mohan

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment