首页 > 解决方案 > What's wrong with my PDF reader activity?

问题描述

I have a PDF reading activity that won't open for whatever reason. I suspect that the issue stems from an API that I had imported earlier. When I previewed the XML file in the PDF-reading activity, I noticed that there was a question mark next to the PDF-API, indicating that it hasn't been recognized by android studio I'd be extremely appreciative if anyone could help me figure this out. Here's the code:

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);
    }
} 

Here's a screenshot of the error: enter image description here

Error Part 2:

Logcat

Manifest code:

<?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>

标签: javascriptjavaandroidandroid-studioandroid-layout

解决方案


Edit

Declare your activity inside AndroidManifest.xml like this

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

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

Shouldn't this

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

Be that?

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


推荐阅读