0

When I try to start an IntentService over adb i get tho following error

E/AndroidRuntime( 2418): java.lang.RuntimeException: Unable to instantiate service 
com.myCompany.MyPackage.Service: java.lang.InstantiationException: 
com.myCompany.MyPackage.Service

when I start a normal service ovre adb, everithing works fine.

What are the reason a cannot start an intentservice over adb?

public class NCService extends IntentService {

public NCService(String name) {
    super(name);
    // TODO Auto-generated constructor stub
}

NetworkStateReceiver nsr;

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    Toast.makeText(getBaseContext(), "onStartCommand", 0).show();
    nsr = new NetworkStateReceiver();

    return START_STICKY;
}

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    Toast.makeText(getBaseContext(), "onCreate", 0).show();
    super.onCreate();
}

@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    Toast.makeText(getBaseContext(), "onDestroy", 0).show();
    super.onDestroy();
}

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
protected void onHandleIntent(Intent intent) {
    // TODO Auto-generated method stub

}

}

<uses-sdk android:minSdkVersion="10" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <service android:name=".NCService" />

    <receiver android:name=".NetworkStateReceiver" >
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
    </receiver>
</application>

Regards Simon

Similitran
  • 165
  • 1
  • 1
  • 9

1 Answers1

2

Your service need a default no-arg constructor, otherwise Android does not know what argument pass as name parameter:

public NCService() {
    super("MyNCService");
}
Robert
  • 39,162
  • 17
  • 99
  • 152