Java Question illegal start of expression return Observable.defer(() ->

somed3v3loper

Well-Known Member
Licensed User
Hello again
Just a new library with new barrier :D

I got this error from SLC when trying to wrap this project https://github.com/niqdev/ipcam-view

B4X:
Mjpeg.java:84: error: illegal start of expression
        return Observable.defer(() -> {
                                 ^
1 error


Error.



B4X:
    @NonNull
    private Observable<MjpegInputStream> connect(String url) {
/*this is line 84 */        return Observable.defer(() -> {
            try {
                HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
                InputStream inputStream = urlConnection.getInputStream();
                switch (type) {
                    // handle multiple implementations
                    case DEFAULT:
                        return Observable.just(new MjpegInputStreamDefault(inputStream));
                    case NATIVE:
                        return Observable.just(new MjpegInputStreamNative(inputStream));
                }
                throw new IllegalStateException("invalid type");
            } catch (IOException e) {
                return Observable.error(e);
            }
         });
    }

Is it possible that "Observable" uses some kind of tokens or special symbols that SLC does not understand ?

How can I solve such issue ?

Thanks in advance
 

DonManfred

Expert
Licensed User

somed3v3loper

Well-Known Member
Licensed User
Seems like the new Jack toolchain does support lambda expressions: http://developer.android.com/preview/j8-jack.html#supported-features

B4A currently doesn't use it. Note that this is not the default toolchain in Android Studio and it also doesn't support new features in Android Studio 2.0.
What do you think the best solution other than tigrot's one :D ?

The solution could be recoding the routine. 30 minutes ago I didn't know the existance of lamba expressions. I lived happy for 44 years in IT without them !
 

Erel

B4X founder
Staff member
Licensed User
I guess that you are right.

The code should be:
B4X:
return Observable.defer(new Func0<Observable<MjpegInputStream>>() {
 Observable<MjpegInputStream>call() {
try {
 HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();InputStreaminputStream = urlConnection.getInputStream();switch (type) {
 // handle multiple implementationscase DEFAULT:return Observable.just(new MjpegInputStreamDefault(inputStream));case NATIVE:return Observable.just(new MjpegInputStreamNative(inputStream));}
 throw new IllegalStateException("invalid type");
 } catch (IOException e) {
 return Observable.error(e);
 }
}
});
 

somed3v3loper

Well-Known Member
Licensed User
I think this is not related to original issue but now I get this error .
Why does this happen ?

B4X:
incompatible types
case DEFAULT:return Observable.just(new MjpegInputStreamDefault(inputStream));
                                    ^
  required: Observable<MjpegInputStream>
  found:    Observable<MjpegInputStreamDefault>
1 error


Error.
 

harvyjackk

New Member
Mjpeg.java:84: error: illegal start of expression

This error is a compile time error when the compiler encounters an inappropriate statement in the source code. This error can be encountered in various scenarios . Illegal start of expression can be encountered in various scenarios. The following are the most common errors:
  • Missing an opening or closing curly bracket for a code block
  • Declaring a function inside another function
  • Using an access specifier with a function's local variable
  • String Character Without Double Quote

To debug this error, try looking at the lines preceding the error message for missing brackets, curly braces or semicolons and check the syntax.
 
Top