资源$ NotFoundException:资源ID#0x7f040031

时间:2017-11-24 22:04:01

标签: android

谁帮助我在显示适配器中的数据时我不知道错误是什么? 检查数据,但是当你在适配器中列出它们时

11-24 14:55:16.679 15327-15327/pentasystem.consultaafiliados E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: pentasystem.consultaafiliados, PID: 15327
                                                                               android.content.res.Resources$NotFoundException: Resource ID #0x7f040031
                                                                                   at android.content.res.Resources.getValue(Resources.java:1351)
                                                                                   at android.content.res.Resources.loadXmlResourceParser(Resources.java:2774)
                                                                                   at android.content.res.Resources.getLayout(Resources.java:1165)
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
                                                                                   at pentasystem.consultaafiliados.Beneficiarios_Adaptador.getView(Beneficiarios_Adaptador.java:58)
                                                                                   at android.widget.AbsListView.obtainView(AbsListView.java:2346)
                                                                                   at android.widget.ListView.onMeasure(ListView.java:1158)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                                                                                   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1283)
                                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                                   at android.widget.ScrollView.onMeasure(ScrollView.java:340)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                                                                                   at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
                                                                                   at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                                   at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                                                                                   at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
                                                                                   at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                                   at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
                                                                                   at android.view.View.measure(View.java:18788)
                                                                                   at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
                                                                                   at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
                                                                                   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
                                                                                   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
                                                                                   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
                                                                                   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                                   at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                                   at android.view.Choreographer.doFrame(Choreographer.java:606)
                                                                                   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                                   at android.os.Handler.handleCallback(Handler.java:739)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                   at android.os.Looper.loop(Looper.java:148)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$Metho

适配器row = inflater.inflate(layoutResourceId,parent,false)当你到达时出现错误:

 Context context;
int layoutResourceId;
Beneficiarios data[] = null;

public Beneficiarios_Adaptador(Context context, int layoutResourceId, Beneficiarios[] data) {

    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
}



@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    WeatherHolder holder = null;

    if(row == null)
    {

        // LayoutInflater inflater = LayoutInflater.from(context);
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new WeatherHolder();

        holder.txtnombres = (TextView)row.findViewById(R.id.txtnombres);
        holder.txtapellidos = (TextView)row.findViewById(R.id.txtapellidos);
        holder.txtdocumento = (TextView)row.findViewById(R.id.txtdocumento);
        holder.txtedad = (TextView)row.findViewById(R.id.txtedad);
        holder.txtparentesco = (TextView)row.findViewById(R.id.txtparentesco);
        holder.txtfecha = (TextView)row.findViewById(R.id.txtfecha);
       // holder.imgusuario = (ImageView)row.findViewById(R.id.imgusuario);
        row.setTag(holder);
    }
    else
    {
        holder = (WeatherHolder)row.getTag();
    }

    Beneficiarios beneficiarios = data[position];
    holder.txtnombres.setText(""+beneficiarios.nombres);
    holder.txtapellidos.setText(""+beneficiarios.apellidos);
    holder.txtdocumento.setText(""+beneficiarios.documento );
    holder.txtedad.setText(""+beneficiarios.edad );
    holder.txtparentesco.setText(""+beneficiarios.parentesco );
    holder.txtfecha.setText(""+beneficiarios.fechaafiliacion );
    // holder.imgIcon.setImageResource(usuario.icon);

    return row;
}

static class WeatherHolder
{

    TextView txtapellidos;
    TextView txtnombres;
    TextView txtdocumento;
    TextView txtedad;
    TextView txtparentesco;
    TextView txtfecha;
   // ImageView imgusuario;
}

我发送数据的片段,我正在使用片段导航:

 ListViewBeneficiarios.setAdapter(new Beneficiarios_Adaptador(getContext(),R.layout.listitem_beneficiarios, listaBeneficiarios));
ListViewBeneficiarios.setOnItemClickListener(new ItemList());

listitem_beneficiarios

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dp"
    android:layout_marginEnd="2dp"
    android:layout_marginLeft="2dp"
    android:layout_marginRight="2dp"
    android:layout_marginStart="2dp"
    android:layout_marginTop="2dp"
    android:background="@drawable/rounded_corner"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imgusuario"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginTop="5dp"
        android:adjustViewBounds="true"
        android:contentDescription="Descripción del contenido de la imagen"
        android:scaleType="fitXY"
        android:src="@android:drawable/ic_menu_gallery" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/txtnombres"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Nombres"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textSize="18sp" />

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/txtapellidos"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Apellidos"

                    android:textSize="18sp" />

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView20"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Documento" />

                <TextView
                    android:id="@+id/txtdocumento"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Cantidad"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView26"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Edad" />

                <TextView
                    android:id="@+id/txtedad"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Valor Unitario" />

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView27"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Parentesco" />

                <TextView
                    android:id="@+id/txtparentesco"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Descuento" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView29"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Fecha Afil."
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/txtfecha"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="0.000.000000"
                    android:textSize="14sp" />

            </TableRow>

        </TableLayout>

    </LinearLayout>
</LinearLayout>

我已经解决了它是有列表的方向(土地) 非常感谢你

1 个答案:

答案 0 :(得分:-2)

这是一个常见问题,您使用<input type="button" name="Add" value="Add" onclick="addDetails()"/>这种方法不仅会收到setText也可以收到资源ID(String),然后在您的代码中尝试转换您的{ {1}}值为int以避免这种混淆。

int

我假设String holder.txtdocumento.setText(""+beneficiarios.documento ); holder.txtedad.setText(""+beneficiarios.edad ); 是整数。

更新

此外,您必须检查您的视图ID是否在您在此变量中传递的布局documento(listitem_beneficiarios.xml)

edad

更新2

你的布局文件应该在layoutResourceId文件夹中,也许你只有txtnombres, txtapellidos, txtdocumento, txtedad, txtparentesco, txtfecha 文件夹里面的布局:)检查一下。