简体   繁体   English

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

[英]No grammar constraints (DTD or XML schema) detected for the document 6

I am making my exam in programming C on my gymnasium. 我正在体育馆里编写C语言进行考试。 My App chrashes every time i click on either "krypter" or "dekrypter" (they are two buttons). 每次我单击“ krypter”或“ dekrypter”(它们是两个按钮)时,我的应用程序都会崩溃。 I get the above error in some diffent places in my code and cant figure out what the problem is. 我在代码的某些不同位置出现了上述错误,无法弄清楚问题出在哪里。 I have already looked at many other questions like this but none made me see the problem. 我已经看过很多其他这样的问题,但是没有一个让我明白这个问题。 The two activites is mostly identical and the same for the XML's. 这两个活动在XML上几乎是相同的。

The code for one of the activities you can open from my main activity 您可以从我的主要活动中打开的活动之一的代码

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;
}

}

The XML for the activity above 上述活动的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>

The code for the second activity you can open from my main activity 您可以从主活动中打开的第二个活动的代码

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;
}

} }

The XML for the activity above 上述活动的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>

You uncommented the code that fetches the tekst input, so your app will crash when you try to to anything with the tekst variable 您未注释获取tekst输入的代码,因此当您尝试使用tekst变量进行任何操作时,您的应用程序将崩溃

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

That happens here: 发生在这里:

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

so, uncomment tekst = (EditText) findViewById(editText1); 因此,取消注释tekst = (EditText) findViewById(editText1); and you should be fine. 你应该没事的

I got the solution by following steps:
  1. goto Windows-> Preferences-> XML-> XML Files 转到Windows->首选项-> XML-> XML文件
  2. In Validation files section, choose Ignore in No grammar is specified, default is Warning 在“验证文件”部分中,选择“在没有指定语法的情况下忽略”,默认值为“警告”
  3. Apply and Ok. 申请,确定。 After Validating clean all projects and enjoy :) 验证后清理所有项目并享受:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM