java Android PDF查看器空对象引用错误
我和其他很多人一样使用barteksc Android PDF Viewer(https://github.com/barteksc/AndroidPdfViewer)。我一直收到一个空对象引用错误。这就是错误所在
E/AndroidRuntime: FATAL EXCEPTION: main
Process: group6.interactivehandwriting, PID: 24037
java.lang.RuntimeException: Unable to start activity ComponentInfo{group6.interactivehandwriting/group6.interactivehandwriting.activities.RoomActivity.RoomActivity}: 安卓.view.InflateException: Binary XML file line #9: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
我已检查以确保正确引用了视图。我正在加载的名为“sample.pdf”的资产位于我的资产中
*你能看出我收到这个错误的原因吗*
我知道有很多关于这个图书馆的帖子,但是每个例子似乎都是独一无二的,所以我决定继续问
房间活动。爪哇
package group6.interactivehandwriting.activities.RoomActivity;
import 安卓.content.res.AssetManager;
import 安卓.os.Bundle;
import 安卓.app.Activity;
import 安卓.util.Log;
import 安卓.view.View;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
import group6.interactivehandwriting.R;
import group6.interactivehandwriting.activities.RoomActivity.views.DocumentView;
import group6.interactivehandwriting.activities.RoomActivity.views.RoomView;
public class RoomActivity extends Activity implements OnPageChangeListener, OnLoadCompleteListener {
RoomView roomView;
DocumentView docView;
PDFView pView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("Android: ", "Setting content view to an instance of RoomView in: " + this.getClass().getName());
setContentView(R.layout.activity_draw);
System.out.println("Attempting to set ImageView..");
pView = (PDFView) findViewById(R.id.pdfView);
pView.fromAsset("sample.pdf").defaultPage(0)
.enableSwipe(true).swipeHorizontal(false).
onPageChange(this).enableAnnotationRendering(true).onLoad(this).scrollHandle(new DefaultScrollHandle(this)).load();
}
@Override
public void onPageChanged(int page, int pageCount) {
setTitle(String.format("%s %s / %s", "Sample", page + 1, pageCount));
}
@Override
public void loadComplete(int nbPages) {
}
}
AndroidManifest。xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="group6.interactivehandwriting">
<uses-permission 安卓:name="安卓.permission.READ_EXTERNAL_STORAGE"/>
<application
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:roundIcon="@mipmap/ic_launcher_round"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity
安卓:name=".activities.RoomActivity.RoomActivity"
安卓:label="@string/title_activity_menu"
安卓:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
活动:画画。xml
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.constraint.ConstraintLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context=".activities.RoomActivity.RoomActivity">
<view
安卓:id="@+id/room_view"
id="@+id/view"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.github.barteksc.pdfviewer.PDFView
安卓:id="@+id/pdfView"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"/>
<TextView
安卓:id="@+id/textView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginStart="8dp"
安卓:layout_marginTop="8dp"
安卓:text="@string/room"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</安卓.support.constraint.ConstraintLayout>
依赖项:
compile 'com.github.barteksc:安卓-pdf-viewer:2.8.2'
compile 'org.apache.commons:commons-collections4:4.1'
共 (0) 个答案