Pre loader

Create annotation with gesture causes crash


Hello there,

I’m trying to implement adding line annotation on touch, but this causes crash.

I’m watching example android app in fragment CreateAnnotationsDynamicallyFragment.

I guess, it should be very easy, but example uses data binding and part of code is hidden somewhere + source code is obfuscated, so it’s hard for me to understand what is wrong.

Can someone give a short example of how to add annotation on touch?



 Process: process_name, PID: 24978
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Comparable com.scichart.charting.visuals.axes.IAxis.getDataValue(float)' on a null object reference
    at com.scichart.charting.modifiers.AnnotationCreationModifier.a(SourceFile:203)
    at com.scichart.charting.modifiers.AnnotationCreationModifier.onTouchDown(SourceFile:155)
  • You must to post comments
Best Answer

Hi Vadim,

We have an example in our demo application which shows how to do it. Based on your exception I would say that annotation created by modifier have incorrect AxisId for X or Y axis. This can happen if you change Id of axis but forgot to set the same id in AnnotationCreationModifier or any other case when for some reason annotation can’t locate associated X/YAxis. I would suggest to check id of axis which you use and ensure that you set the same id for modifier:

    // set ids which should be set to new annotations

Best regards,

  • You must to post comments

Hi Yura,

This is how i did it, but still crashing on touch:

private void initDrawingAnnotations() {
    annotationCreationModifier = new AnnotationCreationModifier();

    DefaultAnnotationFactory annotationFactory = new DefaultAnnotationFactory();

    annotationFactory.setFactoryForAnnotationType(DefaultAnnotationFactory.LINE_ANNOTATION, new IAnnotationFactory() {
        public IAnnotation createAnnotation(ISciChartSurface parentSurface, int annotationType) {
            return sciChartBuilder.newLineAnnotation()
                    .withStroke(1, Color.RED)
  • Yura Khariton
    Please try to use code from my answer because modifier will override XAxisId/YAxisId which you set in factory with values from modifier’s XAxisId/YAxisId properties. If this doesn’t help please attach entire project which reproduces this issue.
  • Kirey Vadim
    Thanks, it worked
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies