mahmoud mahmoud - 9 months ago 36
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 :)