M
M
Maxim Pritchin2021-03-06 20:50:03
Java
Maxim Pritchin, 2021-03-06 20:50:03

Why does an Android app compile error occur?

As I suppose you need to use this but I can't figure out how to do it

package com.rgapp;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ServerCard extends RelativeLayout {
    TextView textViewTitle;
    TextView textViewValue;
    ImageView imageView;

    String Name;

    public ServerCard(Context context) {
        super(context);
        init(context);
    }

    public ServerCard(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ServerCard(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        View.inflate(context, R.layout.servercard, this);
        setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
        textViewTitle = (TextView) findViewById(R.id.textViewTitle);
        textViewValue = (TextView) findViewById(R.id.textViewValue);
        imageView = (ImageView) findViewById(R.id.imageView);

    }

    public void setTitleText(String text) {
        textViewTitle.setText(text);
    }

    public void setValueText(String text) {
        textViewValue.setText(text);
    }
}


Mistake
error: cannot find symbol
        textViewTitle = (TextView) findViewById(R.id.textViewTitle);
                                                                               ^
  symbol:   variable textViewTitle
  location: class id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-03-06
@pritchin_maxim1

Reimport class R..
Then clean cache (Invalidate cache & restart) and restart again. Should help.
Also check if there is such an id in xmlR.id.textViewTitle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question