2014-01-25 41 views
0

我使用的是在Android開發命名爲A類,這個警告彈出,當我創建了一個名爲類:警告這種方法有一個構造函數名稱

private Intent a() // This method has a constructor name 
{ 
    b.setDrawingCacheEnabled(true); 
    Bitmap bitmap = b.getDrawingCache(); 
    Intent intent = new Intent("android.intent.action.SEND"); 
    intent.setType("image/jpg"); 
    ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); 
    bitmap.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, 
      bytearrayoutputstream); 
    File file = new File((new StringBuilder()) 
      .append(Environment.getExternalStorageDirectory()) 
      .append(File.separator).append("temp_file.jpg").toString()); 
    try { 
     file.createNewFile(); 
     FileOutputStream fileoutputstream = new FileOutputStream(file); 
     fileoutputstream.write(bytearrayoutputstream.toByteArray()); 
     fileoutputstream.close(); 
    } catch (IOException ioexception) { 
     ioexception.printStackTrace(); 
    } 
    intent.addFlags(0x80000); 
    intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(file)); 
    a.startActivity(Intent.createChooser(intent, "Share via: ")); 
    return intent; 
} 

我該怎麼辦?

+3

重命名你的方法 – Raghunandan

+0

這永遠不會發生,當你遵循Java命名約定;-) – Henry

回答

2

什麼@Raghunandan說。

創建命名一樣的類名(從而構造函數)的方法顯然並不違法(警告,沒有錯誤?),但可以非常混亂。試着想出一個更具描述性的方法名稱。

+0

像什麼????? –

+1

你的方法到底在做什麼? – nhaarman

+0

撲克臉:| 意味着什麼? –

0

您看到這個警告,因爲Android的皮棉工具(靜態代碼分析工具),檢查你的Android項目源文件中潛在的錯誤和優化改進,檢測到可疑的(但不是錯誤的),這裏命名。

你有3種選擇,在所有情況下都將編譯很好,什麼都不會發生爆炸。 我已經訂購了從最好到最差的選項。

  1. 讓每個人都開心,並使用可笑的名字改名字

  2. 保持和忽略警告

  3. 請加入其中,這是給以上部分的@supresswarnings規則警告消失警告或調整您的IDE中的lint設置。

相關問題