-3
<TextView
    android:id="@+id/longitude_val"
    android:layout_width="wrap_content"
    android:layout_height="14dp"
    android:text="Lattitude"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.194"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.373" />

Hi I am very confused, why i am getting error on findviewbyId
I am doing as following longitude_val=(TextView) longitude_val.findViewById(R.id.longitude_val);

Ehtisham
  • 1
  • 2

3 Answers3

0

You have defined this id for the TextView:

android:id="@+id/Lattitude"

this means you should stick to that id when you use findViewById too. You code should then be:

TextView yourTextView = findViewById(R.id.Lattitude);
Gregorio Palamà
  • 1,965
  • 2
  • 17
  • 22
0

You are getting an NPE because you are trying to find the id of an element that doesn't exist, longitude_val. Your id that you defined in your xml layout file is `Lattitude'. Your code to find this view should be this:

lattitudeTextView = (TextView) longitude_val.findViewById(R.id.Lattitude);
Michael
  • 3,093
  • 7
  • 39
  • 83
0

First of all you shouldn't name object in your java code in snake_case format.Use camelCase.

Second, your TextView had id of Lattitude and you're trying to assign an object to id of longitude_val.

Try this:

longitude_val=(TextView) longitude_val.findViewById(R.id.Lattitude);
MakinTosH
  • 623
  • 7
  • 12