android - cannot resolve symbol "LoadPreferences" , "nSharedPreferenceListener" -


this main activity,actually trying display settings option pressing icon on action bar , settings option invokes preference options(the default values) . getting errors . there red marks on "loadpreferences" , "nsharedpreferencelistener"

import android.content.intent; import android.content.sharedpreferences; import android.content.pm.packagemanager; import android.os.asynctask; import android.os.bundle; import android.os.powermanager; import android.preference.preferencemanager; import android.support.v7.app.appcompatactivity; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.view.surfaceholder; import android.view.surfaceview; import android.widget.textview;  import org.apache.http.conn.util.inetaddressutils;  import java.net.inetaddress; import java.net.networkinterface; import java.util.enumeration;  public class launcheractivity_streamcameraactivity extends appcompatactivity         implements surfaceholder.callback {  private surfaceholder npreviewdisplay = null;       private static final string tag = launcheractivity_streamcameraactivity.class.getsimplename();      private static final string pref_camera = "camera";     private static final int pref_camera_def = 0;     private static final string pref_flash_light = "flash_light";     private static final boolean pref_flash_light_def = false;     private static final string pref_port = "port";     private static final int pref_port_def = 8080;     private static final string pref_jpeg_size = "size";     private static final string pref_jpeg_quality = "jpeg_quality";     private static final int pref_jpeg_quality_def = 40;     // preview sizes have @ least 1 element, safe     private static final int pref_preview_size_def = 0;      private static final string wake_lock_tag = "wicam";     private powermanager.wakelock nwakelock = null;     private boolean nrunning = false;     private sharedpreferences nprefs = null;     private boolean npreviewdisplaycreated = false;     private activity2_1camerastream ncamerastream = null;     private int ncameraindex = pref_camera_def;     private boolean nuseflashlight = pref_flash_light_def;     private int nport = pref_port_def;     private int njpegquality = pref_jpeg_quality_def;     private int npreviewsizeindex = pref_preview_size_def;      private menuitem nsettingsmenuitem = null;      private textview nipaddressview = null;     private string nipaddress = "";      public launcheractivity_streamcameraactivity() {super();}    // constructor()      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         android.support.v7.app.actionbar actionbar = getsupportactionbar();         new loadpreferences().execute();         npreviewdisplay = ((surfaceview) findviewbyid(r.id.camera)).getholder();         npreviewdisplay.settype(surfaceholder.surface_type_push_buffers);         npreviewdisplay.addcallback(this);         nipaddress = trygetipv4address();         nipaddressview = (textview) findviewbyid(r.id.ipaddress);         updatecacheandui();          final powermanager powermanager =                 (powermanager) getsystemservice(power_service);         nwakelock = powermanager.newwakelock(powermanager.screen_dim_wake_lock,                 wake_lock_tag);       }// oncreate(bundle      @override       protected void onresume()     {         super.onresume();         nrunning = true;         if (nprefs != null)         {             nprefs.registeronsharedpreferencechangelistener(                     nsharedpreferencelistener);         } // if         updatecacheandui();         trystartcamerastream();         nwakelock.acquire();     } // onresume()      @override     protected void onpause()     {         nwakelock.release();         super.onpause();         nrunning = false;         if (nprefs != null)         {             nprefs.unregisteronsharedpreferencechangelistener(                     nsharedpreferencelistener);         } // if         ensurecamerastreamstopped();     } // onpause()       @override     public void surfacechanged(final surfaceholder holder, final int format,                                final int width, final int height)     {         // ingored     } // surfacechanged(surfaceholder, int, int, int)      @override     public void surfacecreated(final surfaceholder holder)     {         npreviewdisplaycreated = true;         trystartcamerastream();     } // surfacecreated(surfaceholder)      @override     public void surfacedestroyed(final surfaceholder holder)     {         npreviewdisplaycreated = false;         ensurecamerastreamstopped();     } // surfacedestroyed(surfaceholder)      private void trystartcamerastream()     {         if (nrunning && npreviewdisplaycreated && nprefs != null)         {             ncamerastream = new activity2_1camerastream(ncameraindex, nuseflashlight, nport,                     npreviewsizeindex, njpegquality, npreviewdisplay);             ncamerastream.start();         } // if     } // trystartcamerastreamer()      private void ensurecamerastreamstopped()     {         if (ncamerastream != null)         {             ncamerastream.stop();             ncamerastream = null;         } // if     } // stopcamerastreamer()      @override     public boolean oncreateoptionsmenu(final menu menu)     {         super.oncreateoptionsmenu(menu);        /* nsettingsmenuitem = menu.add(r.string.settings);         nsettingsmenuitem.seticon(android.r.drawable.ic_menu_manage);         */         menuinflater menuinflater = getmenuinflater();         menuinflater.inflate(r.menu.main_menu, menu);         return true;     } // oncreateoptionsmenu(menu)      @override     public boolean onoptionsitemselected(final menuitem item)     {         /*if (item != nsettingsmenuitem)         {             return super.onoptionsitemselected(item);         } // if         */         switch(item.getitemid())         {         case r.id.settings:         startactivity(new intent(this, activity2_2preferenceactivityscreen.class));         return true;             default:                 return super.onoptionsitemselected(item);     } // onoptionsitemselected(menuitem)      private final class loadpreferences             extends asynctask<void, void, sharedpreferences>     {         private loadpreferences()         {             super();         } // constructor()          @override         protected sharedpreferences doinbackground(final void... noparams)         {             return preferencemanager.getdefaultsharedpreferences(                     launcheractivity_streamcameraactivity.this);         } // doinbackground()          @override         protected void onpostexecute(final sharedpreferences prefs)         {             launcheractivity_streamcameraactivity.this.nprefs = prefs;             prefs.registeronsharedpreferencechangelistener(                     nsharedpreferencelistener);             updatecacheandui();             trystartcamerastream();         } // onpostexecute(sharedpreferences)       } // class loadpreferences     private final sharedpreferences.onsharedpreferencechangelistener nsharedpreferencelistener =             new sharedpreferences.onsharedpreferencechangelistener()             {                 @override                 public void onsharedpreferencechanged(final sharedpreferences prefs,                                                       final string key)                 {                     updatecacheandui();                 } // on                sharedpreferencechanged(sharedpreferences, string)              }; // nsharedpreferenceslistener       private final int getprefint(final string key, final int defvalue)     {         // can't call getint because preference activity         // saves string.         try         {             return integer.parseint(nprefs.getstring(key, null /* defvalue */));         } // try         catch (final nullpointerexception e)         {             return defvalue;         } // catch         catch (final numberformatexception e)         {             return defvalue;         } // catch     } // getprefint(string, int)      private final void updatecacheandui()   //validation     {         ncameraindex = getprefint(pref_camera, pref_camera_def);         if (hasflashlight())         {             if (nprefs != null)             {                 nuseflashlight =nprefs.getboolean(pref_flash_light,                         pref_flash_light_def);             } // if             else             {                 nuseflashlight = pref_flash_light_def;             } // else         } //if         else         {             nuseflashlight = false;         } // else          // xxx: validation should in preferences activity.         nport = getprefint(pref_port, pref_port_def);         // port must in range [1024 65535]         if (nport < 1024)         {             nport = 1024;         } // if         else if (nport > 65535)         {             nport = 65535;         } // else if          npreviewsizeindex = getprefint(pref_jpeg_size, pref_preview_size_def);         njpegquality = getprefint(pref_jpeg_quality, pref_jpeg_quality_def);         // jpeg quality must in range [0 100]         if (njpegquality < 0)         {             njpegquality = 0;         } // if         else if (njpegquality > 100)         {             njpegquality = 100;         } // else if         nipaddressview.settext("http://" + nipaddress + ":" + nport + "/");     } // updatecacheandui()       private boolean hasflashlight()     {         return getpackagemanager().hassystemfeature(                 packagemanager.feature_camera_flash);     } // hasflashlight()      private static string trygetipv4address()     {         try         {             final enumeration<networkinterface> en =                     networkinterface.getnetworkinterfaces();             while (en.hasmoreelements())             {                 final networkinterface intf = en.nextelement();                 final enumeration<inetaddress> enumipaddr =                         intf.getinetaddresses();                 while (enumipaddr.hasmoreelements())                 {                     final  inetaddress inetaddress = enumipaddr.nextelement();                     if (!inetaddress.isloopbackaddress())                     {                         final string addr = inetaddress.gethostaddress().touppercase();                         if (inetaddressutils.isipv4address(addr))                         {                             return addr;                         }                     } // if                 } // while             } //         } // try         catch (final exception e)         {             // ignore         } // catch         return null;     } // trygetipv4address()  } 

it normal loadpreferences not found, constructor private.

why don't try remove the:

private loadpreferences() {      super(); }  

and why "final"???

private final class loadpreferences 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -