1

I'm following the ShinobiCharts for Android quick start guide, except adding the chart fragment programmatically, like so:

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ChartFragment chartFragment = new ChartFragment();
fragmentTransaction.add(R.id.history_container, chartFragment, "chart");
fragmentTransaction.commit();
ShinobiChart shinobiChart = chartFragment.getShinobiChart();

Everything looks to be fine until the last line, when shinobiChart always initializes to null. I'm calling this from a custom class inheriting from Fragment, in the onCreateView method, and I suspect this problem might be rooted in that - but I'm not sure how to fix it.

user2709279
  • 353
  • 1
  • 3
  • 15

1 Answers1

1

The ChartFragment gets its shinobiChart during ChartFragment.onCreate, so in your code it's still null at this time - all you've done so far is to instantiate it.

Presumably you're planning to do some chart setup using the ShinobiChart reference, so I'd suggest subclassing ChartFragment, and moving your setup code into its onCreate method (be sure to call super.onCreate(savedInstanceState);).

There's an example of this pattern in the CustomDataAdapter sample.

  • 1
    That's a much better model, thanks, and seems to get past the null issue. But even with this approach I'm still getting an error: `Couldn't load shinobicharts-android from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.domain.appname-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.domain.appname-1, /system/lib]]]: findLibrary returned null`. Is this a separate issue? All the classes compile just fine, so I'm not sure what's happening here. – user2709279 Oct 21 '13 at 23:14