Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fails on nullpointerexception when setting a smiley for the first time #32

Closed
ghost opened this issue Sep 15, 2017 · 9 comments
Closed
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Sep 15, 2017

Your work is awsome! but now I need to make it work :) I follow the 3 steps in the usage part and I see the smilies in the designer preview. I did the following in an adapter:
RatingViewHolder(View itemView) {
super(itemView);
srRating = (SmileRating) itemView.findViewById(R.id.smile_rating);
srRating.setIndicator(true); //<< srRating is not null and this line works
}

@OverRide
public void onBindViewHolder(final RatingViewHolder holder, int position) {
Rating theRating = RatingList.get(position);
holder.srRating.setSelectedSmile(5,true); << fails*
}

  • SmileRating.java, line 194
    moveSmile(mTouchPoints.get(mSelectedSmile).x); <<< fails mTouchPoints size is 0
    I put a breakpoint in line 255: createTouchPoints() but it never reaches there before the above code so it fails on nullpointerexception because there is no position 5

Please advice, it seems that this is working for everyone so I wonder if I miss something
Thanks

@sujithkanna
Copy link
Owner

Are you sure it is null pointer? or IndexOutOfBounds exception

@sujithkanna
Copy link
Owner

Can you post the stackTrace of the error too?

@ghost
Copy link
Author

ghost commented Sep 16, 2017

I guess mTouchPoints should be 5 (smilies) but it contains 0 because they were never created. I think.
Here is the stacktrace
--------- beginning of crash
09-16 08:35:36.497 3992-3992/com.update.update E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.update.update, PID: 3992
java.lang.NullPointerException: Attempt to read from field 'float com.hsalf.smilerating.BaseRating$Point.x' on a null object reference
at com.hsalf.smilerating.SmileRating$2.onAnimationStart(SmileRating.java:194)
at android.animation.ValueAnimator.notifyStartListeners(ValueAnimator.java:1048)
at android.animation.ValueAnimator.start(ValueAnimator.java:1110)
at android.animation.ValueAnimator.start(ValueAnimator.java:1117)
at com.hsalf.smilerating.SmileRating.setSelectedSmile(SmileRating.java:565)
at com.hsalf.smilerating.SmileRating.setSelectedSmile(SmileRating.java:545)
at com.update.update.DateRatingAdapter.onBindViewHolder(DateRatingAdapter.java:49) -> holder.srRating.setSelectedSmile(5,true);

@ghost
Copy link
Author

ghost commented Sep 16, 2017

I hope the above will be enough but if you need more info from me, let me know

@yinqingh
Copy link

I got the same error

@ghost
Copy link
Author

ghost commented Sep 18, 2017

@LeooonH It seems that we're the only ones to get this error... I wonder what the problem is. Waiting for @sujithkanna response.

@BRKNCD
Copy link

BRKNCD commented Feb 3, 2018

Hi all,
I want to ask why when I set true for the animation it gives me java.lang.NullPointerException: Attempt to read from field 'float com.hsalf.smilerating.BaseRating$Point.x' on a null object reference

My code (simplyfied):

public class scoreActivity extends AppCompatActivity{

    SmileRating smileRating;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.score_layout);
        smileRating = (SmileRating) findViewById(R.id.smile_rating);
        smileRating.setIndicator(true);

// this works
        smileRating.setSelectedSmile(BaseRating.TERRIBLE);

// this one doesn't works
//      smileRating.setSelectedSmile(BaseRating.TERRIBLE,true);
    }

What am I doing wrong?

Thank you for your AWESOME work! :D

@sujithkanna
Copy link
Owner

It is because the view is not inflated yet fully, so try posting it using runnable.

smileyRating.post(new Runnable() {
            @Override
            public void run() {
                smileRating.setSelectedSmile(BaseRating.TERRIBLE,true);
            }
        });

Can you try this?

Thank you :D

@benoffi7
Copy link

solution by @sujithkanna works! same problem with animate and the snippet works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants