mahmoud mahmoud - 1 year ago 125
Android Question

How to use findViewById in onCreate() method in Service class?

When I used

onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
, the problem is that
can't exist in

public class FloatingViewService extends Service{
CircleMenu circleMenu;
public FloatingViewService() {

public IBinder onBind(Intent intent) {
return null;

public void onCreate() {
//Inflate the floating view layout we created
mFloatingView = LayoutInflater
.inflate(R.layout.layout_floating_widget, null);
circleMenu = (CircleMenu) findViewById(;

Answer Source

try to change the last line to: circleMenu = (CircleMenu) mFloatingView.findViewById(;

hope it will help :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download