0

我正在创建一个应用程序来查看 pdf 文件。我在我的应用程序的主页上使用了 pdfviewer.jar,它会显示我存储在内部存储中的 pdf 文件,但是当我单击该项目时,应用程序崩溃了。

在我的 MainActivity.java

package com.example.pdf;

import java.io.File;
import java.io.FilenameFilter;

import net.sf.andpdf.pdfviewer.PdfViewerActivity;

import android.os.Bundle;
import android.os.Environment;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ListActivity {

    String[] pdflist;
    File[] imagelist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        File images = Environment.getExternalStorageDirectory();
        imagelist = images.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return ((name.endsWith(".pdf")));
            }
        });
        pdflist = new String[imagelist.length];
        for (int i = 0; i < imagelist.length; i++) {
            pdflist[i] = imagelist[i].getName();
        }
        this.setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, pdflist));
    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String path = imagelist[(int) id].getAbsolutePath();
        openPdfIntent(path);
    }

    private void openPdfIntent(String path) {
        try {
            final Intent intent = new Intent(MainActivity.this,DefaultActivity.class);
            intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

在我的 DefaultActivity.java

package com.example.pdf;

import android.os.Bundle;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;

public class DefaultActivity extends PdfViewerActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    public int getPreviousPageImageResource() {
        return R.drawable.left_arrow;
    }

    public int getNextPageImageResource() {
        return R.drawable.right_arrow;
    }

    public int getZoomInImageResource() {
        return R.drawable.zoom_in;
    }

    public int getZoomOutImageResource() {
        return R.drawable.zoom_out;
    }

    public int getPdfPasswordLayoutResource() {
        return R.layout.pdf_file_password;
    }

    public int getPdfPageNumberResource() {
        return R.layout.dialog_pagenumber;
    }

    public int getPdfPasswordEditField() {
        return R.id.etPassword;
    }

    public int getPdfPasswordOkButton() {
        return R.id.btOK;
    }

    public int getPdfPasswordExitButton() {
        return R.id.btExit;
    }

    public int getPdfPageNumberEditField() {
        return R.id.pagenum_edit;
    }
}

这是我的日志猫输出

10-31 12:57:30.580: E/AndroidRuntime(1163): FATAL EXCEPTION: main
10-31 12:57:30.580: E/AndroidRuntime(1163): java.lang.NoClassDefFoundError: com.example.pdf.DefaultActivity
10-31 12:57:30.580: E/AndroidRuntime(1163):     at com.example.pdf.MainActivity.openPdfIntent(MainActivity.java:50)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at com.example.pdf.MainActivity.onListItemClick(MainActivity.java:45)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.widget.AdapterView.performItemClick(AdapterView.java:292)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.widget.AbsListView.onTouchEvent(AbsListView.java:3180)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.View.dispatchTouchEvent(View.java:5541)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1912)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.View.dispatchPointerEvent(View.java:5721)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:859)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.os.Looper.loop(Looper.java:137)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at android.app.ActivityThread.main(ActivityThread.java:4446)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at java.lang.reflect.Method.invokeNative(Native Method)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at java.lang.reflect.Method.invoke(Method.java:511)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-31 12:57:30.580: E/AndroidRuntime(1163):     at dalvik.system.NativeStart.main(Native Method)

我检查了我是否在清单文件中声明了所有活动。

4

1 回答 1

0

这些是将您的 jar 文件应用到您的项目的步骤:-

  1. 只需右键单击您的项目并选择属性
  2. 转到java构建路径
  3. 然后选择订单和出口标签
  4. 检查标记(复选框)您的 pdfviewer.jar 并单击 OK...现在清理您的项目并运行...。
于 2012-10-31T05:14:18.573 回答