gpt4 book ai didi

java - Android PDF Viewer空对象引用错误

转载 作者:行者123 更新时间:2023-12-02 10:47:25 24 4
gpt4 key购买 nike

我和其他许多人一样使用 barteksc Android PDF 查看器 ( 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}: android.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

我已检查以确保正确引用了 View 。我正在加载的名为“sample.pdf”的 Assets 位于我的 Assets 中。

* 您能看出我收到此错误的原因吗? *

我意识到有很多关于这个库的帖子,但是每个实例似乎都是独一无二的,所以我决定继续询问。

RoomActivity.java

package group6.interactivehandwriting.activities.RoomActivity;

import android.content.res.AssetManager;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.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:android="http://schemas.android.com/apk/res/android"
package="group6.interactivehandwriting">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activities.RoomActivity.RoomActivity"
android:label="@string/title_activity_menu"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>

activity_draw.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.RoomActivity.RoomActivity">

<view
android:id="@+id/room_view"
id="@+id/view"
android:layout_width="wrap_content"
android: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
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/room"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

依赖关系:

compile 'com.github.barteksc:android-pdf-viewer:2.8.2'

compile 'org.apache.commons:commons-collections4:4.1'

最佳答案

您的activity_draw.xml中有一个拼写错误!

它应该是View而不是view在第 9 行。

同时删除以下行 -

id="@+id/view

关于java - Android PDF Viewer空对象引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52449994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com