简体   繁体   English

无法找到显式活动类 {}; 您是否在 AndroidManifest.xml 中声明了此活动

[英]Unable to find explicit activity class {}; have you declared this activity in your AndroidManifest.xml

I'm trying unzip some files in background, so I use IntentService like in google's tutorial.我正在尝试在后台解压缩一些文件,所以我像在谷歌的教程中一样使用 IntentService。 My service class declared in AndroidManifest like this:我在 AndroidManifest 中声明的服务类是这样的:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.osmdroid">

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="21" />


<application
    android:configChanges="orientation|screenSize|keyboardHidden"
    android:hardwareAccelerated="true"
    android:icon="@drawable/ecn_icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >


    <activity
        android:name=".MapActivity"
        android:icon="@drawable/ecn_icon"
        android:label="test" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity
        android:name=".SettingsActivity"
        android:label="@string/title_activity_settings">
    </activity>
    <service
        android:name=".UnZipService"
        android:exported="false"/>
</application>

In activity, I have在活动中,我有

IntentFilter intentFilter = new IntentFilter(DownloadManager
            .ACTION_DOWNLOAD_COMPLETE);

    receiverDownloadComplete = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            long reference = intent.getLongExtra(DownloadManager
                    .EXTRA_DOWNLOAD_ID, -1);
            if (myDownloadReference == reference) {

                     ...
                switch (status) {
                    case DownloadManager.STATUS_SUCCESSFUL:

                        Intent mServiceIntent = new Intent(context, UnZipService.class);
                        mServiceIntent.setData(Uri.parse(savedFilePath));
                        startActivity(mServiceIntent);

                        break;
                    ...
                }
                cursor.close();
            }
        }
    };
    registerReceiver(receiverDownloadComplete, intentFilter);

And service here:和这里的服务:

public class UnZipService extends IntentService {
public UnZipService() {
    super("UnZipService");
}

@Override
protected void onHandleIntent(Intent workIntent) {
    String dataString = workIntent.getDataString();
    Log.v("IntentURI", dataString);
    Toast.makeText(this, "Installing....", Toast.LENGTH_SHORT).show();
}

It should show toast just for test, but I always get an error:它应该显示 toast 只是为了测试,但我总是收到一个错误:

    01-29 19:08:25.740  15521-15521/org.osmdroid E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=org.osmdroid (has extras) } in org.osmdroid.SettingsActivity$1@21292650
            at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:768)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:150)
            at android.app.ActivityThread.main(ActivityThread.java:5147)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.osmdroid/org.osmdroid.UnZipService}; have you declared this activity in your AndroidManifest.xml?
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
            at android.app.Activity.startActivityForResult(Activity.java:3404)
            at android.app.Activity.startActivityForResult(Activity.java:3365)
            at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
            at android.app.Activity.startActivity(Activity.java:3600)
            at android.app.Activity.startActivity(Activity.java:3568)
            at org.osmdroid.SettingsActivity$1.onReceive(SettingsActivity.java:148)
            at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:758)
at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:150)
            at android.app.ActivityThread.main(ActivityThread.java:5147)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)    

Both (class and activity) in same folder (org.osmdroid).两者(类和活动)都在同一个文件夹(org.osmdroid)中。 Seems like paths is ok, but the problem appears and I have no more ideas...看起来路径没问题,但问题出现了,我没有更多的想法......

You are starting a service as an activity您正在将服务作为一项活动开始

Change改变

Intent mServiceIntent = new Intent(context, UnZipService.class);
mServiceIntent.setData(Uri.parse(savedFilePath));
startActivity(mServiceIntent);

to

Intent mServiceIntent = new Intent(context, UnZipService.class);
mServiceIntent.setData(Uri.parse(savedFilePath));
startService(mServiceIntent); // Only this line is changed

请在您的 AndroidManifest.xml 中声明此活动

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法找到明确的活动类,是否已在AndroidManifest.xml中声明了该活动? - Unable to find explicit activity class have you declared this activity in your AndroidManifest.xml? 屏幕锁定导致无法找到明确的活动类,您是否已在AndroidManifest.xml中声明了该活动? - Screen Locked causing Unable to find explicit activity class have you declared this activity in your AndroidManifest.xml? 无法找到显式活动 class {}; 你有没有在你的 AndroidManifest.xml 地图中声明这个活动 API 不工作g;(Java ZE846DZDBC9AB870 - Unable to find explicit activity class {}; have you declared this activity in your AndroidManifest.xml Maps API not workingg ;( Java Android Studio? android.content.ActivityNotFoundException:无法找到显式活动 class {您是否在 AndroidManifest.xml 中声明了此活动? - android.content.ActivityNotFoundException: Unable to find explicit activity class { have you declared this activity in your AndroidManifest.xml? android.content.ActivityNotFoundException:无法找到显式活动类; 您是否在 AndroidManifest.xml 中声明了此活动? - android.content.ActivityNotFoundException: Unable to find explicit activity class; have you declared this activity in your AndroidManifest.xml? 切换到另一个活动时出错,无法找到明确的活动类,您是否在 AndroidManifest 中声明了此活动 - Error when switching to another Activity unable to find explicit activity class have you declared this activity in your AndroidManifest Android Studio:无法找到显式活动 class 但活动已在 AndroidManifest.xml 中声明 - Android Studio: Unable to find explicit activity class but activity already declared in AndroidManifest.xml 错误您是否在 AndroidManifest.xml 中声明了此活动? - Error have you declared this activity in your AndroidManifest.xml? 您是否在AndroidManifest.xml中声明了此活动? 登录活动 - Have you declared this activity in your AndroidManifest.xml ? LoginActivity 无法找到明确的活动类。 在 AndroidManifest.xml 中 - Unable to find explicit activity class. in AndroidManifest.xml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM