无法实例化活动ComponentInfo异常 [英] Unable to instantiate activity ComponentInfo Exception

查看:208
本文介绍了无法实例化活动ComponentInfo异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用可以通过两种方式启动:

My app can be started in two ways:

  • 通过启动器通常"
  • 作为一种意图,当用户从其通讯录中选择一个联系人时

第一种方法可以正常工作.将打开主要活动,并且用户可以使用该应用程序.但是,第二种方法会产生以下错误/崩溃:

The first method works just fine. The main activity opens up, and the user can use the app. The second method however produces the following error/crash:

无法实例化活动 ComponentInfo {de.mystuff.myapp/de.mystuff.myapp.MainActivity}: java.lang.ClassNotFoundException:找不到类 路径上的"de.mystuff.myapp.MainActivity":DexPathList [[zip文件 "/data/app/de.mystuff.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/de.mystuff.myapp-1/lib/arm, /data/app/de.mystuff.myapp-1/base.apk!/lib/armeabi-v7a, /vendor/lib,/system/lib]]

Unable to instantiate activity ComponentInfo{de.mystuff.myapp/de.mystuff.myapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "de.mystuff.myapp.MainActivity" on path: DexPathList[[zip file "/data/app/de.mystuff.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/de.mystuff.myapp-1/lib/arm, /data/app/de.mystuff.myapp-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]

我在清单中声明了以下主要活动:

In my manifest I have declared the main activity as follows:

<activity android:name=".MainActivity" android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.CALL" />
                <category android:name="android.intent.category.DEFAULT" />
                <action android:name="android.intent.action.CALL_PRIVILEGED" />
                <data android:scheme="tel" />
            </intent-filter>
        </activity>

我的活动代码如下:

[Activity (Label = "MyApp", MainLauncher = true, Icon = "@mipmap/ic_launcher")]
  public class MainActivity : Activity, SwipeRefreshLayout.IOnRefreshListener
  {
    AppSettings mAppSettings;

    ContactListViewAdapter mListViewAdapter;

    SwipeRefreshLayout mSwiper;

    protected override void OnCreate (Bundle savedInstanceState)
    {
      base.OnCreate (savedInstanceState);
      SetContentView (Resource.Layout.Main);

      // Do some other init stuff
    }
}

推荐答案

您应避免混淆声明式样式并手动编写AndroidManifest.xml.

You should avoid to mix up declarative style and manually writing the AndroidManifest.xml.

[Activity (Label = "MyApp", MainLauncher = true, Icon = "@mipmap/ic_launcher")]正在实际使用的(生成的)AndroidManifest.xml中生成一段代码,如下所示:

[Activity (Label = "MyApp", MainLauncher = true, Icon = "@mipmap/ic_launcher")] is generating a piece of code in the actual used (generated) AndroidManifest.xml that looks like:

<activity android:icon="@drawable/icon" android:label="AndroidApp1" android:name="md5c178831cd46fc53bebc42cf953f78ced.MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

,您的代码将在其他地方.您可以在输出文件夹.\obj\Debug\android中找到生成的AndroidManifest.xml.

and your code will be somewhere else. You can find the generated AndroidManifest.xml in the output folder .\obj\Debug\android.

解决方案:

您可以通过以下属性添加您的资料:

You can add your stuff via attributes like:

[Activity (Label = "MyApp", MainLauncher = true, Icon = "@mipmap/ic_launcher")]
[IntentFilter(
    new [] { Intent.ActionCall, "android.intent.action.CALL_PRIVILEGED" },
    Categories = new [] {Intent.CategoryDefault},
    DataScheme = "tel")]
public class MainActivity : Activity, SwipeRefreshLayout.IOnRefreshListener
{
    // ...
}

并从清单文件中删除手动编辑.输出将如下所示:

And remove the manual edits from your manifest file. The output will look like:

<activity android:icon="@drawable/icon" android:label="AndroidApp1" android:name="md5c178831cd46fc53bebc42cf953f78ced.MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.CALL" />
    <action android:name="android.intent.action.CALL_PRIVILEGED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="tel" />
  </intent-filter>
</activity>

这篇关于无法实例化活动ComponentInfo异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆