cannot start a inner class service


Last Updated:

  1. dougDaG

    dougDaG New Member This Topic's Starter

    Joined:
    Oct 13, 2010
    Messages:
    1
    Likes Received:
    0
    it seems that cannot nest a service class in a activity class...
    to run the following code, i got the errormsg;
    FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to instantiate service inner.service.InnerService$Inner: java.lang.IllegalAccessException: access to class not allowed.....

    Androidmanifest.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="inner.service"
    android:versionCode="1"
    android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".InnerService"
    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=".InnerService.Inner"/>
    </application>
    </manifest>


    InnerService.java:

    public class InnerService extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button btn = (Button) findViewById(R.id.btn);
    btn.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    Intent i = new Intent(InnerService.this, Inner.class);
    startService(i);
    }
    });
    }
    public static final class Inner extends Service {
    @Override
    public IBinder onBind(Intent intent) {
    return null;
    }

    @Override
    public void onCreate() {
    super.onCreate();
    Log.e("-->", "create service");
    }

    @Override
    public void onDestroy() {
    super.onDestroy();
    Log.e("-->", "stop service");
    }
    }
    }

    Any help would be welcome
    d&g
     

    Advertisement

Share This Page

Loading...