【问题标题】:What's wrong with my PDF reader activity?我的 PDF 阅读器活动有什么问题?
【发布时间】:2018-11-24 04:41:14
【问题描述】:

我有一个 PDF 阅读活动,无论出于何种原因都无法打开。我怀疑问题出在我之前导入的 API 上。当我在 PDF 阅读活动中预览 XML 文件时,我注意到 PDF-API 旁边有一个问号,表示它尚未被 android studio 识别,如果有人可以帮助我,我将非常感激把这个想出来(解决;计算出;弄明白。代码如下:

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=".PDFReader">

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfViewer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent">

    </com.github.barteksc.pdfviewer.PDFView>

</android.support.constraint.ConstraintLayout> 

Java:

  package com.androidcodefinder.loginscreendemo.Analytics;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import com.androidcodefinder.loginscreendemo.MainActivity;
import com.androidcodefinder.loginscreendemo.R;
import com.androidcodefinder.loginscreendemo.SignUpActivity;
import com.androidcodefinder.loginscreendemo.Utils.BottomNavigationViewHelper;
import com.github.barteksc.pdfviewer.PDFView;
import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx;

public class AnalyticsActivity extends AppCompatActivity {
    private static final String TAG = "AnalyticsActivity";
    private Context mContext= AnalyticsActivity.this;
    private static final int ACTIVITY_NUM = 0;
    private Button pdfViwer;
    private Button pdfViwer2;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.analytics_activity);
        Log.d(TAG,"onCreate: started");

        setupBottomNavigationView();
        pdfViwer=(Button)findViewById(R.id.pdf23);
        pdfViwer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(AnalyticsActivity.this,PDFView.class);
                startActivity(intent);
            }
        });
        pdfViwer2=(Button)findViewById(R.id.pdf22);
        pdfViwer2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(AnalyticsActivity.this,PDFView.class);
                startActivity(intent);
            }
        });

    }

    private void setupBottomNavigationView(){
        Log.d(TAG,"setupBottomNavigationView: setting up BottomNavigationView");
        BottomNavigationViewEx bottomNavigationViewEx = (BottomNavigationViewEx) findViewById(R.id.bottomNavViewBar);
        BottomNavigationViewHelper.setupBottomNavigationView(bottomNavigationViewEx);
        BottomNavigationViewHelper.enableNavigation(mContext, bottomNavigationViewEx);
        Menu menu = bottomNavigationViewEx.getMenu();
        MenuItem menuItem = menu.getItem(ACTIVITY_NUM);
        menuItem.setChecked(true);
    }
} 

这是错误的屏幕截图:

清单代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidcodefinder.loginscreendemo">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <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_background"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SignUpActivity" />
        <activity android:name=".zippage" />
        <activity android:name=".Catalysts.CatalystsActivity" />
        <activity android:name=".Profile.ProfileActivity" />
        <activity android:name=".Analytics.AnalyticsActivity" />
        <activity android:name=".postpg" />
        <activity android:name=".postp1" />
        <activity android:name=".post2" />
        <activity android:name=".postend" />
        <activity android:name=".PDFReader"></activity>
    </application>

</manifest>

【问题讨论】:

  • 请分享您的 logcat 详细信息
  • 我刚刚添加了它:)
  • 请不要发布代码、XML 或 logcat 输出的屏幕截图。请将所有文本作为文本发布。而且,这不是我们需要的。您正在寻找stack trace from the crash
  • 这是来自 logcat 的消息:无法找到显式活动类 {com.androidcodefinder.loginscreendemo/com.github.barteksc.pdfviewer.PDFView};您是否在 AndroidManifest.xml 中声明了此活动?
  • @ABASHERSI do this answer(stackoverflow.com/a/53455588/7360848) 解决了你的问题,如果是,请接受:)

标签: javascript java android android-studio android-layout


【解决方案1】:

编辑

像这样在 AndroidManifest.xml 中声明你的活动

<application
    .
    .
    android:theme="@style/AppTheme">

    <activity android:name=".PDFReader">
    </activity> 
    .
    .
</application>

不应该这样

Intent intent = new Intent(AnalyticsActivity.this,PDFView.class);

是吗?

Intent intent = new Intent(AnalyticsActivity.this.PDFReader.class);

【讨论】:

  • 我试过了,但不幸的是它给了我一大堆错误。
  • 请在logcat中选择debug而不是verbose,并在出现错误时粘贴logcat
  • 我按照你说的做了我收到以下消息:无法找到明确的活动类 {com.androidcodefinder.loginscreendemo/com.github.barteksc.pdfviewer.PDFView};您是否在 AndroidManifest.xml 中声明了此活动?
  • 错误是不言自明的,请参阅我的更新答案
  • 我的活动已经被宣布,所以不幸的是没有帮助:(
【解决方案2】:

您正在寻找视图

pdfViwer=(Button)findViewById(R.id.pdf23);
pdfViwer2=(Button)findViewById(R.id.pdf22);

id 为 pdf23,pdf22,但这两个在您的 xml 文件中不可用。所以它会抛出运行时异常。

【讨论】:

  • 感谢您的回复,但 pdf22 和 pdf23 是位于不同 xml 文件中的按钮,因此这不是问题。
  • 好的,将你的 logcat 添加到问题中
  • 我刚刚添加了它:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-05
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 2019-11-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多