没有为文档6检测到语法约束(DTD或XML模式)

时间:2013-04-08 12:38:12

标签: android xml constraints

我正在我的体育馆进行C编程考试。每次点击“krypter”或“dekrypter”(他们是两个按钮)时,我的应用程序都会崩溃。 我在我的代码中的一些不同的地方得到上述错误,无法找出问题所在。我已经看过很多其他这样的问题,但没有人让我看到问题所在。 对于XML来说,这两个活动大多相同且相同。

您可以从我的主要活动中打开的其中一项活动的代码

public class Krypteringstype extends Activity {

public Button slider;
public Button krypterKnap;
public EditText tekst;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.krypteringstype);                               // viser krypteringssiden
    slider = (Button) findViewById(R.id.handle);                            // forbinder xml-knappen og knappen "slider", som er defineret tidligere
    slider.getBackground().setAlpha(230);                                   // gør baggrunden, som jeg bruger let transparent
    //tekst = (EditText) findViewById(editText1);
    krypterKnap = (Button) findViewById(R.id.krypter);
    krypterKnap.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            krypterKnap();
        }
    });
}

private void krypterKnap() {
    if (tekst.getText().equals("")){
        Toast.makeText(getApplicationContext(), "Skriv tekst først", Toast.LENGTH_LONG).show();
    }
    else {
        konverter();
    }   
}

private void konverter(){
    String initialString = "yourString";
    char[] chars = initialString.toCharArray();
    for (int i = 0; i < chars.length; ++i)
        chars[i] = (char)((int)chars[i] + 2);
//  String resultString = new String(chars);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.krypter, menu);
    return true;
}

}

上述活动的XML

<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@drawable/blue_binary_code_1600_1200"
tools:context=".Krypter" >

<Button
    android:id="@+id/krypter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="15dp"
    android:layout_marginLeft="30dp"
    android:background="@drawable/background_large"
    android:gravity="center"
    android:minHeight="35dp"
    android:minWidth="100dp"
    android:text="@string/valg"
    android:textSize="20sp" />

<Button
    android:id="@+id/standardKrypter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="15dp"
    android:layout_marginRight="30dp"
    android:background="@drawable/background_large"
    android:gravity="center"
    android:minHeight="35dp"
    android:minWidth="100dp"
    android:text="@string/standard"
    android:textSize="20sp" />

<Button
    android:id="@+id/overskriftKrypter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="15dp"
    android:background="@drawable/background_large"
    android:minHeight="35dp"
    android:minWidth="250dp"
    android:text="@string/overskrift"
    android:textSize="20sp" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/krypter"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/overskriftKrypter"
    android:layout_marginBottom="15dp"
    android:layout_marginTop="15dp" >

    <SlidingDrawer
        android:id="@+id/slidingDrawerKrypter"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_large"
            android:minHeight="35dp"
            android:text="@string/ceasar" />

        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/button_background" >

            <EditText
                android:id="@+id/editText1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="@string/ceasarNr"
                android:inputType="number" >

                <requestFocus />
            </EditText>
        </LinearLayout>
    </SlidingDrawer>

    <SlidingDrawer
        android:id="@+id/slidingDrawer2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_large"
            android:minHeight="35dp"
            android:text="@string/abe" />

        <LinearLayout
            android:id="@+id/content2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/button_background"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editText2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/a"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/b"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/e"
                android:inputType="number" />
        </LinearLayout>
    </SlidingDrawer>

    <SlidingDrawer
        android:id="@+id/slidingDrawer3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_large"
            android:minHeight="35dp"
            android:text="@string/rsa" />

        <LinearLayout
            android:id="@+id/content3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/button_background"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editText5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prim1"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prim2"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/k"
                android:inputType="number" />

        </LinearLayout>
    </SlidingDrawer>
</LinearLayout>

您可以从我的主要活动中打开的第二个活动的代码

public class Dekrypteringstype extends Activity {

public Button slider;
public Button krypterKnap;
public EditText tekst;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dekrypteringstype);                             // viser krypteringssiden
    slider = (Button) findViewById(R.id.handle);                            // forbinder xml-knappen og knappen "slider", som er defineret tidligere
    slider.getBackground().setAlpha(230);                                   // gør baggrunden, som jeg bruger let transparent
    //tekst = (EditText) findViewById(editText1);
    krypterKnap = (Button) findViewById(R.id.dekrypter);
    krypterKnap.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            krypterKnap();
        }
    });
}

private void krypterKnap() {
    if (tekst.getText().equals("")){
        Toast.makeText(getApplicationContext(), "Skriv tekst først", Toast.LENGTH_LONG).show();
    }
    else {
        konverter();
    }   
}

private void konverter(){
    String initialString = "yourString";
    char[] chars = initialString.toCharArray();
    for (int i = 0; i < chars.length; ++i)
        chars[i] = (char)((int)chars[i] + 2);
//  String resultString = new String(chars);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.dekrypter, menu);
    return true;
}

}

上述活动的XML

<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@drawable/blue_binary_code_1600_1200"
tools:context=".Dekrypter" >

<Button
    android:id="@+id/dekrypter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="15dp"
    android:layout_marginLeft="30dp"
    android:background="@drawable/background_large"
    android:gravity="center"
    android:minHeight="35dp"
    android:minWidth="100dp"
    android:text="@string/valg"
    android:textSize="20sp" />

<Button
    android:id="@+id/standardDekrypter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="15dp"
    android:layout_marginRight="30dp"
    android:background="@drawable/background_large"
    android:gravity="center"
    android:minHeight="35dp"
    android:minWidth="100dp"
    android:text="@string/standard"
    android:textSize="20sp" />

<Button
    android:id="@+id/overskriftDekrypter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="15dp"
    android:background="@drawable/background_large"
    android:minHeight="35dp"
    android:minWidth="250dp"
    android:text="@string/overskrift2"
    android:textSize="20sp" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/dekrypter"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/overskriftDekrypter"
    android:layout_marginBottom="15dp"
    android:layout_marginTop="15dp" >

    <SlidingDrawer
        android:id="@+id/slidingDrawerDekrypter"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_large"
            android:minHeight="35dp"
            android:text="@string/ceasar" />

        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/button_background" >

            <EditText
                android:id="@+id/editText1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="@string/ceasarNr"
                android:inputType="number" >

                <requestFocus />
            </EditText>
        </LinearLayout>
    </SlidingDrawer>

    <SlidingDrawer
        android:id="@+id/slidingDrawer2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_large"
            android:minHeight="35dp"
            android:text="@string/abe" />

        <LinearLayout
            android:id="@+id/content2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/button_background"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editText2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/a"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/b"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/e"
                android:inputType="number" />
        </LinearLayout>
    </SlidingDrawer>

    <SlidingDrawer
        android:id="@+id/slidingDrawer3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_large"
            android:minHeight="35dp"
            android:text="@string/rsa" />

        <LinearLayout
            android:id="@+id/content3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/button_background"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editText5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prim1"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prim2"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/k"
                android:inputType="number" />

        </LinearLayout>
    </SlidingDrawer>
</LinearLayout>

2 个答案:

答案 0 :(得分:0)

您取消注释了提取tekst输入的代码,因此当您尝试使用tekst变量

时,您的应用会崩溃
  

// tekst =(EditText)findViewById(editText1);

这发生在这里:

...snip
 private void krypterKnap() {
        if (tekst.getText().equals("")){
...snip

所以,取消注释tekst = (EditText) findViewById(editText1);,你应该没事。

答案 1 :(得分:0)

I got the solution by following steps:
  1. 转到Windows-&gt;首选项&GT; XML-&GT; XML文件
  2. 在“验证文件”部分中,选择“无语法中的忽略”,默认为“警告”
  3. 申请,好的。验证清理所有项目后享受:)
相关问题