findViewById returns null ???

Put your problem here if it does not fit any of the other categories.

findViewById returns null ???

Postby mawa » Fri Feb 29, 2008 10:34 am

I debugged into the Notepad3 (tutorial exercise) and noticed, that #findViewById returns null within the onCreate method. Nevertheless the Notepad3 sample runs fine. Any explanations ?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public void onCreate(Bundle icicle) {
  3.  
  4.        
  5.  
  6.         View myView;
  7.  
  8.        
  9.  
  10.        
  11.  
  12.         super.onCreate(icicle);
  13.  
  14.        
  15.  
  16.         myView = findViewById(R.layout.notes_list); //breakpoint: myView is null
  17.  
  18.         myView = findViewById(R.layout.notes_row); //breakpoint: myView is null
  19.  
  20.        
  21.  
  22.         setContentView(R.layout.notes_list);
  23.  
  24.  
  25.  
  26.         myView = findViewById(R.layout.notes_list); //breakpoint: myView is null
  27.  
  28.         myView = findViewById(R.layout.notes_row); //breakpoint: myView is null
  29.  
  30.  
  31.  
  32.         dbHelper = new DBHelper(this);
  33.  
  34.         fillData();
  35.  
  36.     }
  37.  
  38.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
mawa
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 27, 2008 9:59 am
Location: Germany

Top

Postby plusminus » Fri Feb 29, 2008 5:00 pm

Hello mawa,

those examples are probably not yet updated to sdk-version m5.

Go to the notes_list.xml and replace

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. ...id="...
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


with

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. ...android:id="...
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


That should work.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 23 guests