GreenBot EventBus cannot send event

I am using EventBus to communicate from a long running thread with fragments that update their interface. This long stream mainly listens for network activity, analyzes it and pushes events to the bus. I have 2 snippets set to receive events.

I am getting an error while updating the Fragments UIs (Text View) from the onEvent Fragments method. How do I update the UI in a snippet from a separate thread?

Here is my code for the snippets and the logcat output I see ...

Logcat:

10-15 02:19:44.637: I/System.out(682): debugger has settled (1440)
10-15 02:19:45.021: V/BRRT(682): start thread
10-15 02:19:45.021: V/BRRT(682): past start thread
10-15 02:19:45.031: V/TEST(682): running thread...
10-15 02:19:45.121: D/Event(682): No subscribers registered for event class com.broadreach.radiotester.io.ExpeditionEvent
10-15 02:19:45.121: D/Event(682): No subscribers registered for event class de.greenrobot.event.NoSubscriberEvent
10-15 02:19:45.261: V/BRRT(682): OneUp event received: 204 : 32
10-15 02:19:45.271: W/ResourceType(682): No package identifier when getting value for resource number 0x00000000
10-15 02:19:45.351: E/Event(682): Could not dispatch event: class com.broadreach.radiotester.io.ExpeditionEvent to subscribing class class com.broadreach.radiotester.screens.OneUpScreen
10-15 02:19:45.351: E/Event(682): android.content.res.Resources$NotFoundException: String resource ID #0x0
10-15 02:19:45.351: E/Event(682):   at android.content.res.Resources.getText(Resources.java:247)
10-15 02:19:45.351: E/Event(682):   at android.widget.TextView.setText(TextView.java:3428)
10-15 02:19:45.351: E/Event(682):   at com.broadreach.radiotester.screens.OneUpScreen.onEvent(OneUpScreen.java:47)
10-15 02:19:45.351: E/Event(682):   at java.lang.reflect.Method.invokeNative(Native Method)
10-15 02:19:45.351: E/Event(682):   at java.lang.reflect.Method.invoke(Method.java:511)
10-15 02:19:45.351: E/Event(682):   at de.greenrobot.event.EventBus.invokeSubscriber(EventBus.java:569)
10-15 02:19:45.351: E/Event(682):   at de.greenrobot.event.EventBus.postToSubscription(EventBus.java:500)
10-15 02:19:45.351: E/Event(682):   at de.greenrobot.event.EventBus.subscribe(EventBus.java:288)
10-15 02:19:45.351: E/Event(682):   at de.greenrobot.event.EventBus.register(EventBus.java:189)
10-15 02:19:45.351: E/Event(682):   at de.greenrobot.event.EventBus.registerSticky(EventBus.java:166)
10-15 02:19:45.351: E/Event(682):   at com.broadreach.radiotester.screens.OneUpScreen.onResume(OneUpScreen.java:33)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.app.Fragment.performResume(Fragment.java:1547)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:978)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
10-15 02:19:45.351: E/Event(682):   at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
10-15 02:19:45.351: E/Event(682):   at android.view.View.measure(View.java:12603)
10-15 02:19:45.351: E/Event(682):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
10-15 02:19:45.351: E/Event(682):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-15 02:19:45.351: E/Event(682):   at android.view.View.measure(View.java:12603)
10-15 02:19:45.351: E/Event(682):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
10-15 02:19:45.351: E/Event(682):   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-15 02:19:45.351: E/Event(682):   at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
10-15 02:19:45.351: E/Event(682):   at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
10-15 02:19:45.351: E/Event(682):   at android.view.View.measure(View.java:12603)
10-15 02:19:45.351: E/Event(682):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
10-15 02:19:45.351: E/Event(682):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-15 02:19:45.351: E/Event(682):   at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2072)
10-15 02:19:45.351: E/Event(682):   at android.view.View.measure(View.java:12603)
10-15 02:19:45.351: E/Event(682):   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1044)
10-15 02:19:45.351: E/Event(682):   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
10-15 02:19:45.351: E/Event(682):   at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 02:19:45.351: E/Event(682):   at android.os.Looper.loop(Looper.java:137)
10-15 02:19:45.351: E/Event(682):   at android.app.ActivityThread.main(ActivityThread.java:4340)
10-15 02:19:45.351: E/Event(682):   at java.lang.reflect.Method.invokeNative(Native Method)
10-15 02:19:45.351: E/Event(682):   at java.lang.reflect.Method.invoke(Method.java:511)
10-15 02:19:45.351: E/Event(682):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-15 02:19:45.351: E/Event(682):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-15 02:19:45.351: E/Event(682):   at dalvik.system.NativeStart.main(Native Method)
10-15 02:19:45.351: D/Event(682): No subscribers registered for event class de.greenrobot.event.SubscriberExceptionEvent
10-15 02:19:45.551: V/BRRT(682): FourUp event received: 204 : 32
10-15 02:19:45.561: W/ResourceType(682): No package identifier when getting value for resource number 0x00000000

      

Here is one snippet (they look the same):

public class OneUpScreen extends ScreenFragment {   
    private Button name;
    private TextView c00Title, c00Data;

    //DEBUG
    public String title;

    //DEBUG
    private int counter = 0;

    //for logging and convenience
    private static final String TAG = "BRRT";   


    @Override
    public void onResume(){
        super.onResume();
        EventBus.getDefault().registerSticky(this);
    }

    @Override
    public void onPause(){
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    //process the bus messaging
    public void onEvent(ExpeditionEvent event){
        Log.v(TAG, "OneUp event received: " + event.getEventId() + " : " + event.getEventScreenValue());

        c00Data = (TextView) getView().findViewById(R.id.c00Data);
        c00Data.setText(counter);

        counter++;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.one_up_screen_layout, container, false);

        name = (Button) v.findViewById(R.id.lblTitle);
        c00Title = (TextView) v.findViewById(R.id.c00Title);
        c00Data = (TextView) v.findViewById(R.id.c00Data);

        Bundle bundle = this.getArguments();

        //initial set up of the text on the screen
        //null check
        name.setText((bundle.getString("name") == null) ? "error" : bundle.getString("name"));
        c00Title.setText((bundle.getString("c00Title") == null) ? "error" : bundle.getString("c00Title"));
        title = bundle.getString("c00Title");

        return v;
    }

    public OneUpScreen(){

    }

    public static OneUpScreen newInstance() {
        OneUpScreen frag = new OneUpScreen();
        return frag;
    }

    //attach the config for this instance.
    @Override
    public void setConfig(ScreenConfig sc){
        //set up the data to paint the screen for the first time
        Bundle b = new Bundle();

        //now we have to parse some stuff into a bundle and send the bundle to the fragment
        b.putString("name", sc.getName());
        b.putString("c00Title", sc.getEvents().get(0).getCleanName());
        b.putInt("c00Data", sc.getEvents().get(0).getEventID());

        //pass it along
        this.setArguments(b);
    }


    @Override
    public void update(SparseArray<String> sensorDataMap) {
        Log.v(TAG, "OneUp Update called: " + counter);
        counter++;
    }
}

      

The onEvent method is where I am looking at here. If you notice in the log, this method makes a call. But I cannot get to the textView inside it. Initially, I just kept a reference to the text view that I accept in the onCreate () method. but I saw also an example where you look at it again in event handling, so I moved on to this with no luck.

If I choose:

c00Data.setText(counter);

      

then everything works well.

What am I missing here?

+3


source to share


1 answer


Ok, for those who come here later, this is how I solved it ...

It turned out that the key error I was seeing was not an event related error, but a resource related error.

10-15 02:19:45.271: W/ResourceType(682): No package identifier when getting value for resource number 0x00000000

      

I looked elsewhere on SO and found this:

No bundle id when getting value for resource number

Then I went back to my code and rewrote the TextView.setText () calls to look different.



Old way (counter is int):

c00Data.setText(counter);

      

New way:

c00Data.setText(""+counter);

      

And so it was. I screamed.

+7


source







All Articles