iText 在 android 中创建 pdf 文件时遇到问题。它不断崩溃,并且此错误不断出现在 log cat 中:
java.lang.NoClassDefFoundError: com.itextpdf.text.Document
这是我的java文件:
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();
}
}
我已经包含<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
在 AndroidManifest.xml 中
这是我的.classpath ..
<?xml version="1.0" encoding="UTF-8"?>
<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="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itextpdf-5.3.4.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itextpdf-5.3.4-javadoc.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itextpdf-5.3.4-sources.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-pdfa-5.3.4.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-pdfa-5.3.4-javadoc.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-pdfa-5.3.4-sources.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-xtra-5.3.4.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-xtra-5.3.4-javadoc.jar"/>
<classpathentry kind="lib" path="C:/Users/joan/Documents/Eclipse Workspace/itext-5.3.4/itext-xtra-5.3.4-sources.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
我也尝试插入 SD 卡,因为有人说这可能是问题,但它仍然崩溃了......
希望任何人都可以帮助我..我是android的新手.. :|