java - Android: "Expression expected" when passing an Activity class -


i kind of new android programming , java in general, , cannot work out causing error; understand should work. in code shown below (near end of first snippet), line "colouroutput.do_output((activity) com.(name-removed).(app-name-removed).colouractivity);" giving error "expression expected" on text "com.(name-removed).(app-name-removed).colouractivity" in android studio 1.1.0.

(this inside class "public class colouractivity extends activity".)

        private camera.previewcallback preview_callback = new camera.previewcallback() {         @override         public void onpreviewframe(byte[] data, camera camera) {             int width = mcamera.getparameters().getpreviewsize().width;             int height = mcamera.getparameters().getpreviewsize().height;             int raw_pixels[];             int pixels[];              raw_pixels = new int[width * height];             pixels = new int[get_sample_width() * get_sample_height()];             convert_yuv(raw_pixels, data, width, height);             crop_pixels(raw_pixels, pixels, width, height, (width - get_sample_width()) / 2, (height - get_sample_height()) / 2, get_sample_width(), get_sample_height());              if (preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("use_mean", true) == true) {                 colouroutput.add_colour_to_output(                         colourtools.get_mean(                                 pixels, get_sample_width(), get_sample_height(),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("detect_secondary", true),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("detect_white", true),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("detect_brightness", true),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getint("quantization_secondary", 32),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getint("quantization_dark", 43),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getint("quantization_light", 128),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("quantization_matching_only", true)                         ),                         colouroutput.colourtype.mean);             }             if (preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("use_mode", true) == true) {                 colouroutput.add_colour_to_output(                         colourtools.get_mode(                                 pixels, get_sample_width(), get_sample_height(),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("detect_secondary", true),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("detect_white", true),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("detect_brightness", true),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getint("quantization_secondary", 32),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getint("quantization_dark", 43),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getint("quantization_light", 128),                                 preferencemanager.getdefaultsharedpreferences(getapplicationcontext()).getboolean("quantization_matching_only", true)                         ),                         colouroutput.colourtype.mode);             }             colouroutput.do_output((activity) com.(name-removed).(app-name-removed).colouractivity);         }     }; 

here definition of "colouroutput.do_output":

public class colouroutput {     private static boolean output_clear = true;     private static string output_buffer = "";      public static enum colourtype {         mean,         mode     }      public static void add_colour_to_output(colourtools.colourdescription colour, colourtype type) {         if (output_clear == true) {             output_buffer = colour.brightness.tostring() + " " + colour.colour.tostring();         }         else {             output_buffer = output_buffer + " " + colour.brightness.tostring() + " " + colour.colour.tostring();         }         output_clear = false;     }      public static void do_output(activity activity) {         ((textview) activity.findviewbyid(r.id.output_text)).settext(output_buffer);         output_buffer = "";         output_clear = true;     } } 

the error message should self-explanatory: ...colouractivity class name , class name not valid expression in java. not android problem, simple syntax error.

do_output() expects instance of activity. i'm not quite sure, trying achieve trying pass name of activity class.

i'd assume, --since calling do_output() inside activity-- might want try

colouroutput.do_output(coloractivity.this); 

instead.

as suggested @priya singhal, explicit reference coloractivity.this necessary calling method within inner class , this refers instance of inner class.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -