2012-06-28 74 views
0

我試圖實現PDF查看器,應用程序來檢測存儲在SD卡中的PDF,就像您在圖像中看到的那樣。 http://img225.imageshack.us/img225/3852/pdfs.png使用PDFViewer的NoClassDefFoundError

但是,當我點擊任何文件來查看它...錯誤。

這是logcat的:

06-28 07:32:46.963: WARN/dalvikvm(330): Unable to resolve superclass of Lcom/example/trypdf/Second; (496) 
06-28 07:32:46.983: WARN/dalvikvm(330): Link of class 'Lcom/example/trypdf/Second;' failed 
06-28 07:32:46.983: ERROR/dalvikvm(330): Could not find class 'com.example.trypdf.Second', referenced from method com.example.trypdf.PDFViewerActivity.openPdfIntent 
06-28 07:32:47.013: WARN/dalvikvm(330): VFY: unable to resolve const-class 419 (Lcom/example/trypdf/Second;) in Lcom/example/trypdf/PDFViewerActivity; 
06-28 07:32:47.013: DEBUG/dalvikvm(330): VFY: replacing opcode 0x1c at 0x0002 
06-28 07:32:47.013: DEBUG/dalvikvm(330): VFY: dead code 0x0004-000e in Lcom/example/trypdf/PDFViewerActivity;.openPdfIntent (Ljava/lang/String;)V 
06-28 07:32:47.373: INFO/ActivityManager(59): Displayed activity com.example.trypdf/.PDFViewerActivity: 1665 ms (total 1665 ms) 
06-28 07:32:52.593: DEBUG/dalvikvm(131): GC_EXPLICIT freed 1336 objects/74064 bytes in 149ms 
06-28 07:33:28.634: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol 
06-28 07:33:55.655: DEBUG/AndroidRuntime(330): Shutting down VM 
06-28 07:33:55.663: WARN/dalvikvm(330): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330): FATAL EXCEPTION: main 
06-28 07:33:55.684: ERROR/AndroidRuntime(330): java.lang.NoClassDefFoundError: com.example.trypdf.Second 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at com.example.trypdf.PDFViewerActivity.openPdfIntent(PDFViewerActivity.java:46) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at com.example.trypdf.PDFViewerActivity.onListItemClick(PDFViewerActivity.java:41) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.app.ListActivity$2.onItemClick(ListActivity.java:321) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.widget.AdapterView.performItemClick(AdapterView.java:284) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.widget.ListView.performItemClick(ListView.java:3382) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.os.Handler.handleCallback(Handler.java:587) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.os.Handler.dispatchMessage(Handler.java:92) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.os.Looper.loop(Looper.java:123) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at java.lang.reflect.Method.invokeNative(Native Method) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at java.lang.reflect.Method.invoke(Method.java:521) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
06-28 07:33:55.684: ERROR/AndroidRuntime(330):  at dalvik.system.NativeStart.main(Native Method) 
06-28 07:33:55.693: WARN/ActivityManager(59): Force finishing activity com.example.trypdf/.PDFViewerActivity 
06-28 07:33:56.213: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{44fe47a0 com.example.trypdf/.PDFViewerActivity} 

我已經試過幾乎所有的東西:

  • 創建一個新項目,並複製類。
  • 使用其他目標(APIS lvl10),(2.2,_lvl8)。
  • Clean and build
  • 重置ADB。
  • 使用從其他網站下載的PDFViewer庫。

但我總是得到相同的錯誤:

06-28 07:32:46.983: ERROR/dalvikvm(330): Could not find class 'com.example.trypdf.Second', referenced from method com.example.trypdf.PDFViewerActivity.openPdfIntent 
06-28 07:33:55.684: ERROR/AndroidRuntime(330): java.lang.NoClassDefFoundError: com.example.trypdf.Second 

在這裏你還可以看到我的兩個班,還有明顯。

PDFViewerActivity.java

package com.example.trypdf; 

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

import com.example.trypdf.Second; 
import net.sf.andpdf.pdfviewer.PdfViewerActivity; 
import android.app.ListActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Environment; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class PDFViewerActivity 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(PDFViewerActivity.this, Second.class); 
      intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path); 
      startActivity(intent); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

Second.java

 package com.example.trypdf; 

import net.sf.andpdf.pdfviewer.PdfViewerActivity; 
import net.sf.andpdf.pdfviewer.R; 
import net.sf.andpdf.pdfviewer.R.drawable; 
import net.sf.andpdf.pdfviewer.R.id; 
import net.sf.andpdf.pdfviewer.R.layout; 
import android.os.Bundle; 

public class Second 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; 
    } 
} 

清單

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.trypdf" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="15" /> 
<application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name="com.example.trypdf.PDFViewerActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
     android:name="com.example.trypdf.Second" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
    </application> 
</manifest> 

Thankss!

回答

2

要解決此問題,您需要:

  1. 在項目中創建一個名爲「libs」的文件夾。 2將需要項目的庫導入到此新文件夾。 2.1。要導入它們:右鍵單擊libs文件夾 - >導入 - >文件系統 - >選擇.jar並接受。
  2. 清潔,並建立和啓動

來源:Akki

0

從PdfViewerActivity活動中刪除import net.sf.andpdf.pdfviewer.PdfViewerActivity;

你的包名com.example.trypdfnet.sf.andpdf.pdfviewer

改變你的代碼作爲PdfViewerActivity活動作爲

Yourr PDFViewerActivity as: 

package com.example.trypdf; 
package net.sf.andpdf.pdfviewer; 

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


import android.app.ListActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Environment; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class PDFViewerActivity extends ListActivity { 

    //your code here/...... 
} 

在第二:

package com.example.trypdf; 
package net.sf.andpdf.pdfviewer; 

import android.os.Bundle; 

public class Second extends PdfViewerActivity { 
//your code here/...... 

} 
+0

您在manifast添加PDF查看器lib和項目 –

+0

清單中<使用圖書館機器人添加爲:名稱=「net.sf.andpdf。pdfviewer「/>

+0

然後嘗試使用包net.sf.andpdf.pdfviewer;而不是導入net.sf.andpdf.pdfviewer.PdfViewerActivity; –