Syntax error in Android service
I use this code for connection to my service, but when I put this line
this.bindService(service, conn, flags);
I receive error message: syntax error on token "}", { expected after this token ... (1)
here is all code in my class:
package com.flaxa.fixx;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstance开发者_如何学JAVAState);
setContentView(R.layout.main);
}
public void butonRunOnlyClickHandler(View target) {
Intent activity = new Intent(this, com.flax.trainer.RunOnly.class);
startActivity(activity);
}
public void butonChallengeClickHandler(View target) {
}
public void butonProgramClickHandler(View target) {
}
public void butonCalculatorClickHandler(View target) {
}
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
}
this.bindService(new Intent("") , conn, Context.BIND_AUTO_CREATE);
};
}
Can some one help my with bindService function, where I'm wrong??
Thanks
I suspect it is this line here:
this.bindService(new Intent("...") , conn, Context.BIND_AUTO_CREATE);
You're placing this statement inside your ServiceConnection
declaration, but not inside
a method. Assuming you're using the ServiceConnection
from an Activity
, you should move
this statement to your onCreate
or onResume
.
For me it looks like you are trying to invoke method outside of any method. So it's indeed not valid you'll have to move it into the body of some method in our case one line up.
精彩评论