Hi, im not sure if that is the best title, but anyway.
Im using an android module to create my own android widget. My problem is that when I try to do a modification on my view, by calling a method that i have in my proxy, the TiUIView hasnt been created yet (the createView method on my proxy hasnt been called yet), so when i do view.someMethod I got a NullPointerException. I also have another proxy method that its been called when I tap any part of my widget, and it works, because for the time i touch the screen the TiUIView has been already created.
This is my javascript code that Im using for instantiating and calling my proxy
function Chart() { //create object instance, a parasitic subclass of Observable var chartModule = require('com.fede.chartmodule'); var events = [0.1, 0.375, 0.35, 0.625, 0.7, 0.875, 0.8, 0.125, 0.91, 0.375]; var chart = chartModule.createChartView(); chart.addEventListener("click", function(e) { chart.setSelection(e.x); }); chart.setEvents(events); } module.exports = Chart;And this is my Proxy code
@Kroll.proxy(creatableInModule=ChartmoduleModule.class) public class ChartViewProxy extends TiViewProxy { public ChartViewProxy() { super(); } @Override public TiUIView createView(Activity activity) { view = new ChartView(this); view.getLayoutParams().autoFillsHeight = true; view.getLayoutParams().autoFillsWidth = true; return view; } . . . public void setSelection(Float x) { view.setSelection(x); } public void setEvents(Float[] events) { ArrayList<float[]> eventsPoints = new ArrayList<float[]>(); for(int i = 0; i < events.length; i += 2) { float[] point = {events[i], events[i + 1]}; eventsPoints.add(point); } view.setEventsPoints(eventsPoints); } }So, I got a NullPointerException when calling setEvents(...) but there is no problem when calling setSelection(...)
Also, I "solved" this problem by instantiating the view on the setEvents(...) method if its null. I just dont think this is a correct way to solve this problem and I would like to know whats happening here!!!
Thanks for your help guys!!!
1 Answer
You may want to make view to a class var so its accessable through this on the class level ?
Your Answer
Think you can help? Login to answer this question!