作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 list 文件有错误。
service.FetchAddressIntentService 没有默认构造函数所以我在服务类中创建了构造函数,如下所示。现在我遇到了异常..
有什么建议吗?
08-12 21:27:36.568 20148-20148/com.sunil.location.mylocation E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.sunil.location.mylocation, PID: 20148
java.lang.RuntimeException: Unable to instantiate service service.FetchAddressIntentService: java.lang.IllegalAccessException: access to constructor not allowed
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2570)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalAccessException: access to constructor not allowed
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2567)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
08-12 21:32:36.611 20148-20148/com.sunil.location.mylocation I/Process﹕ Sending signal. PID: 20148 SIG: 9
获取地址 Intent 服务
public class FetchAddressIntentService extends IntentService {
private static final String TAG = "fetch-address-intent-service";
private static final String TAG = FetchAddressIntentService.class.getSimpleName();
/**
* The receiver where results are forwarded from this service.
*/
protected ResultReceiver mReceiver;
/**
* This constructor is required, and calls the super IntentService(String)
* constructor with the name for a worker thread.
*/
FetchAddressIntentService(){
super(TAG);
}
public FetchAddressIntentService(String name) {
//Give the class name to worker thread
super(TAG);
}
............
}
list
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sunil.location.mylocation" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>
<service android:name="service.FetchAddressIntentService"
android:exported="false"/>
</application>
</manifest>
最佳答案
您没有在默认构造函数前指定任何访问修饰符,因此它的包是私有(private)的(默认)。
因此,您的默认构造函数仅在包内可见。
适本地公开或保护它。
关于java - 无法实例化服务 service.FetchAddressIntentService : java. lang.IllegalAccessException:不允许访问构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31970495/
我的 list 文件有错误。 service.FetchAddressIntentService 没有默认构造函数所以我在服务类中创建了构造函数,如下所示。现在我遇到了异常.. 有什么建议吗? 08-
我是一名优秀的程序员,十分优秀!