联系监听器错误

时间:2013-10-22 12:28:50

标签: android box2d andengine

当我使用这段代码时,我收到错误。错误行是“if”。为什么呢?

     private ContactListener contactListener()
    {
        ContactListener contactListener = new ContactListener()
        {
            @Override
            public void beginContact(Contact contact)
            {
                final Fixture x1 = contact.getFixtureA();
                final Fixture x2 = contact.getFixtureB();
                if(x1.getBody().getUserData().equals("player"))
                {

                }
           }

            @Override
            public void endContact(Contact contact)
            {
            }   
         };
         return contactListener;
    }

错误

enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个 -

if (x1.getBody().getUserData()!=null && x1.getBody().getUserData().equals("player") ||
        x2.getBody().getUserData()!=null && x2.getBody().getUserData().equals("player"))