簡體   English   中英

我該如何修復'android.content.ActivityNotFoundException'?

[英]How can I fix 'android.content.ActivityNotFoundException'?

問題是我能夠啟動我的應用程序“ tk.buntowaf.docs ”但是當我嘗試使用該應用程序時它會崩潰。

錯誤

我用adb logcat *:E命令調試了應用程序,我得到了這個錯誤輸出:

AndroidRuntime: Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {tk.buntowaf.docs.app/tk.buntowaf.docs.DocsWebViewActivity}; have you declared this activity in your AndroidManifest.xml?

這是這個應用程序的完整logcat:

...
04-21 12:06:05.879   828   843 E SmartStandbyMode: user=UserHandle{0},owner=UserHandle{0}
04-21 12:06:05.945  9211  9211 E AndroidRuntime: FATAL EXCEPTION: main
04-21 12:06:05.945  9211  9211 E AndroidRuntime: Process: tk.buntowaf.docs.app, PID: 9211
04-21 12:06:05.945  9211  9211 E AndroidRuntime: java.lang.IllegalStateException: Could not execute method for android:onClick
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.view.View.performClick(View.java:5265)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.view.View$PerformClick.run(View.java:21534)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:815)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:104)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:207)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:5728)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
04-21 12:06:05.945  9211  9211 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        ... 9 more
04-21 12:06:05.945  9211  9211 E AndroidRuntime: Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {tk.buntowaf.docs.app/tk.buntowaf.docs.DocsWebViewActivity}; have you declared this activity in your AndroidManifest.xml?
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.app.ContextImpl.startActivity(ContextImpl.java:682)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.app.ContextImpl.startActivity(ContextImpl.java:664)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at com.thefinestartist.utils.content.ContextUtil.startActivity(ContextUtil.java:461)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at tk.buntowaf.docs.DocsWebView$Builder.show(DocsWebView.java:924)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at tk.buntowaf.docs.DocsWebView$Builder.show(DocsWebView.java:911)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        at tk.buntowaf.docs.app.MainActivity.onClick(MainActivity.java:46)
04-21 12:06:05.945  9211  9211 E AndroidRuntime:        ... 11 more
04-21 12:06:05.952   205   205 E SurfaceFlinger: smallscreen captureScreenImplLocked isSmall 0, isLeft 0
04-21 12:06:05.952   205   205 E SurfaceFlinger: add by mtk crop(0,36,480,516) reqWidth(288) reqHeight(288)
04-21 12:06:05.985   828   843 E SmartStandbyMode: SSM_ShouldHandle while UserHandle.OWNER
04-21 12:06:05.986   828   843 E SmartStandbyMode: user=UserHandle{0},owner=UserHandle{0}
04-21 12:06:05.993   828   843 E SmartStandbyMode: SSM_ShouldHandle while UserHandle.OWNER
04-21 12:06:05.993   828   843 E SmartStandbyMode: user=UserHandle{0},owner=UserHandle{0}
04-21 12:06:06.138   828   843 E SmartStandbyMode: SSM_ShouldHandle while UserHandle.OWNER
04-21 12:06:06.139   828   843 E SmartStandbyMode: user=UserHandle{0},owner=UserHandle{0}
04-21 12:06:06.141   828   843 E SmartStandbyMode: SSM_ShouldHandle while UserHandle.OWNER
04-21 12:06:06.141   828   843 E SmartStandbyMode: user=UserHandle{0},owner=UserHandle{0}
04-21 12:06:06.292   828   828 E WifiTrafficPoller:  packet count Tx=4934 Rx=5765
04-21 12:06:06.292   828   828 E WifiTrafficPoller: notifying of data activity 1
04-21 12:06:07.294   828   828 E WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 14 num clients 9
04-21 12:06:07.295   828   828 E WifiTrafficPoller:  packet count Tx=4943 Rx=5773
04-21 12:06:07.295   828   828 E WifiTrafficPoller: notifying of data activity 3
04-21 12:06:07.524   828   878 E InputDispatcher: channel 'a901017 Toast (server)' ~ Channel is unrecoverably broken and will be disposed!
04-21 12:06:07.524   828   878 E InputDispatcher: channel '7609fb1 tk.buntowaf.docs.app/tk.buntowaf.docs.app.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
04-21 12:06:07.540   828  1661 E MultiWindowProxy: getServiceInstance failed!
04-21 12:06:08.296   828   828 E WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 14 num clients 9
04-21 12:06:08.297   828   828 E WifiTrafficPoller:  packet count Tx=4943 Rx=5773
04-21 12:06:08.297   828   828 E WifiTrafficPoller: notifying of data activity 0
...

我的環境

我在用:

  • Android Studio 1.0
  • Java版本: java version "1.8.0_73" / Java(TM) SE Runtime Environment (build 1.8.0_73-b02) / Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)
  • Gradle版本: com.android.tools.build:gradle:2.0.0com.android.tools.build:gradle:2.0.0com.android.tools.build:gradle:2.0.0
  • 我啟用了Multidex!

我的./build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    classpath 'com.novoda:bintray-release:0.3.4'
  }
}

allprojects {
  repositories {
    jcenter()
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

ext {
  minSdkVersion = 7
  targetSdkVersion = 23
  compileSdkVersion = 23
  buildToolsVersion = '23.0.3'

  sourceCompatibility = JavaVersion.VERSION_1_8
  targetCompatibility = JavaVersion.VERSION_1_8

  versionCode = 1
  versionName = '1.0.0'

  supportLibVersion = '24.1.1'
  playLibVersion = '8.4.0'
}

我的./app/build.gradle文件:

apply plugin: 'com.android.application'

android {
  compileSdkVersion rootProject.ext.compileSdkVersion
  buildToolsVersion rootProject.ext.buildToolsVersion

  defaultConfig {
    applicationId "tk.buntowaf.docs.app"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode rootProject.ext.versionCode
    versionName rootProject.ext.versionName
    vectorDrawables.useSupportLibrary = true
    multiDexEnabled = true
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
    buildToolsVersion '25.0.0'
}

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:multidex:1.0.1'

  compile project(':library')
  //    compile "tk.buntowaf.docs:${rootProject.ext.versionName}"

  compile "com.android.support:support-annotations:${rootProject.ext.supportLibVersion}"
  compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
  //    compile "com.android.support:support-vector-drawable:${rootProject.ext.supportLibVersion}"
  //    compile "com.android.support:palette-v7:${rootProject.ext.supportLibVersion}"
  compile "com.android.support:design:${rootProject.ext.supportLibVersion}"
  //    compile "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"

  //    compile "com.google.android.gms:play-services-base:${rootProject.ext.playLibVersion}"
  //    compile "com.google.android.gms:play-services-gcm:${rootProject.ext.playLibVersion}"
  //    compile "com.google.android.gms:play-services-plus:${rootProject.ext.playLibVersion}"
  //    compile "com.google.android.gms:play-services-analytics:${rootProject.ext.playLibVersion}"
  //    compile "com.google.android.gms:play-services-location:${rootProject.ext.playLibVersion}"
  //    compile "com.google.android.gms:play-services-maps:${rootProject.ext.playLibVersion}"
}

我的./app/src/main/AndroidManifest.xml文件:

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

  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  <application
      android:name="android.support.multidex.MultiDexApplication"
      android:allowBackup="true"
      android:hardwareAccelerated="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
    <activity
        android:name="tk.buntowaf.docs.app.MainActivity"
        android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

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

    <activity
        android:name="tk.buntowaf.docs.DocsWebViewActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="sensor"
        android:theme="@style/FinestWebViewTheme.Light"/>

    <activity android:name="tk.buntowaf.docs.app.WebViewActivity"/>
  </application>

</manifest>

完整代碼:


編輯:

我的./settings.gradle文件:

include ':library', ':app'

你在清單中的最后一個活動有問題

設置這樣,我認為它解決了你的問題

而不是這些

 <activity
    android:name="tk.buntowaf.docs.DocsWebViewActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="sensor"
    android:theme="@style/FinestWebViewTheme.Light"/>

<activity android:name="tk.buntowaf.docs.app.WebViewActivity"/>

剛剛過去

<activity
    android:name="tk.buntowaf.docs.DocsWebViewActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="sensor"
    android:theme="@style/FinestWebViewTheme.Light">

  <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
  </intent-filter>

</activity>

你輸入了android:name ....兩次
而且我認為有必要對活動進行意圖過濾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM