问题描述
当我尝试实施时
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
在我的Android应用程序中,我的应用程序崩溃了,它启动并显示关闭应用程序的对话框,我无法找出问题所在以及问题所在
这是我的gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsversion "30.0.1"
defaultConfig {
// -keep class com.shockwave.**
applicationId "com.example.quran"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
}
}
}
dependencies {
implementation filetree(dir: "libs",include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
这是我的xml文件
<com.github.barteksc.pdfviewer.PDFView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/quran"
/>
这是我的java文件
PDFView pdfView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_whole_quran);
pdfView=findViewById(R.id.quran);
pdfView.fromAsset("complete_quran")
.defaultPage(0)
.enableAnnotationRendering(true)
.scrollHandle(new DefaultScrollHandle(this))
.spacing(2)
.load();
}
这是日志猫
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.quran,PID: 13976
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.quran/com.example.quran.MainActivity}: java.lang.IllegalStateException:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3091)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1843)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6758)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or
descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.quran.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2933)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3091)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1843)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6758)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912)
这里给出了它的清单......请检查是否需要任何类型的许可......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.quran">
<uses-permission android:name="android.permission.INTERNET" />
<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=".wholeQuran"></activity>
<activity android:name=".surah_shown" />
<activity android:name=".surahActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
解决方法
尝试将清单中的 android:theme="@style/AppTheme"
更改为android:theme="@style/Theme.AppCompat.Light"
。