Hi im trying to figure out how to generate sourcefiles from babel
files and i keep getting the same error.
I have tried a few different codeblocks from the documentation
and the only thing that changes is the "position" number.
I hope i have not missed something in the documentation.


Code:

#+BEGIN_SRC emacs-lisp            
(defun org-xor (a b)
 "Exclusive or."
(if a (not b) b))
#+END_SRC
 

Debug message:

Debugger entered--Lisp error: (error "Before first headline at
position 1 in buffer test.org")
  signal(error ("Before first headline at position 1 in buffer
test.org"))
  error("Before first headline at position %d in buffer %s" 1
#<buffer test.org>)
  byte-code("\300\301`p#\207" [error "Before first headline at
position %d in buffer %s"] 4)
  org-back-to-heading(t)
  org-heading-components()
  byte-code("\306\307 !\210peb\210\310 \311\312#\203\370