2012-07-28 30 views
1

我正在與Android項目上的朋友進行遠程協作,並且當我將其更改導入到本地回購庫時,出現以下錯誤消息,用於對AlertDialog對象:DialogInterface.OnShowListener()無法解析爲類型

DialogInterface.OnShowListener() cannot be resolved to a type 

下面是完整的代碼:

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.text.InputType; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 
import android.widget.CompoundButton.OnCheckedChangeListener; 
import android.widget.EditText; 
import android.widget.TextView; 
... 
... 
protected AlertDialog mDialogForgotPassword; 
... 
... 
mDialogForgotPassword = new AlertDialog.Builder(LogInActivity.this) 
.setTitle(getString(R.string.forgot_password)) 
.setView(input) 
.setCancelable(false) 
.setPositiveButton("Submit", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 
     // NOTE: LEAVE THIS AS EMPTY 
     // WE OVERRIDEN THIS METHOD USING THE setOnShowListener 
    } 

}) 
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 
     dialog.cancel(); 
    } 
}) 
.create(); // created AlertDialog 

// ERROR APPEARS NEXT, red line under "new DialogInterface.OnShowListener()" 
mDialogForgotPassword.setOnShowListener(new DialogInterface.OnShowListener() { 
    @Override 
    public void onShow(DialogInterface dialog) { 
     final Button positiveButton = mDialogForgotPassword.getButton(AlertDialog.BUTTON_POSITIVE); 
     positiveButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       final String EMAIL = input.getText().toString(); 
       if(ValidationHelper.isEmail(EMAIL)){ 
        resetUserPassword(EMAIL); 
       } 
      } 
     }); 
    } 
}); // end setOnShowListener 
mDialogForgotPassword.show(); 

朋友說,當他輸入mDialogForgotPasswordsetOnShowListener()顯示爲一個建議的方法後,按下Ctrl + Space在Eclipse。然而,對我而言,這並不是,但是進口報表似乎已經完整。幫幫我?

回答

0

我做了什麼,以消除錯誤:

  1. 確信在Eclipse中我的Java編譯器設置爲1.6。右鍵單擊項目 - > Java編譯器 - >選中「啓用項目特定設置」 - >將「編譯器合規性級別」設置爲1.6 - >選中「使用默認編譯器合規性設置」。

  2. 右鍵單擊項目 - > Android - >勾選「Android 4.1」作爲項目構建目標。在撰寫本文時,Jelly Bean是最新版本。

  3. 在我的Android清單中,我將最低SDK升級到8(Froyo,2.2),並將targetSdk設置爲16,Jelly Bean。無論如何,API等級4過低都是最低的,並且根據Android distribution data,其市場份額非常小且不斷縮小。

1

如果您使用的是Eclipse,然後嘗試按

CTRL + SHIFT + O 

(它不是「零」,其字母「O」),而在該文件中所導致的問題。這應該可以解決所有導入問題。

如果這沒有幫助,那麼您應該確保您和您的朋友將項目配置爲使用相同的API級別。 DialogInterface.OnShowListener()可用於API級別8,因此請確保您的項目已配置爲至少使用該API級別。

+0

恐怕這兩個解決方案都不起作用。我右鍵單擊項目 - >屬性 - > Android,我的目標版本實際上是API級別13.但是,在清單中,最小SDK設置爲4,最大值設置爲15。 – 2012-07-28 09:21:17