Android Forums

Go Back   Android Forums > Google Android > Android Development

Click Here To Register!
Reply
 
Thread Tools Search this Thread Display Modes
Old 07-31-2008, 10:06 PM   #1
Junior Member
 
Join Date: Jul 2008
Posts: 5
Hi,

I am facing this issue with very simple code. All I have done is declare a button in the xml layout and calling it in the onCreate() method. What I am receiving is a Null Pointer exception. I have wasted two days hopping around..still no idea whats wrong with that...

Hopefully someone can sort this thing out...The code is as below:
PHP Code:
public void onCreate(Bundle icicle) {
        
super.onCreate(icicle);
        
setContentView(R.layout.main);
        
temp = (Button)findViewById(R.id.button);
        
temp.setOnClickListener(new View.OnClickListener(){

            public 
void onClick(View arg0) {
                
// TODO Auto-generated method stub
                
            
}
            
        });
    } 
Hope to hear something great
baran_khan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 07-31-2008, 11:35 PM   #2
Member
 
Rand5's Avatar
 
Join Date: Apr 2008
Posts: 35
Here's a nice little trick to find the line that is causing the NPE

1. Open the Debug perspective in Eclipse
2. Choose the 'Breakpoints' view tab.
3. Select the 'Add Java Exception Breakpoint' and choose
NullPointerException.
4. Launch your activity, either by using 'Debug As...' or attaching
the debugger to a running instance via DDMS.
5. Execute the offending workflow. It will break on the line that
caused the NPE.
Rand5 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 08-01-2008, 06:07 AM   #3
Junior Member
 
Join Date: Jul 2008
Posts: 5
Quote:
Originally Posted by Rand5 View Post
Here's a nice little trick to find the line that is causing the NPE

1. Open the Debug perspective in Eclipse
2. Choose the 'Breakpoints' view tab.
3. Select the 'Add Java Exception Breakpoint' and choose
NullPointerException.
4. Launch your activity, either by using 'Debug As...' or attaching
the debugger to a running instance via DDMS.
5. Execute the offending workflow. It will break on the line that
caused the NPE.
Hi,

Thanks for the reply, well I have already done that and I know where the exception is but the problem is I can't resolve it. The problem is on the line where I am fetching the button from the xml. For some reasons it is returning null instead of the button I am referring to.

I verified the name, the button is present in the xml and is been identified by eclipse as well. That means I can read that in the class as it is listed in the R.java. Now every time I run the application I get this null pointer exception. I tried different systems and I tried multiple applications, I guess its only me who is making the mistake and missing something in the process development. Can anyone provide me some help or else sample code that have only single button on the screen which is doing a very small thing...lets say changing the text of a editbox.

Thanks in advance...
baran_khan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 08-01-2008, 06:47 AM   #4
Junior Member
 
Join Date: Jul 2008
Posts: 5
Got it....The problem was in the syntax.....I found this thing on a forum that the google has changed the convention of declaring an ID for a field in the xml layout from "id=name" to "android:id=name" ...A thing which they should have mentioned on there website.....

Wasted my two full important days in identifying this foolish thing....

anyways..hope this will help someone else by reading this post....
baran_khan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




Unlocked G1 Phones

All times are GMT. The time now is 06:30 AM.



SEO by vBSEO 3.2.0 RC5 ©2008, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.