2011-12-22 55 views
2

我想用一些自定义的GLSurfaceView来覆盖它,在游戏中显示分数。我做了一个统一的xml布局,基于某些人在这里发布,但是当我尝试加载它与setContentView应用程序崩溃。调试后,我发现它说“源无法找到”。我已经重建了R文件,但这没有帮助。为了参考,我的扩展GLSurfaceView的类被称为GLView。任何帮助,将不胜感激。setContentView说源找不到

package org.kizik.WLTBO; 


    import android.app.Activity; 
    import android.os.Bundle; 




    import android.view.View; 
    import android.view.ViewGroup; 
    import android.widget.FrameLayout; 
    import android.widget.LinearLayout; 
    import android.widget.RelativeLayout; 
    import android.widget.TextView; 


    public class WholettheballoutActivity extends Activity { 
     GLView view; 



     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.score); 
      view = (GLView) findViewById(R.id.mySurfaceView); 

     // You can use a FrameLayout to hold the surface view 
      /*FrameLayout frameLayout = new FrameLayout(this); 
      frameLayout.addView(view); 

      // Then create a layout to hold everything, for example a RelativeLayout 
      RelativeLayout relativeLayout= new RelativeLayout(this); 
      relativeLayout.addView(frameLayout); 
      relativeLayout.addView(score); 
      setContentView(relativeLayout);*/ 
     } 

     @Override 
     protected void onPause() { 
      super.onPause(); 
      view.onPause(); 
     } 

     @Override 
     protected void onResume() { 
      super.onResume(); 
      view.onResume(); 
     } 
    } 

随着XML文件名score.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView android:id="@+id/textView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 

    <TextView android:id="@+id/textView2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 

    <org.kizik.WLTBO.GLView 
     android:id="@+id/mySurfaceView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/>   

</LinearLayout> 

回答

3

可能发生,如果你已经创建了一个单参数GLView(Context c)的构造函数,你需要创建另一个像GLView这样的构造函数(Context c,AttributeSet attrs),所以如果你还没有创建该构造函数,那么它不能找到来自类的GLView,因为它的构造函数不会被创建.. !!我想你还没有创建该构造函数..!

public GLview(Context context, AttributeSet attrs){ 

    super(context,attrs); } 
+0

非常感谢!这永远伴随着我尝试随机的东西。那确实解决了它。 – 2011-12-22 22:51:17

0

的问题是在自定义视图的XML声明,它应该是这样的:

<org.kizik.WLTBO.GLView [other attributes]/> 
+0

这也没有工作,我会更新以显示它的样子。 – 2011-12-22 12:29:02