2012-04-23 115 views
1

我一直在收到以下錯誤。 1:命名空間'System'中不存在類型或命名空間名稱'CountDownTime'(缺少程序集引用) 2:類型或命名空間naem'Runtime'在名稱空間Andriod.OS中不存在你錯過了一個程序集參考)MonoDevelop上的命名空間錯誤

我想代碼生成10個減法問題,提出答案,然後給出測試花費的時間。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.CountDownTimer; 

using Android.App; 
using Android.Content; 
using Android.OS.Runtime; 
using Android.Runtime; 
using Android.Util; 
using Android.Views; 
using Android.Widget; 
using Android; 

namespace Jagtutor 
{ 
    public class Subtraction : View 
    { 
     public Subtraction (Context context, IAttributeSet attrs) : 
      base (context, attrs) 
     { 
      Initialize(); 
     } 

     public Subtraction (Context context, IAttributeSet attrs, int defStyle) : 
      base (context, attrs, defStyle) 
     { 
      Initialize(); 
     } 

     private void Initialize() 
     { 
      int correctCount; 
      int count = 0; 
      long startTime = CountDownTimer(0); 

      while (count < 10) 
      { 
       // Generate two random single-digit numbers 
       srand(CountDownTimer(0)); 
       int number1 = Random() % 10; 
       int number2 = Random() % 10; 

       // if number1 < number, swap number1 with number2 
       if (number1 < number2) 
       { 
        int temp = number1; 
        number1 = number2; 
        number2 = temp; 

        // PROMPT THE STUDENT TO ANSWER " WHAT IS NUMBERE1 - NUMBER2?" 
        Console.WriteLine("WHAT IS ")(number1);" - "(number2)("?"); 

        // Grade the answer and display the result 
        if (number1 - number2 == answer){ 
         Console.Write("You are correct!"); 
         correctCount++; 
        } 
        else 
         Console.WriteLine("Your answer is wrong"); 
        Console.WriteLine(number1);"-"(number2); " should be" (number1 - number2); 

        // increase the count 
        count++; 
       } 
       long endTime = CountDownTimer(0); 
       long testTime = endTime - startTime; 

       Console.Write(" Correct count is ")(correctCount);" Test time is" (testTime)("seconds"); 
       return 0; 
      } 

     } 
    } 

} 
+0

請學習如何在Stack Overflow處爲您的下一個問題設置代碼格式。這裏的代碼格式化程序不喜歡標籤,所以最好只使用空格。將代碼粘貼到編輯框中後,選擇整個代碼並按下「Ctrl + K」或單擊編輯框上方的「{}」圖標。 – 2012-04-23 21:49:23

回答

0

隨着其他的,添加:

using Android.OS;

1

的C#using directive命名空間,不類型使用。沒有System.CountDownTimer名稱空間,因此錯誤。

對於這個問題,也沒有System.CountDownTimer類型;它是Android.OS.CountDownTimer,所以你需要:

using Android.OS; 

同樣,沒有Android.OS.Runtime命名空間,因此using Android.OS.Runtime;也將產生一個編譯時錯誤;去掉它。