SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
0
0

Hii !!

I have extracted the ECG Sample Code from your source project and i want to update the same RealTime via Bluetooth. I am getting a nullpoint exception.
Below is my source code too along with exception.

Exception

06-18 15:44:02.708 15813-15813/com.advancetechindia.wirelessecg
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.advancetechindia.wirelessecg, PID: 15813
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.advancetechindia.wirelessecg/com.advancetechindia.wirelessecg.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method
‘com.scichart.extensions.builders.DataSeriesBuilder$XyDataSeriesBuilder
com.scichart.extensions.builders.SciChartBuilder.newXyDataSeries(java.lang.Class,
java.lang.Class)’ on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2561)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method
‘com.scichart.extensions.builders.DataSeriesBuilder$XyDataSeriesBuilder
com.scichart.extensions.builders.SciChartBuilder.newXyDataSeries(java.lang.Class,
java.lang.Class)’ on a null object reference
at com.advancetechindia.wirelessecg.MainActivity.(MainActivity.java:394)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1100)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2551)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6123) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

Source Code

settingChart() is Called in onCreate() of Activity

//SciChart Work

protected final SciChartBuilder sciChartBuilder =
SciChartBuilder.instance();
private final static long TIME_INTERVAL = 20;

private final IXyDataSeries<Double, Double> series0 = sciChartBuilder.newXyDataSeries(Double.class,
Double.class).withFifoCapacity(3850).build();
private final IXyDataSeries<Double, Double> series1 = sciChartBuilder.newXyDataSeries(Double.class,
Double.class).withFifoCapacity(3850).build();

private ArrayList<Double> sourceData;
  
  private int _currentIndex;
  private int _totalIndex;
  
  private MainActivity.TraceAOrB whichTrace = MainActivity.TraceAOrB.TraceA;
  
  private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
  private ScheduledFuture<?> schedule;
  
  private volatile boolean isRunning = true;
  SciChartSurface surface;
  private void settingSciChart() {
      sourceData=new ArrayList<>();
      surface=(SciChartSurface)findViewById(R.id.ecg);
  
      initExample();
  }
  
  private void initExample() {
      UpdateSuspender.using(surface, new Runnable() {
          @Override
          public void run() {
              final IAxis xBottomAxis = sciChartBuilder.newNumericAxis()
                      .withVisibleRange(new DoubleRange(0d, 10d))
                      .withAutoRangeMode(AutoRange.Never)
                      .withAxisTitle("Time (seconds)")
                      .build();
  
              final IAxis yRightAxis = sciChartBuilder.newNumericAxis()
                      .withVisibleRange(new DoubleRange(-0.5d, 1.5d))
                      .withAxisTitle("Voltage (mV)")
                      .build();
  
              final IRenderableSeries rs1 = sciChartBuilder.newLineSeries()
                      .withDataSeries(series0)
                      .build();
  
              final IRenderableSeries rs2 = sciChartBuilder.newLineSeries()
                      .withDataSeries(series1)
                      .build();
  
              Collections.addAll(surface.getXAxes(), xBottomAxis);
              Collections.addAll(surface.getYAxes(), yRightAxis);
              Collections.addAll(surface.getRenderableSeries(), rs1, rs2);
          }
      });
  
      schedule = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
          @Override
          public void run() {
              UpdateSuspender.using(surface, appendDataRunnable);
          }
      }, 0, TIME_INTERVAL, TimeUnit.MILLISECONDS);
  }
  
  private final Runnable appendDataRunnable = new Runnable() {
      @Override
      public synchronized void run() {
          if (isRunning) {
              for (int i = 0; i < 10; i++) {
                  appendPoint(400);
              }
          }
      }
  };
  
  private synchronized void appendPoint(double sampleRate) {
      if (_currentIndex >= sourceData.size()) {
          _currentIndex = 0;
      }
  
      // Get the next voltage and time, and append to the chart
      double voltage = sourceData.get(_currentIndex);
      double time = (_totalIndex / sampleRate) % 10;
  
      if (whichTrace == MainActivity.TraceAOrB.TraceA) {
          series0.append(time, voltage);
          series1.append(time, Double.NaN);
      } else {
          series0.append(time, Double.NaN);
          series1.append(time, voltage);
      }
  
      _currentIndex++;
      _totalIndex++;
  
      if (_totalIndex % 4000 == 0) {
          whichTrace = whichTrace == MainActivity.TraceAOrB.TraceA ? MainActivity.TraceAOrB.TraceB : MainActivity.TraceAOrB.TraceA;
      }
  }
  
  enum TraceAOrB {
      TraceA,
      TraceB
  }
  
Version
7.1.2
  • You must to post comments
Best Answer
1
0

Hi Gourav,

It looks like you didn’t call init() in your code ( or at least you didn’t post a code fragment which contains it) so SciChartBuilder returns null when you call getInstance(). Can you try to add it before calling SciChartBuilder.getInstance()

  SciChartBuilder.init(context);

Hope this will help you!

Best regards,
Yura

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.