2012-07-03 53 views
0

當我嘗試當我開始提供正常的服務OVRE ADB,everithing正常工作重新開始,亞行的IntentService我得到壽以下錯誤在亞行開始intentservice失敗

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

無法通過adb啓動intentservice的原因是什麼?

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> 

問候 西蒙

+0

發佈服務和顯示xml代碼 –

回答

2

您的服務需要一個默認的無參數的構造函數,否則Android不知道什麼參數傳遞的名稱參數:

public NCService() { 
    super("MyNCService"); 
}