Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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
无法实例化服务service.FetchAddressIntentService:java.lang.IllegalAccessException:不允许访问构造函数_Java_Android_Android Intent_Android Service - Fatal编程技术网

无法实例化服务service.FetchAddressIntentService:java.lang.IllegalAccessException:不允许访问构造函数

无法实例化服务service.FetchAddressIntentService:java.lang.IllegalAccessException:不允许访问构造函数,java,android,android-intent,android-service,Java,Android,Android Intent,Android Service,我的清单文件有错误 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

我的清单文件有错误

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
FetchAddressIntentService

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);
    }


        ............


        }
显示

<?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>


实际上,异常文本说明了一切——没有参数的公共构造函数。正如我所见,您只有该类型的包本地(不带修饰符)构造函数-您只需将其公开

您没有在默认构造函数前面指定任何访问修饰符,因此其包是私有的(默认)。
因此,默认构造函数仅在包内可见。
公开或保护任何适当的信息