I can't find why these errors are showing, anyone help?

Search This thread

MakemOne

Member
May 1, 2021
21
0
there are errors in this bit of code, I have added the line numbers at the start.



public class ViewHolder extends RecyclerView.ViewHolder {

// creating a variable for our text view and image view.
private TextView fallnameTV, what3wordsTV, gridrefTV, postcodeTV, coordinatesTV, watercourseTV, areaTV;
private ImageView userIV;

public ViewHolder(@NonNull View itemView) {
super(itemView);

71 // initializing our variables.
72 fallnameTV = itemView.findViewById(R.id.idTVfallname);
73 what3wordsTV = itemView.findViewById(R.id.idTVwhat3words);
74 gridrefTV = itemView.findViewById(R.id.idTVgridref);
75 postcodeTV = itemView.findViewById(R.id.idTVpostcode);
76 coordinatesTV = itemView.findViewById(R.id.idTVcoordinates);
77 watercourseTV = itemView.findViewById(R.id.idTVwatercourse);
78 areaTV = itemView.findViewById(R.id.idTVarea);
79 userIV = itemView.findViewById(R.id.idIVUser);
80 }
}
}


there are 4 symbol variables that can't be found TVpostcode, TVcoordinates, TVwatercourse & TVarea although to my knowledge these have been defined correctly. They show in RED and normal text whereas the others show in PURPLE ITALIC

Can anyone point my to where I will find the cause of the error.
 

James_Watson

Senior Member
  • Feb 10, 2015
    949
    127
    okblackcafe.blogspot.com
    there are errors in this bit of code, I have added the line numbers at the start.



    public class ViewHolder extends RecyclerView.ViewHolder {

    // creating a variable for our text view and image view.
    private TextView fallnameTV, what3wordsTV, gridrefTV, postcodeTV, coordinatesTV, watercourseTV, areaTV;
    private ImageView userIV;

    public ViewHolder(@NonNull View itemView) {
    super(itemView);

    71 // initializing our variables.
    72 fallnameTV = itemView.findViewById(R.id.idTVfallname);
    73 what3wordsTV = itemView.findViewById(R.id.idTVwhat3words);
    74 gridrefTV = itemView.findViewById(R.id.idTVgridref);
    75 postcodeTV = itemView.findViewById(R.id.idTVpostcode);
    76 coordinatesTV = itemView.findViewById(R.id.idTVcoordinates);
    77 watercourseTV = itemView.findViewById(R.id.idTVwatercourse);
    78 areaTV = itemView.findViewById(R.id.idTVarea);
    79 userIV = itemView.findViewById(R.id.idIVUser);
    80 }
    }
    }


    there are 4 symbol variables that can't be found TVpostcode, TVcoordinates, TVwatercourse & TVarea although to my knowledge these have been defined correctly. They show in RED and normal text whereas the others show in PURPLE ITALIC

    Can anyone point my to where I will find the cause of the error.
    Do you mean that these variables (postcodeTV, coordinatesTV, watercourseTV, areaTV) couldn't be found?
     

    MakemOne

    Member
    May 1, 2021
    21
    0
    yes I do but they were referring to them as symbols or symbol variables. Looks like after several hours trying I have found that the variables are actually there but seem as if they are not entered in the correct way or order AS doesn't find them. I think I'm sorted with that but know I will have a similar problem soon, lol.

    thanks
     

    MakemOne

    Member
    May 1, 2021
    21
    0
    This is the one that is causing a lot of bother, this line

    coordinatesTV = itemView.findViewById(R.id.idTVcoordinates);

    second line from the bottom of this code from "UserRVAdapter" in the JAVA folder. I can't see where the mistake is. idTVcoordinates is highlighted RED and displays the following in the 'build analyzer

    "C:\Users\Norman\AndroidStudioProjects\Waterfalls\app\src\main\java\com\example\waterfalls\UserRVAdapter.java:73: error: cannot find symbol
    coordinatesTV = itemView.findViewById(R.id.idTVcoordinates);
    ^
    symbol: variable idTVcoordinates
    location: class id"






    package com.example.waterfalls;

    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    import android.widget.TextView;

    import androidx.annotation.NonNull;
    import androidx.recyclerview.widget.RecyclerView;

    import com.squareup.picasso.Picasso;

    import java.util.ArrayList;

    public class UserRVAdapter extends RecyclerView.Adapter<UserRVAdapter.ViewHolder> {

    // variable for our array list and context.
    private ArrayList<UserModal> userModalArrayList;
    private Context context;

    // creating a constructor.
    public UserRVAdapter(ArrayList<UserModal> userModalArrayList, Context context) {
    this.userModalArrayList = userModalArrayList;
    this.context = context;
    }

    @NonNull
    @override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    // inflating our layout file on below line.
    View view = LayoutInflater.from(context).inflate(R.layout.user_rv_item, parent, false);
    return new ViewHolder(view);
    }

    @override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    // getting data from our array list in our modal class.
    UserModal userModal = userModalArrayList.get(position);

    // on the below line we are setting data to our text view.
    holder.fallsnameTV.setText(userModal.getfallsname());
    holder.what3wordsTV.setText(userModal.getwhat3words());
    holder.gridrefTV.setText(userModal.getgridref());
    holder.coordinatesTV.setText(userModal.getCoordinates());

    // on below line we are loading our image from the URL
    // in our image view using Picasso.
    Picasso.get().load(userModal.getfallsimage()).into(holder.userIV);
    }

    @override
    public int getItemCount() {
    // returning the size of array list.
    return userModalArrayList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

    // creating a variable for our text view and image view.
    private TextView fallsnameTV, what3wordsTV, gridrefTV, coordinatesTV;
    private ImageView userIV;

    public ViewHolder(@NonNull View itemView) {
    super(itemView);

    // initializing our variables.
    fallsnameTV = itemView.findViewById(R.id.idTVfallsname);
    what3wordsTV = itemView.findViewById(R.id.idTVwhat3words);
    gridrefTV = itemView.findViewById(R.id.idTVgridref);
    coordinatesTV = itemView.findViewById(R.id.idTVcoordinates);
    userIV = itemView.findViewById(R.id.idIVUser);
    }

    }
    }
     

    MakemOne

    Member
    May 1, 2021
    21
    0

    Check if those TextViews have been set with an id for each in your layout xml file.

    Like something as below:

    <TextView
    android:id="@+id/idTVcoordinates"
    ......
    Yes, that was it. I had not realised variables were set in there and I managed to find it by working slowly through every line of code in all the modules then using find & replace to double check and your message confirmed it. If only I got it 20 mins earlier, lol. Thanks
     

    James_Watson

    Senior Member
  • Feb 10, 2015
    949
    127
    okblackcafe.blogspot.com
    Yes, that was it. I had not realised variables were set in there and I managed to find it by working slowly through every line of code in all the modules then using find & replace to double check and your message confirmed it. If only I got it 20 mins earlier, lol. Thanks
    Okay, you are welcome. I also called the function, findViewById(R.id...., in my own apps. :cool: