title: iText: having trouble creating a pdf file in android
body: <p>i have a problem with iText in creating a pdf file in android. It keeps crashing and this error keeps appearing in log cat:</p>
  
  <p><code>java.lang.NoClassDefFoundError: com.itextpdf.text.Document</code></p>
  
  <p>this is my java file:</p>
  
  <pre><code>import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  import com.itextpdf.text.Document;
  import com.itextpdf.text.DocumentException;
  import com.itextpdf.text.Paragraph;
  import com.itextpdf.text.pdf.PdfWriter;
  
  public class MainActivity extends Activity {
  
  public static Button button;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      button = (Button) findViewById(R.id.Submit);
  
      button.setOnClickListener(new OnClickListener() 
      {           
          public void onClick(View arg0) 
          {
              // TODO Auto-generated method stub
  
              toPDF();
  
          }
      });
  }
  
  public void toPDF(){
  
      Document document=new Document();
      try {
          PdfWriter.getInstance(document,new FileOutputStream("try.pdf"));
          document.open();
          document.add(new Paragraph("Hello Android!! :)"));
          document.close();
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (DocumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
   }
  </code></pre>
  
  <p>and i already included <code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;</code> in AndroidManifest.xml</p>
  
  <p>and this is my .classpath..</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classpath&gt;
       &lt;classpathentry kind="src" path="src"/&gt;
       &lt;classpathentry kind="src" path="gen"/&gt;
       &lt;classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/&gt;
       &lt;classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itextpdf-5.3.4.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itextpdf-5.3.4-javadoc.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itextpdf-5.3.4-sources.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-pdfa-5.3.4.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-pdfa-5.3.4-javadoc.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-pdfa-5.3.4-sources.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-xtra-5.3.4.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-xtra-5.3.4-javadoc.jar"/&gt;
       &lt;classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-xtra-5.3.4-sources.jar"/&gt;
       &lt;classpathentry kind="output" path="bin/classes"/&gt;
  &lt;/classpath&gt;
  </code></pre>
  
  <p>I also tried to insert SD card because someone says that it might be the problem, but still, it crashed...</p>
  
  <p>hope anyone can help me.. i'm new to android.. :|</p>