调试错误:确认透视切换

时间:2013-03-25 18:25:29

标签: android xml debugging

当我点击按钮添加调试错误

并打开确认透视切换对话框 在dis line“EditText add =(EditText)d1.findViewById(R.id.add);”中显示错误 我的代码中的错误是什么?

xml页面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Question1" >
    </TextView>
    <EditText
        android:id="@+id/question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" >
    </EditText>
    <EditText
        android:id="@+id/answer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" >
    </EditText>
    <Button
        android:id="@+id/registerques"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="registerques" >
    </Button>
</LinearLayout>

java类 在editext行中显示错误

package quesansw.the1;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

public class Memo extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Dialog d1 = new Dialog(this);
        Window window = d1.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        d1.setTitle("Register Questions");
        d1.setContentView(R.layout.memo);
        d1.show();
        Button view1 = (Button) d1.findViewById(R.id.view);
        Button add = (Button) d1.findViewById(R.id.add);
        add.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                EditText add = (EditText) d1.findViewById(R.id.add);
                EditText view = (EditText) d1.findViewById(R.id.view);
                System.out.println(add.toString());
                System.out.println(view.toString());
            }
        });
        view1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent(getBaseContext(), View.class);
                startActivity(intent);
            }
        });
    }
}

1 个答案:

答案 0 :(得分:0)

代码中可能出现的错误是您从未定义过ID“添加” - 您在xml“页面”中有@+id/TextView01(您的意思是文件 - 您必须告诉我们哪个文件)但没有@+id/add

相关问题