2017-09-06 78 views
0

當我要生成簽名的應用程序,它告訴我:Android的 - 這個類應該提供一個默認的構造函數

Error:Error: This class should provide a default constructor (a public constructor with no arguments) (com.example.discopc.beautiyuser.Customy) [Instantiatable] 

我的項目:

public class Customy extends ArrayAdapter<String> { 

private final Activity context; 
     View v; 
private final String[]name; 

public Customy(Activity context, String[] name){ 
     //super(null,0); 
     super(context,R.layout.activity_customy,name); 


     this.context=context; 
     this.name=name; 



     } 


public View getView(final int position,View convertView,ViewGroup parent){ 
     try{ 



     LayoutInflater infalter=context.getLayoutInflater(); 
     v=infalter.inflate(R.layout.activity_customy,null,true); 
       TextView txtName=(TextView)v.findViewById(R.id.name); 


     txtName.setText(""+name[position]+""); 

     }catch(Exception e){ 

     } 
     return v; 
     } 
} 

注意:正常工作時調試上我的android設備,但我不能

構建>生成簽名的應用程序

我真的不知道該怎麼做。

感謝,

+0

? – Disco4uf

+3

是的,刪除並嘗試:D。這不是一個活動 – Raghavendra

+1

哦,不錯的職位,作爲一個answear :) – Disco4uf

回答

1

錯誤地檢查您是否在Android Manifest中添加了該適配器名稱。如果是,請刪除並嘗試。

1

一個默認構造函數是它不帶參數,可以隱式使用的類的構造函數。

public Customy(/* notice - no arguments */) { 
    // your code here 
} 

但在你的情況 - 這不一定是問題。問題在於,您的XML配置中某處有這個類,其中一些框架試圖使用默認構造函數實例化它,而我們明顯看到您需要將2個參數傳遞給您的構造函數才能運行。

+1

我想到了同樣的解決方案,但我認爲這是由於別的! 他說他無法爲此創建簽名APK。 – Dennis

+0

在哪裏添加這個新的構造函數...? :X – Disco4uf

+0

As @Raghavendra上面寫道 - 嘗試從你的XML中刪除該行:' – Zilvinas

相關問題