Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IntentService的Hello World Android IntentService-enqueueWork()函数不接受参数MyIntentService.class_Android - Fatal编程技术网

IntentService的Hello World Android IntentService-enqueueWork()函数不接受参数MyIntentService.class

IntentService的Hello World Android IntentService-enqueueWork()函数不接受参数MyIntentService.class,android,Android,我只想写一个“Hello World IntentService应用程序”。不幸的是,我不能这样做 问题: MyIntentService.enqueueWork()方法不起作用 IntentService的enqueueWork()函数不接受参数MyIntentService.class 我在谷歌和YouTube上搜索了很多,但没有找到任何有用的东西。事先非常感谢 资料来源: 步骤1:创建一个新的Android项目 步骤2:创建新服务 文件->新建->服务->服务(IntentServi

我只想写一个“Hello World IntentService应用程序”。不幸的是,我不能这样做

问题:

MyIntentService.enqueueWork()方法不起作用

IntentService的enqueueWork()函数不接受参数MyIntentService.class

我在谷歌和YouTube上搜索了很多,但没有找到任何有用的东西。事先非常感谢

资料来源:

步骤1:创建一个新的Android项目

步骤2:创建新服务 文件->新建->服务->服务(IntentService)(只需保留名称:MyIntentService)

//在运行之前给出此错误 排队工作出错-> 无法解析方法'enqueueWork(android.content.Context,java.lang.Class,int,android.content.Intent)'

//步骤5: 现在,我运行应用程序,并给出以下错误:

编译失败;有关详细信息,请参阅编译器错误输出

错误:找不到符号方法排队工作(上下文、类、int、Intent)

IntentService的enqueueWork()函数不接受参数MyIntentService.class


非常感谢

而不是:

MyIntentService.enqueueWork()
应该是:

JobIntentService.enqueueWork(getApplicationContext(), MyIntentService.class, JOB_ID, mServiceIntent);

IntentService
JobIntentService
是不同的东西。非常感谢拉夫桑·艾哈迈德!这解决了我的问题。但我还有一个问题:这是有效的:MyIntentService.startActionFoo(getApplicationContext(),“aaa”,“bbb”);但这不起作用,崩溃:Intent mServiceIntent=newintent();int JOB_ID=1000;JobIntentService.enqueueWork(getApplicationContext(),MyIntentService.class,作业ID,MSServiceIntent);谢谢!如果它崩溃了,那么在问题中添加崩溃日志。可能在其他代码行中发生崩溃。异常在这里->JobIntentService.class->公共静态void enqueueWork(@-NonNull上下文上下文、@NonNull ComponentName组件、int-jobId、@-NonNull意图工作){if(work==null){throw new IllegalArgumentException(“工作不能为null”);}else{}}Intent/work不是null,但它表示null。我不明白。谢谢。这意味着谷歌网页中有一个错误:RSSPullService.enqueueWork(getContext(),RSSPullService.class,RSS_JOB_ID,mServiceIntent);我错了吗?请提供来自android studio的完整logcat stacktrace。没有logcat,很难调试问题。此外,您还可以创建一个新的问题,让每个人都可以看一看@哈伦阿尔泰
JobIntentService.enqueueWork(getApplicationContext(), MyIntentService.class, JOB_ID, mServiceIntent);