gpt4 book ai didi

android - 错误 :This class should provide a default constructor (a public constructor with no arguments) [Instantiatable] in Android

转载 作者:行者123 更新时间:2023-12-03 15:30:14 33 4
gpt4 key购买 nike

我在 Android Studio 中使用 Generated Signed APK 生成文件 apk,但出现此错误:

Error:Error: This class should provide a default constructor (a public constructor with no arguments) (com.actua.actuaconsultores.actuamindfulness.GridImagenAdaptar) [Instantiatable]



我的课是:
public class GridImagenAdaptar extends BaseAdapter {

private final Context mContext;
private final ArrayList<ModelImage> mGridItems;

public GridImagenAdaptar(Context mContext, ArrayList<ModelImage> mGridItems) {
this.mContext = mContext;
this.mGridItems = mGridItems;
}

public int getCount() {
return mGridItems.size();
}

public Object getItem(int position) {
return mGridItems.get(position);
}

public long getItemId(int position) {
return position;
}


public View getView(int position, View convertView, ViewGroup parent)
{
if( convertView == null)
{ // If ReusedView doesn't exist
convertView = inflatedViewWithContextInParentView(R.layout.activity_grid_imagen_adaptar, mContext, parent);

convertView.setTag("HomeMenuCell"); // Reuse Identifier
}

fillViewWithItemAtIndex(convertView, position);

return convertView;
}

private View inflatedViewWithContextInParentView(int id, Context context, ViewGroup parentView)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
View inflatedView = inflater.inflate(id, parentView, false);
return inflatedView;
}

private void fillViewWithItemAtIndex(View reusedView, int index)
{
ModelImage item = mGridItems.get(index);
item.setId(index);

TextView title = (TextView) reusedView.findViewById(R.id.title);
title.setText(item.title);

ImageView picture = (ImageView) reusedView.findViewById(R.id.image);
int resourceID = getIDForResourceName(item.imageName);
picture.setImageResource(resourceID);
}

private int getIDForResourceName(String name)
{
try {
Class res = R.drawable.class;
Field field = res.getField(name);
int drawableId = field.getInt(null);
return drawableId;
}
catch (Exception e) {
Log.e("GridItemsAdapter", "Error: Couldn't get a drawable id.", e);
}
return -1;
}
}

问题是什么?

谢谢

最佳答案

查看 AndroidManifest.xml文件必须有额外的类的行意外添加只需删除或更改该类名就可以了。例如,在我的情况下,它是像这样添加的 ParyllService ,我删除了它以使其工作。

 <!--  was uncessary <service
android:name=".services.finance.payroll.PayrollService"
android:enabled="true"
android:exported="true"></service>-->

关于android - 错误 :This class should provide a default constructor (a public constructor with no arguments) [Instantiatable] in Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37821254/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com