3

我已将 .jar 文件添加到我现有的项目中,如http://www.vogella.com/articles/Eclipse/article.html#classpath中所述。

当我尝试运行模拟器时,我最终得到“java.lang.NoClassDefFoundError: com.itextpdf.text.Document”</p>

我的 .classpath 文件:

<classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
        <classpathentry kind="lib" path="lib/itext-pdfa-5.3.3-javadoc.jar"/>
        <classpathentry kind="lib" path="lib/itext-pdfa-5.3.3-sources.jar"/>
        <classpathentry kind="lib" path="lib/itext-pdfa-5.3.3.jar"/>
        <classpathentry kind="lib" path="lib/itext-xtra-5.3.3-javadoc.jar"/>
        <classpathentry kind="lib" path="lib/itext-xtra-5.3.3-sources.jar"/>
        <classpathentry kind="lib" path="lib/itext-xtra-5.3.3.jar"/>
        <classpathentry kind="lib" path="lib/itextpdf-5.3.3-javadoc.jar"/>
        <classpathentry kind="lib" path="lib/itextpdf-5.3.3-sources.jar"/>
        <classpathentry kind="lib" path="lib/itextpdf-5.3.3.jar"/>
        <classpathentry kind="output" path="bin/classes"/>
</classpath>

MainActivity.java

package com.example.tmp;

import java.io.FileOutputStream;

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

          String FILE = "/home/ronline/Desktop/FirstPdf.pdf";
        try {
            Document document=new Document();
              PdfWriter.getInstance(document, new FileOutputStream(FILE));
              document.open();
              document.close();
            } catch (Exception e) {
              e.printStackTrace();
            }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
4

2 回答 2

1

由于未知原因,无法通过 Eclipse 接口将 jar 放入 Java 库。手动复制/过去到 libs 文件夹就可以了。感谢 Parth Doshi 的建议。

于 2012-10-07T16:56:07.890 回答
0

你应该从这里下载 jar 然后尝试。

于 2013-01-22T07:07:40.797 回答