2010-08-28 122 views
1

我使用此代码连接到我的服务,但是当我把这个线语法错误

this.bindService(service, conn, flags); 

我收到错误消息:syntax error on token "}", { expected after this token ... (1)

这里是我的类中的所有代码:

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(savedInstanceState); 
     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); 

    }; 

} 

有人可以帮我bindService函数,我错了吗?

谢谢

回答

1

我怀疑它是这条线的位置:

this.bindService(new Intent("...") , conn, Context.BIND_AUTO_CREATE); 

你把这个说法您ServiceConnection声明中,而不是内部 的方法。假设您使用ActivityServiceConnection,则应将此语句的 移动到onCreateonResume

+0

感谢Erich Douglass 我这一行this.bindService(新的意图(“...”),康恩,Context.BIND_AUTO_CREATE); on on在我的活动上创建 再次感谢 – Jovan 2010-08-28 01:42:17

+0

没问题!如果答案有帮助,请点击左侧的复选框将其标记为已接受的答案。 – 2010-08-28 17:12:41

1

对我来说,它看起来像你试图调用任何方法以外的方法。所以这确实是无效的,在我们的案例中,你必须把它移到一个方法体内。