0
*11-06 11:08:16.390: E/AndroidRuntime(3482): java.lang.RuntimeException: Unable to instantiate service com.android.Description$MyService: java.lang.InstantiationException: com.android.Description$MyService

私のコード

 Class Description extends Activity{
   logic
startService(new Intent(getBaseContext(), MyService.class));
logic

    public class MyService extends Service {
            @Override
            public IBinder onBind(Intent arg0) {
                return null;
            }
            public MyService(){
                super();
            }
            @Override
            public int onStartCommand(Intent intent, int flags, int startId) {
                // Let it continue running until it is stopped.
                System.out.println("service started");
                Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();

            }
            @Override
            public void onDestroy() {
                System.out.println("service stopped");
                super.onDestroy();
                Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
            }
        }
        public class HelloService extends Service {
            /** indicates how to behave if the service is killed */
            int mStartMode;
            /** interface for clients that bind */
            IBinder mBinder;     
            /** indicates whether onRebind should be used */
            boolean mAllowRebind;
            /** Called when the service is being created. */
            @Override
            public void onCreate() {
            }
            /** The service is starting, due to a call to startService() */
            @Override
            public int onStartCommand(Intent intent, int flags, int startId) {
                return mStartMode;
            }
            /** A client is binding to the service with bindService() */
            @Override
            public IBinder onBind(Intent intent) {
                return mBinder;
            }
            /** Called when all clients have unbound with unbindService() */
            @Override
            public boolean onUnbind(Intent intent) {
                return mAllowRebind;
            }
            /** Called when a client is binding to the service with bindService()*/
            @Override
            public void onRebind(Intent intent) {
            }
            /** Called when The service is no longer used and is being destroyed */
            @Override
            public void onDestroy() {
            }
        }
    }

マニフェスト <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <service android:name="com.android.Description$MyService" android:enabled="true" />

4

3 に答える 3