1. Are you ready for the Galaxy S20? Here is everything we know so far!

Null Pointer Exception after taking their refrences

Discussion in 'Android Development' started by MamtaJatRana, Mar 24, 2021.

  1. MamtaJatRana

    MamtaJatRana Lurker
    Thread Starter

    Hello Guys
    I am stuck at some point in my Android Project.
    Code (Java):
    1.  public void initStreamerInfo() {
    2.  
    3.         ImageView streamerAvatar= findViewById(R.id.livestreamingHeader_streamerImage);
    4.         TextView streamerName = findViewById(R.id.livestreamingHeader_name);
    5.         TextView streamerAge = findViewById(R.id.livestreamingHeader_age);
    6.         followingImg = findViewById(R.id.livestreamingHeader_followedStreamer);
    7.         if (streamerAvatar==null){
    8.             Log.d("statusofimgvw","kuch nhi ho sakta");
    9.         }
    10.         else {
    11.             Log.d("statusofimgvw","Not null");
    12.         }
    13.         User puser=mLiveStreamObject.getAuthor();
    14.         Log.d("checkingvaluel",puser.getProfilePhotos().get(puser.getAvatarPhotoPosition()).getUrl());
    15.         Log.d("checkingvaluel",puser.getColFirstName());
    16.         Log.d("checkingvaluel"," "+mLiveStreamObject.getAuthor().getProfilePhotos());
    17.         QuickHelp.getAvatars(mLiveStreamObject.getAuthor(), streamerAvatar);
    18.         streamerName.setText(String.format("%s, ", mLiveStreamObject.getAuthor().getColFirstName()));
    19.  
    20.         if (mLiveStreamObject.getAuthor().getBirthDate() != null){
    21.             streamerAge.setText(String.valueOf(QuickHelp.getAgeFromDate(mLiveStreamObject.getAuthor().getBirthDate())));
    22.         }
    23.  
    24.         setTimer(mLiveStreamObject.getStartedAt());
    25.  
    26.         FollowModel.queryFollowSingleUser(mLiveStreamObject.getAuthor(), new FollowModel.QueryFollowListener() {
    27.             @Override
    28.             public void onQueryFollowSuccess(boolean isFollowing) {
    29.  
    30.                 if (isFollowing){
    31.                     followingImg.setVisibility(View.VISIBLE);
    32.                     isFollowingUser  = true;
    33.                 } else {
    34.                     followingImg.setVisibility(View.GONE);
    35.                     isFollowingUser  = false;
    36.                 }
    37.             }
    38.  
    39.             @Override
    40.             public void onQueryFollowError(ParseException error) {
    41.                 followingImg.setVisibility(View.GONE);
    42.                 isFollowingUser  = false;
    43.             }
    44.         });
    45.     }

    It's my java code where I am initializing the xml components and using them.
    Code (Java):
    1.  public static void getAvatars(User user, ImageView imageView){
    2.  
    3.         ColorDrawable colorDrawable = new ColorDrawable(ContextCompat.getColor(Application.getInstance().getApplicationContext(), R.color.highlight_light_ripple));
    4.  
    5.         // Load profile Photos
    6.         if (user.getProfilePhotos() != null && user.getProfilePhotos().size() > 0) {
    7.  
    8.             Glide.with(Application.getInstance().getApplicationContext())
    9.                     .load(user.getProfilePhotos().get(user.getAvatarPhotoPosition()).getUrl())
    10.                     .error(colorDrawable)
    11.                     .centerCrop()
    12.                     .circleCrop()
    13.                     .fitCenter()
    14.                     .placeholder(colorDrawable)
    15.                     .into(imageView);
    16.  
    17.         } else {
    18.  
    19.             Glide.with(Application.getInstance().getApplicationContext())
    20.                     .load(colorDrawable)
    21.                     .into(imageView);
    22.         }
    23.     }
    It's the method named getAvatars in another class named QuickHelp.
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <merge xmlns:android="http://schemas.android.com/apk/res/android"
    3.     xmlns:aapt="http://schemas.android.com/aapt"
    4.     xmlns:app="http://schemas.android.com/apk/res-auto"
    5.     xmlns:tools="http://schemas.android.com/tools"
    6.     android:layout_width="match_parent"
    7.     android:layout_height="wrap_content">
    8.  
    9.     <View
    10.         android:id="@+id/imageCenterView"
    11.         android:layout_width="1dp"
    12.         android:layout_height="1dp"
    13.         app:layout_constraintBottom_toBottomOf="@+id/livestreamingHeader_streamerImage"
    14.         app:layout_constraintEnd_toEndOf="@+id/livestreamingHeader_streamerImage"
    15.         app:layout_constraintStart_toStartOf="@+id/livestreamingHeader_streamerImage"
    16.         app:layout_constraintTop_toTopOf="@+id/livestreamingHeader_streamerImage" />
    17.  
    18.     <com.sos.GD_Live.modules.circularimageview.CircleImageView
    19.         android:id="@+id/livestreamingHeader_streamerImage"
    20.         android:layout_width="@dimen/icon_xlg"
    21.         android:layout_height="@dimen/icon_xlg"
    22.         android:layout_marginStart="@dimen/spacing_md"
    23.         android:layout_marginTop="@dimen/spacing_md"
    24.         android:layout_marginBottom="@dimen/spacing_md"
    25.         app:layout_constraintBottom_toBottomOf="parent"
    26.         app:layout_constraintStart_toStartOf="parent"
    27.         app:layout_constraintTop_toTopOf="parent"
    28.         android:layout_marginLeft="@dimen/spacing_md" />
    29.  
    30.     <TextView
    31.         android:id="@+id/livestreamingHeader_status"
    32.         style="?attr/textStyleP3Inverse"
    33.         android:layout_width="wrap_content"
    34.         android:layout_height="wrap_content"
    35.         android:minWidth="26dp"
    36.         android:padding="1dp"
    37.         android:text="00:00"
    38.         android:background="@drawable/bg_livestreaming_rounded_rect_red_carrot"
    39.         app:layout_constraintBottom_toBottomOf="@+id/livestreamingHeader_streamerImage"
    40.         app:layout_constraintEnd_toEndOf="@+id/imageCenterView"
    41.         app:layout_constraintStart_toStartOf="@+id/imageCenterView"
    42.         app:layout_constraintTop_toBottomOf="@+id/livestreamingHeader_streamerImage" />
    43.  
    44.     <LinearLayout
    45.         android:id="@+id/livestreamingHeader_streamerInfo"
    46.         android:layout_width="wrap_content"
    47.         android:layout_height="wrap_content"
    48.         android:layout_marginStart="@dimen/spacing_sm"
    49.         android:layout_marginEnd="@dimen/spacing_md"
    50.         android:gravity="center_vertical"
    51.         android:orientation="horizontal"
    52.         app:layout_constraintBottom_toTopOf="@+id/livestreamingHeader_subtitle"
    53.         app:layout_constraintStart_toEndOf="@+id/livestreamingHeader_streamerImage"
    54.         app:layout_constraintTop_toTopOf="@+id/livestreamingHeader_streamerImage"
    55.         app:layout_constraintVertical_chainStyle="packed"
    56.         android:layout_marginRight="@dimen/spacing_md"
    57.         android:layout_marginLeft="@dimen/spacing_sm">
    58.  
    59.         <TextView
    60.             android:id="@+id/livestreamingHeader_name"
    61.             style="?attr/textStyleP2Inverse"
    62.             android:layout_width="wrap_content"
    63.             android:layout_height="wrap_content"
    64.             android:ellipsize="end"
    65.             android:maxWidth="@dimen/streamer_name_max_width"
    66.             android:maxLines="1"
    67.             tools:text="Maravilho, "
    68.             android:singleLine="true" />
    69.  
    70.         <TextView
    71.             android:id="@+id/livestreamingHeader_age"
    72.             style="?attr/textStyleP2Inverse"
    73.             android:layout_width="wrap_content"
    74.             android:layout_height="wrap_content"
    75.             tools:text="25"
    76.             android:maxLines="1" />
    77.  
    78.         <ImageView
    79.             android:id="@+id/livestreamingHeader_followedStreamer"
    80.             style="?attr/textStyleP2Inverse"
    81.             android:layout_width="wrap_content"
    82.             android:layout_height="wrap_content"
    83.             android:layout_marginStart="4dp"
    84.             android:visibility="gone"
    85.             app:srcCompat="@drawable/ic_livestream_favorites_streamer"
    86.             android:layout_marginLeft="4dp" />
    87.     </LinearLayout>
    88.  
    89.     <TextView
    90.         android:id="@+id/livestreamingHeader_subtitle"
    91.         style="?attr/textStyleP3Inverse"
    92.         android:layout_width="0dp"
    93.         android:layout_height="wrap_content"
    94.         android:layout_marginEnd="@dimen/spacing_md"
    95.         android:alpha="0.5"
    96.         android:ellipsize="end"
    97.         android:maxWidth="120dp"
    98.         android:maxLines="1"
    99.         android:singleLine="true"
    100.         android:visibility="gone"
    101.         app:layout_constraintBottom_toBottomOf="@+id/livestreamingHeader_streamerImage"
    102.         app:layout_constraintEnd_toEndOf="parent"
    103.         app:layout_constraintStart_toStartOf="@+id/livestreamingHeader_streamerInfo"
    104.         app:layout_constraintTop_toBottomOf="@+id/livestreamingHeader_streamerInfo"
    105.         app:layout_constraintVertical_chainStyle="packed"
    106.         android:layout_marginRight="@dimen/spacing_md" />
    107. </merge>
    108.  
    it's my xml code.

    The error is that when I executing this code it shows me null pointer exception on accessing each view after taking refrence also.

    Thanks in Advance
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...