MetaWear Starter Application issue with RouteBuilder

Working through the demo here.

When compiling / Running I get an error in the DeviceSetupActivityFragment.java file:

"error: cannot find symbol class RouteElement"

Code in question (bolds are where the compiler has turned items red or underlined:

`@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

view.findViewById(R.id.acc_start).setOnClickListener(**new View.OnClickListener**() {
    @Override
    public void onClick(View v) {
        accelerometer.acceleration().addRouteAsync(**new RouteBuilder()** {
           ** @Override**
            public void **configure**(**RouteElement** source) {
                source.**stream**(**new Subscriber() **{
                    @Override
                    public void apply(Data data, Object... env) {
                        Log.i("MainActivity", data.value(Acceleration.class).toString());
                    }
                });
            }
        }).continueWith(**new Continuation<Route, Void>()** {
            @Override
                public Void then(Task<Route> task) throws **Exception** {
                    accelerometer.acceleration().start();
                    accelerometer.start();
                    return null;
                }
        });
    }
});
view.findViewById(R.id.acc_stop).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        accelerometer.stop();
        accelerometer.acceleration().stop();
        metawear.tearDown();
    }
});

}`

Comments

  • Guess you can't bold in a code snippet....sorry. So everything in between ** and ** is where the IDE is saying errors are.

  • edited July 2019

    OP did some other funny things formatting wise, so re-pasting for clarity. Here is the proper code section trying to implement:

    This is included in the top of file....

    import com.mbientlab.metawear.builder.RouteBuilder;

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    
        view.findViewById(R.id.acc_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                accelerometer.acceleration().addRouteAsync(new RouteBuilder() {
                    @Override
                    public void configure(RouteElement source) {
                        source.stream(new Subscriber() {
                            @Override
                            public void apply(Data data, Object... env) {
                                Log.i("MainActivity", data.value(Acceleration.class).toString());
                            }
                        });
                    }
                }).continueWith(new Continuation<Route, Void>() {
                    @Override
                        public Void then(Task<Route> task) throws Exception {
                            accelerometer.acceleration().start();
                            accelerometer.start();
                            return null;
                        }
                });
            }
        });
        view.findViewById(R.id.acc_stop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                accelerometer.stop();
                accelerometer.acceleration().stop();
                metawear.tearDown();
            }
        });
    }
    
  • You're just missing some imports. The IDE will provide suggestions and insert the appropriate import statements for you.

  • @Eric said:
    You're just missing some imports. The IDE will provide suggestions and insert the appropriate import statements for you.

    It doesn't though. I know what you mean when it will give you a recomendation witha mouse over...but for this issue it doesn't. On run, the compiler just outputs:

    error: cannot find symbol class RouteElement

  • edited July 2019

    I am having the same issue as trabucco. When I follow the IDE's recommendations and add
    'import com.mbientlab.metawear.builder.RouteBuilder;', it does not recognize the "RouteElement source'

    Then as I hover my mouse over the "new RouteBuilder" the following error message pops up -
    Class 'Anonymous class derived from RouteBuilder' must either be declared abstract or implement abstract method 'configure(RouteComponent)' in 'RouteBuilder'.

    It seems that it is unable to find the RouteBuilder within the Android SDK. I am running Android Studios 3.4.2, and mbientlab:metawear 3.7.1 Any suggestions?

  • @SleeperMan said:
    I am having the same issue as trabucco. When I follow the IDE's recommendations and add
    'import com.mbientlab.metawear.builder.RouteBuilder;', it does not recognize the "RouteElement source'

    Then as I hover my mouse over the "new RouteBuilder" the following error message pops up -
    Class 'Anonymous class derived from RouteBuilder' must either be declared abstract or implement abstract method 'configure(RouteComponent)' in 'RouteBuilder'.

    It seems that it is unable to find the RouteBuilder within the Android SDK. I am running Android Studios 3.4.2, and mbientlab:metawear 3.7.1 Any suggestions?

    Yes, same error on mouse over of "RouteBuilder"

  • @SleeperMan said:
    I am having the same issue as trabucco. When I follow the IDE's recommendations and add
    'import com.mbientlab.metawear.builder.RouteBuilder;', it does not recognize the "RouteElement source'

    Then as I hover my mouse over the "new RouteBuilder" the following error message pops up -
    Class 'Anonymous class derived from RouteBuilder' must either be declared abstract or implement abstract method 'configure(RouteComponent)' in 'RouteBuilder'.

    Replace RouteElement with RouteComponent.

  • @Eric said:
    Replace RouteElement with RouteComponent.

    This finally worked for me. That is indeed a bug then in the code on github and the documentation here:
    https://mbientlab.com/tutorials/Java.html

  • edited October 2020

    I confirm there is an error.
    1. First you have to give alt + enter on classes
    2. Instead of: RouteElement you have to give: RouteComponent

    Question for the same tutorial:
    How to run / test DeviceSetupActivityFragment (not MainActivity)?

  • <activity android:name=".DeviceSetupActivityFragment"
    android:label="@string/app_name"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    ` ``

    ^^ but not working:

  • edited November 2020

    when I run <activity android:name=".MainActivity"> then I do not find any sensors (on the Android simulator)

    scan from the app: nRF Connect for Mobile
    https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp

  • Same on the phone:

Sign In or Register to comment.