错误:(22,31)错误:找不到符号变量car_adapter_layout

时间:2016-10-19 07:23:37

标签: android

我已经创建了一个在unsigned apk版本中运行良好的应用程序,但是当我尝试创建已签名的apk时显示错误错误:(22,31)错误:无法找到符号变量adapter_layout。

这是我的logcat:

Information:Gradle tasks [:app:assembleRelease]
C:\Users\systech\Desktop\imran\RealTimeTrackingandMonitoring\app\src\main\java\com\tracker\systechdigital\realtimetrackingandmonitoring\CarAdapter.java
Error:(22, 31) error: cannot find symbol variable car_adapter_layout
Error:(31, 52) error: cannot find symbol variable car_adapter_layout
Error:(33, 71) error: cannot find symbol variable name_show_car_adapter_tvid
Error:Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 3.257 secs
Information:4 errors
Information:0 warnings
Information:See complete output in console

这是我的xml代码:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/name_show_car_adapter_tvid"
        android:textSize="20sp"
        android:paddingLeft="20dp"
        android:textColor="#f9f9f9"
        android:layout_gravity="center"
        />

</LinearLayout>

并从适配器类调用:

public class CarAdapter extends ArrayAdapter<CarModelClass> {

    ArrayList<CarModelClass> carModelClassArrayList;
    TextView nameShow_CarAdapterTv;
   // private String idAuto;
    CarModelClass carModelClass;
    private Context context;

    public CarAdapter(Context context, ArrayList<CarModelClass> carModelClassArrayList) {
        super(context,R.layout.car_adapter_layout , carModelClassArrayList);
        this.context=context;
        this.carModelClassArrayList=carModelClassArrayList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater layoutInflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView=layoutInflater.inflate(R.layout.car_adapter_layout,parent,false);

        nameShow_CarAdapterTv =(TextView)convertView.findViewById(R.id.name_show_car_adapter_tvid);

        carModelClass=carModelClassArrayList.get(position);

        nameShow_CarAdapterTv.setText(carModelClass.getName());

       // UserInfo.setCarListItemId(carModelClassArrayList.get(position).getIdAuto());


        return convertView;
    }

}

如何解决此错误

1 个答案:

答案 0 :(得分:0)

尝试再次清理和构建项目。尝试使用convertView,如下所示:

public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.car_adapter_layout, parent, false);
} else {
    view = convertView;
}

//other your code
return view;
}

只需编辑我的答案。