我最近在一些java代码中添加了一个按钮进入我的程序,它可以像往常一样解析数据类型,我保存,构建和清理它。当我这样做时,我的所有Android ID和我的大多数XML表单都开始出错。
这是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"
android:background="@drawable/background">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/ACBonus"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Armor Class Bonus"
android:textColor="#FFFF00"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView
android:id="@+id/ACType"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Armor Class Type"
android:textColor="#FFFF00"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView
android:id="@+id/ACCheckPenalty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Armor Check Penalty"
android:textColor="#FFFF00"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView
android:id="@+id/ACSpellFailure"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Armor Class Spell Failure"
android:textColor="#FFFF00"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView
android:id="@+id/ACWeight"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Armor Class Weight"
android:textColor="#FFFF00"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView
android:id="@+id/ACProperties"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Armor Class Properties"
android:textColor="#FFFF00"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<Button
android:id="@+id/bACDescriptionSave"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Save" >
</LinearLayout>
</ScrollView>
</LinearLayout>
这是我当时正在处理的java类。
package com.example.pathfinderapprentice;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class WeapDescrip extends Activity implements OnClickListener {
TextView Weapon, WeapAttackBonus, WeapCrit, WeapType, WeapRange, WeapAmmo,
WeapDamage, Save;
FileOutputStream WeaponStuff;
String FILENAME = "InteralString";
PopUp PopUp = new PopUp();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.weapdescrip);
setIds();
loadData();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent W = new Intent(WeapDescrip.this, PopUp.class);
switch (v.getId()) {
case R.id.Weapon:
/*
* String data = "Test"; File f = new File(FILENAME); try {
* WeaponStuff = new FileOutputStream(f); WeaponStuff.close(); }
* catch (FileNotFoundException e) { // TODO Auto-generated catch
* block e.printStackTrace(); } catch (IOException e) { // TODO
* Auto-generated catch block e.printStackTrace(); }
*
* try { WeaponStuff = openFileOutput(FILENAME,
* Context.MODE_PRIVATE); WeaponStuff.write(data.getBytes());
* WeaponStuff.close(); } catch (FileNotFoundException e) { // TODO
* Auto-generated catch block e.printStackTrace(); } catch
* (IOException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
startActivity(W);
String WeaponName = PopUp.savedObject;
break;
case R.id.WeapAttackBonus:
startActivity(W);
String WeaponAttackBonus = PopUp.savedObject;
break;
case R.id.WeapCrit:
startActivity(W);
String WeaponCritical = PopUp.savedObject;
break;
case R.id.WeapType:
startActivity(W);
String WeaponType = PopUp.savedObject;
break;
case R.id.WeapRange:
startActivity(W);
String WeaponRange = PopUp.savedObject;
break;
case R.id.WeapAmmuniton:
startActivity(W);
String WeaponAmmo = PopUp.savedObject;
break;
case R.id.WeapDamage:
startActivity(W);
String WeaponDamage = PopUp.savedObject;
break;
}
}
public void setIds() {
Weapon = (TextView) findViewById(R.id.Weapon);
WeapAttackBonus = (TextView) findViewById(R.id.WeapAttackBonus);
WeapCrit = (TextView) findViewById(R.id.WeapCrit);
WeapType = (TextView) findViewById(R.id.WeapType);
WeapRange = (TextView) findViewById(R.id.WeapRange);
WeapAmmo = (TextView) findViewById(R.id.WeapAmmuniton);
WeapDamage = (TextView) findViewById(R.id.WeapDamage);
Weapon.setOnClickListener(this);
WeapAttackBonus.setOnClickListener(this);
WeapCrit.setOnClickListener(this);
WeapType.setOnClickListener(this);
WeapRange.setOnClickListener(this);
WeapAmmo.setOnClickListener(this);
WeapDamage.setOnClickListener(this);
try {
WeaponStuff = openFileOutput(FILENAME, Context.MODE_PRIVATE);
WeaponStuff.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void loadData() {
// TODO Auto-generated method stub
/*
* String collected = null; FileInputStream fis = null; try { fis =
* openFileInput(FILENAME); byte[] dataArray = new
* byte[fis.available()]; while(fis.read(dataArray) != -1){ collected =
* new String(dataArray); } } catch (FileNotFoundException e) { // TODO
* Auto-generated catch block e.printStackTrace(); } catch (IOException
* e) { // TODO Auto-generated catch block e.printStackTrace();
* }finally{ try { fis.close(); Weapon.setText(collected); } catch
* (IOException e) { // TODO Auto-generated catch block
* e.printStackTrace(); } }
*/
}
}
答案 0 :(得分:0)
它不是valid XML
你不是关闭按钮标签
将其更改为
<Button
android:id="@+id/bACDescriptionSave"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Save" > </Button> <-----------you forgot here
</LinearLayout>
答案 1 :(得分:0)
您必须关闭Button标记:
<Button
android:id="@+id/bACDescriptionSave"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Save" /> <-- add /