И инженерное исключение RenderSurfaceView NullPointerException

#android #xml #andengine

#Android #xml #andengine

Вопрос:

Я получаю исключение NullPointerException в моем menu_layout.xml файл. Я расширяю класс LayoutGameActivity, чтобы использовать EditText. Перед публикацией здесь я уже много гуглил, но исправить это не удалось. Я также обновил ADT, как некоторые предлагали, но ничего.

menu_layout.xml журнал ошибок:

 java.lang.NullPointerException
Couldn't resolve resource @id/gameSurfaceView
Exception details are logged in Window > Show View > Error Log

java.lang.NullPointerException
at org.andengine.opengl.view.RenderSurfaceView.onMeasure(RenderSurfaceView.java:66)
at android.view.View.measure(View.java:8173)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
at android.view.View.measure(View.java:8173)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
at android.view.View.measure(View.java:8173)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:384)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:307)
at android.view.View.measure(View.java:8173)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:384)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:307)
at android.view.View.measure(View.java:8173)
  

menu_layout.xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MenuActivity" >

<org.andengine.opengl.view.RenderSurfaceView
android:id="@ id/gameSurfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

<ImageView
    android:id="@ id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@null"
    android:src="@drawable/vision" />

<EditText
    android:id="@ id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="@string/uHint"
    android:inputType="textEmailAddress" >

</EditText>

<EditText
    android:id="@ id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="@string/pHint"
    android:inputType="textPassword" />

</RelativeLayout
  

MenuActivity.java

 public class MenuActivity extends LayoutGameActivity{

Scene scene;
protected final static int CAMERA_WIDTH = 800;
protected final static int CAMERA_HEIGHT = 480;

BoundCamera mCamera;


@Override
protected int getLayoutID() {
return R.layout.menu_layout;
}
@Override
protected int getRenderSurfaceViewID() {
return R.id.gameSurfaceView;
}



@Override
public EngineOptions onCreateEngineOptions() {

    mCamera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);


    EngineOptions options = new EngineOptions(true,
            ScreenOrientation.LANDSCAPE_SENSOR, new  RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT), mCamera);
    return options;

}

@Override
public Engine onCreateEngine(EngineOptions pEngineOptions) {
    // 60 FPS
    return new LimitedFPSEngine(pEngineOptions, 60);
}


@Override
public void onCreateResources(
        OnCreateResourcesCallback pOnCreateResourcesCallback)
        throws IOException {

    pOnCreateResourcesCallback.onCreateResourcesFinished();
}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
        throws IOException {
    // TODO Auto-generated method stub
    Scene sc = new Scene();

    pOnCreateSceneCallback.onCreateSceneFinished(sc);
}

@Override
public void onPopulateScene(Scene pScene,
        OnPopulateSceneCallback pOnPopulateSceneCallback)
        throws IOException {
    // TODO Auto-generated method stub
    pOnPopulateSceneCallback.onPopulateSceneFinished();
}
}
  

Комментарии:

1. Приведенный выше код отлично работает на моем устройстве (тестирует Nexus 4), исключение не выдается

2. Я использую AndEngine GLES 2 AnchorCenter

3. я пытаюсь в AndEngine GLES 2 AnchorCenter, он работает 🙂 Можете ли вы попробовать XMLLayoutExample в примере AndEngine GLES 2 AnchorCenter?

4. да, это действительно работает с RelativeLayout. Просто в графическом представлении xml отображается ошибка.