说的setContentView找不到源 [英] setContentView says source not found
问题描述
我想有一些文字在它的自定义GLSurfaceView,显示在一场比赛的比分。我已经做了基础某人的一个统一的XML布局张贴在这里,但是当我试图用的setContentView加载它的应用程序崩溃。调试后我发现,它说:源无法找到。我已经重建了R档但这并不能帮助。仅供参考我的课堂延伸GLSurfaceView被称为GLView。任何帮助将是AP preciated。
包org.kizik.WLTBO;
进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.FrameLayout;
进口android.widget.LinearLayout;
进口android.widget.RelativeLayout;
进口android.widget.TextView;
公共类WholettheballoutActivity延伸活动{
GLView图。 @覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.score);
鉴于=(GLView)findViewById(R.id.mySurfaceView); //可以使用的FrameLayout举行表面观
/ *的FrameLayout的FrameLayout =新的FrameLayout(本);
frameLayout.addView(视图); //然后创建一个布局来容纳一切,例如RelativeLayout的
的RelativeLayout的RelativeLayout =新的RelativeLayout(本);
relativeLayout.addView(的FrameLayout);
relativeLayout.addView(评分);
的setContentView(RelativeLayout的); * /
} @覆盖
保护无效的onPause(){
super.onPause();
view.onPause();
} @覆盖
保护无效onResume(){
super.onResume();
view.onResume();
}
}
通过XML文件名score.xml
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT> < TextView的机器人:ID =@ + ID / textView1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/> < TextView的机器人:ID =@ + ID / textView2
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/> < org.kizik.WLTBO.GLView
机器人:ID =@ + ID / mySurfaceView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1/>< / LinearLayout中>
如果您已经创建了一个参数GLView(上下文C)的构造可能发生,你需要创建一个这样GLView另一个构造(上下文C,AttributeSet中的ATTRS ),所以如果u还没有创建的构造函数,那么就不能不是由类找到GLView,怎么不创建它的构造.. !!我想你还没有创建的构造.. !!
公共GLview(上下文的背景下,ATTRS的AttributeSet){ 超(背景下,ATTRS); }
I am trying to have a custom GLSurfaceView with some text over it, to display the score in a game. I have made a uniform xml layout based off of someones post here but when I try to load it with a setContentView the app crashes. after debugging I found that it says "Source can not be found". I have rebuilt the R file but that doesn't help. For reference my class that extends GLSurfaceView is called GLView. Any help would be appreciated.
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();
}
}
With the XML file name 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>
It may happen if you have created a constructor with single parameter GLView(Context c) , you need to create another constructor like this GLView(Context c, AttributeSet attrs), so if u havent created that constructor, then it can not not find the GLView from class, coz its constructor is not created..!! i think you havent created that constructor..!!
public GLview(Context context, AttributeSet attrs){
super(context,attrs); }
这篇关于说的setContentView找不到源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!