2013-03-25 25 views
0

當我點擊按鈕添加調試錯誤調試錯誤:確認透視開關

並打開確認視角切換對話框 示出DIS線「的EditText添加=(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); 
      } 
     }); 
    } 
} 
+0

錯誤說什麼? – 2013-03-25 18:39:44

+0

@Mr_and_Mrs_D感謝問題解決。另一個問題發生。當點擊查看按鈕(如上圖所示)時,打開一個對話框,顯示「確認轉換開關」。問道:「你現在想打開這個視角嗎?」 – sid123 2013-03-25 18:51:54

+0

你正在eclipse中工作嗎?這個對話框不是一個錯誤 - 它只是向您展示調試器工具(稱爲「調試透視圖」)的eclipse - 您是否設置了斷點?看看這條線的左側 - 是否有一個小的藍色的東西(一個斷點)? – 2013-03-25 18:55:02

回答

0

大概在代碼大錯誤是,你從來沒有定義的ID 「添加」 - 你在有@+id/TextView01 XML「頁面」(你的意思是文件 - 你必須告訴我們文件),但沒有@+id/add