尝试从Android中的活动启动服务时发生ClassNotFoundException [英] ClassNotFoundException when trying to start a Service from an Activity in Android

查看:70
本文介绍了尝试从Android中的活动启动服务时发生ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从这样的活动中启动服务:

I'm trying to start a service from my activity like this:

startService(new Intent(MyActivity.this,
                MyService.class));

但是有一个问题。什么都没发生。我在后台调试,可以看到BootClassLoader在ClassNotFoundException上跳闸。我不知道怎么回事,因为我将服务类放在清单文件中,如下所示:

There is a problem however. Nothing happens. I debugged behind the scenes and I can see that the BootClassLoader trips up on a ClassNotFoundException. I don't know how can that happen because I got my Service class in my manifest file like this:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:enabled="true">
        <service android:name=".MyService" android:exported="false"></service>
        ...
    </application>

,它与MyActivity位于同一软件包中。我有点疯了。可能是什么问题?我调试了MyService,但是 onCreate() onStartCommand()都没有被调用。

and it is in the same package as MyActivity. I'm a little nuts here. What can be the problem? I debugged into MyService but onCreate() and onStartCommand() does not get called either.

推荐答案

一个想法:如果转到项目的 bin文件夹,则应该有 * .apk文件。将其重命名为zip,解压缩并调查是否有您的服务类别。我怀疑smth在构建步骤时出错,并且您的课程不在apk中。删除bin文件夹中的所有内容,并设法从头开始重建项目。然后再次解压缩/检查。

Just an idea: if you go to "bin" folder of the project there should be your "*.apk" file. Rename it to zip, unzip and investigate if there is your service class. I suspect smth went wrong at build step and your class is not in the apk. Delete everything that is in bin folder and manage to rebuild the project from scratch. Then unzip/check again.

这篇关于尝试从Android中的活动启动服务时发生ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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