在AVD我得到不幸的是,PruebaNumero3已经停止工作



我已经在寻找其他问题的答案,但我没有找到它或没有看到它,我很感激任何帮助,谢谢。

这些是日志Cat

中显示的错误
E/Trace(1417): error opening trace file: No such file or directory (2)
 E/AndroidRuntime(1417): java.lang.RuntimeException: Unable to start activity ComponentInfo{gabrielrojas.com/gabrielrojas.com.primeraventana}: android.view.InflateException: Binary XML file line #7: Error inflating class textview
 E/AndroidRuntime(1417): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class textview

androidmanifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".PruebaNumero3"
android:label="@string/title_activity_prueba_numero3" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".primeraventana"/>
<activity android:name=".segundaventana" />
</application>
</manifest>

PruebaNumero3.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".PruebaNumero3" />
<Button android:id="@+id/boton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Primera_Ventana"/>
<Button
android:id="@+id/boton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:text="@string/Segunda_Ventana" />
</RelativeLayout>

PruebaNumero3.java

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prueba_numero3);
// Visualizamos Los botones
Button boton1 = (Button) findViewById(R.id.boton1);
Button boton2 = (Button) findViewById(R.id.boton2);
// Fijamos los eventos que haran ir a las otras actividades
boton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(PruebaNumero3.this, primeraventana.class);
startActivity(intent);
}} );
boton2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(PruebaNumero3.this, segundaventana.class);
startActivity(intent); 
}} );} 

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_prueba_numero3, menu);
return true;
} } ; 

primeraventana.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<textview android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Escala_Uno"/>
<Button android:id="@+id/boton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Menú_Principal"/>
</LinearLayout>

primeraventana.java

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);

TextView text = (TextView) findViewById(R.id.textview1);
Button boton3 = (Button) findViewById(R.id.boton3);
text.setText(R.string.Escala_Uno);
boton3.setText(R.string.Menú_Principal);

boton3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();

segundaventana.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<textview android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Escala_Dos"/>
<Button android:id="@+id/boton4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Menú_Principal"/>
</LinearLayout>

segundaventana.java

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);

TextView text = (TextView) findViewById(R.id.textview2);
Button boton4 = (Button) findViewById(R.id.boton4);
text.setText(R.string.Escala_Dos);
boton4.setText(R.string.Menú_Principal);

boton4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish ();

检查您的primeraventana.xml布局文件。您使用不存在的textview打开了TextView标记。修改如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Escala_Uno"/>
<Button android:id="@+id/boton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Menú_Principal"/>
</LinearLayout>

我不知道到底是什么问题,但我有一些事情你可以尝试:

1)在primeraventana.xml你的TextView应该用大写字母拼写。像这样:

<TextView android:id="@+id/textview1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Escala_Uno"/>

2)在segundaventana.java中,字符串名称只能是英文字母和数字。删除:

中的"ú"
boton4.setText(R.string.Menú_Principal);
最后,我像这样声明OnClickListeners():
button.setOnClickListener(new View.OnClickLister() {
    public void onClick(View v) {
        // You code here.
    }
}

我不知道这对没有视图有什么影响。它看起来更好看。:)

最新更新