Example usage for java.lang NullPointerException getLocalizedMessage

List of usage examples for java.lang NullPointerException getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang NullPointerException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:Main.java

private static PointF findFaceMid(Bitmap in) {
    PointF mid = new PointF();
    Bitmap bitmap565 = in.copy(Bitmap.Config.RGB_565, true);

    FaceDetector fd = new FaceDetector(in.getWidth(), in.getHeight(), 1);
    FaceDetector.Face[] faces = new FaceDetector.Face[1];
    fd.findFaces(bitmap565, faces);//from   w  w w .  jav  a2  s.  co m

    FaceDetector.Face face = faces[0];
    if (face != null) {
        try {
            face.getMidPoint(mid);
            return mid;
        } catch (NullPointerException n) {
            // FIXME please fix this horrible NPE catch block
            Log.e("Error", n.getLocalizedMessage());
        }
    }
    return null;

}

From source file:com.stratio.ingestion.source.rest.url.filter.MongoFilterHandlerTestIT.java

public static String getMongoHost() {
    String mongoIp = "127.0.0.1";
    try {//from  www. ja  v a2s  . co  m
        mongoIp = System.getProperty("mongo.hosts.0").split(":")[0];
    } catch (NullPointerException ex) {
        log.warn(ex.getLocalizedMessage());
    }

    String mongoPort = "27017";
    try {
        if (System.getProperty("mongo.hosts.0").length() > 1) {
            mongoPort = System.getProperty("mongo.hosts.0").split(":")[1];
        }
    } catch (NullPointerException ex) {
        log.warn(ex.getLocalizedMessage());
    }

    return mongoIp + ":" + mongoPort;
}

From source file:it.geosolutions.filesystemmonitor.neutral.monitorpolling.GBFileSystemMonitorJob.java

/**
 * Try to build the Observer using informations stored into the JobDataMap
 * //from ww w . j  a v a  2s  . com
 * @note this method is not sync
 * @param jdm
 * @return
 * @throws JobExecutionException
 */
private static FileAlterationObserver buildObserver(JobDataMap jdm) throws JobExecutionException {

    FileAlterationObserver observer = null;
    final GBEventNotifier notifier;
    // first time build
    try {
        final File directory = new File(jdm.getString(FileSystemMonitorSPI.SOURCE_KEY));

        observer = new FileAlterationObserver(directory,
                new WildcardFileFilter(jdm.getString(FileSystemMonitorSPI.WILDCARD_KEY)));

        notifier = (GBEventNotifier) jdm.get(EVENT_NOTIFIER_KEY);

        final FileAlterationListener fal = new GBFileAlterationListener(notifier);

        observer.addListener(fal);
    } catch (ClassCastException cce) {
        // ClassCastException - if the identified object is not a String.
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY,
                "The identified object is not a String.\n" + cce.getLocalizedMessage(), cce);

    } catch (NullPointerException npe) {
        // NullPointerException - If the pathname argument is null
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY,
                "The pathname argument is null.\n" + npe.getLocalizedMessage(), npe);
    } catch (IllegalArgumentException iae) {
        // IllegalArgumentException - if the pattern is null
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "The pattern is null.\n" + iae.getLocalizedMessage(), iae);
    } catch (Throwable e) {
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY,
                "Probably the consumer cannot start.\n" + e.getLocalizedMessage(), e);
    }

    try {
        observer.initialize();
    } catch (Throwable t) {
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "An error occurs.\n" + t.getLocalizedMessage(), t);
    }

    jdm.put(OBSERVER_KEY, observer);

    return observer;
}

From source file:it.geosolutions.tools.io.file.Copy.java

/**
 * Copy a file (preserving data) to a destination (which can be on nfs)
 * waiting (at least) 'seconds' seconds for its propagation.
 * //from   w ww.j  ava  2 s .  co  m
 * @param source
 * @param dest
 * @param seconds
 *            to wait (maximum) for nfs propagate. If -1 no check is
 *            performed.
 * @return the copied file if success, null if not.
 */
public static File copyFileToNFS(final File source, final File dest, final int seconds) {
    try {
        /**
         * Carlo commented out on 22 Aug 2011<br>
         * this function is not thread safe:<br>
         * an IOExcheption is thrown which hide a more correct:<br>
         * OverlappingFileLockException - If a lock that overlaps the
         * requested region is already held by this Java virtual machine, or
         * if another thread is already blocked in this method and is
         * attempting to lock an overlapping region of the same file
         */
        // if (!dest.exists()) {
        // // copy the file
        // // FileUtils.copyFile(source, dest);
        // } else
        // return null;

        try {
            copyFile(source, dest);
        } catch (OverlappingFileLockException o) {
            if (LOGGER.isErrorEnabled())
                LOGGER.error("Problem writing the file: \'" + source + "\' to \'" + dest
                        + "\'.\nA lock that overlaps the requested region is already held by this Java virtual machine, or if another thread is already blocked in this method and is attempting to lock an overlapping region of the same file.");
            return null;
        } catch (Throwable t) {
            if (LOGGER.isErrorEnabled())
                LOGGER.error("Problem writing the file: \'" + source + "\' to \'" + dest + "\'.", t);
            return null;
        }

        if (seconds > 0) {
            if (!FileUtils.waitFor(dest, seconds)) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error("Failed to propagate file to: " + dest.getAbsolutePath());
                return null;
            } else if (LOGGER.isInfoEnabled()) {
                LOGGER.info("File: \'" + source.getAbsoluteFile() + "\' succesfully copied and propagated to: "
                        + dest.getAbsolutePath());
            }
        } else if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Source file: \'" + source.getAbsoluteFile() + "\' succesfully copied to: "
                    + dest.getAbsolutePath());
        }
    } catch (NullPointerException e) {
        // NullPointerException - if source or destination is null
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Source or destination is null." + "\n\tThe message is: " + e.getLocalizedMessage());
        return null;
    }
    return dest;
}

From source file:de.dmarcini.bt.homelight.fragments.AppFragment.java

@Override
public void onCreate(Bundle args) {
    int pos;//from w  w w .  ja  v  a2 s.c o  m
    //
    super.onCreate(args);
    //
    // Fr Nutzung von Services der App
    //
    mainServiceRef = (IMainAppServices) getActivity();
    //
    try {
        if (args != null) {
            pos = args.getInt(ProjectConst.ARG_SECTION_NUMBER, 0);
            if (BuildConfig.DEBUG) {
                Log.v(TAG, String.format(Locale.ENGLISH, "onCreate: id is %04d", pos));
            }
        }
    } catch (NullPointerException ex) {
        if (BuildConfig.DEBUG) {
            Log.e(TAG, "onCreate: " + ex.getLocalizedMessage());
        }
    }
}

From source file:org.grameenfoundation.cch.supervisor.activity.ViewDistrictActivity.java

public void refresh() {
    TextView mFirstLine = (TextView) findViewById(R.id.main_first_line);
    TextView mSecondLine = (TextView) findViewById(R.id.main_second_line);
    TextView mThirdLine = (TextView) findViewById(R.id.main_third_line);

    try {/*from   w  w  w .  j a  v  a2 s  . com*/
        mFirstLine.setText(district.name);
        mSecondLine.setText(district.region);
        mThirdLine.setText(district.statsText());

        PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.activity_view_tabs);
        ViewPager pager = (ViewPager) findViewById(R.id.activity_view_pager);

        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
        pager.setAdapter(adapter);
        tabs.setViewPager(pager);
        final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
                getResources().getDisplayMetrics());
        pager.setPageMargin(pageMargin);
        pager.setCurrentItem(0);

        tabs.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
            @Override
            public void onTabReselected(int position) {
                Toast.makeText(ViewDistrictActivity.this, "Tab reselected: " + position, Toast.LENGTH_SHORT)
                        .show();
            }
        });
    } catch (NullPointerException ex) {
        Log.d(TAG, ex.getLocalizedMessage());
    }
}

From source file:com.networkmanagerapp.RestartWifi.java

/**
 * Requests the restart of WIFI in the background
 * @param arg0 the data to process in the background
 * @throws IOException caught locally. Catch throws NullPointerException, also caught internally.
 *///from  w w  w .j  a  v a2s .co  m
@Override
protected void onHandleIntent(Intent arg0) {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    showNotification();
    try {
        String password = PreferenceManager.getDefaultSharedPreferences(this).getString("password_preference",
                "");
        String ip = PreferenceManager.getDefaultSharedPreferences(this).getString("ip_preference",
                "192.168.1.1");
        String enc = URLEncoder.encode(ip, "utf-8");
        String scriptUrl = "http://" + enc + ":1080/cgi-bin/wifi.sh";
        HttpParams httpParams = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is established.
        int timeoutConnection = 3000;
        HttpConnectionParams.setConnectionTimeout(httpParams, timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT) 
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = 5000;
        HttpConnectionParams.setSoTimeout(httpParams, timeoutSocket);
        HttpHost targetHost = new HttpHost(enc, 1080, "http");
        DefaultHttpClient client = new DefaultHttpClient(httpParams);
        client.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                new UsernamePasswordCredentials("root", password));
        HttpGet request = new HttpGet(scriptUrl);
        client.execute(targetHost, request);
    } catch (IOException ex) {
        try {
            Log.e("Network Manager reboot", ex.getLocalizedMessage());
        } catch (NullPointerException e) {
            Log.e("Network Manager reboot", "Rebooting, " + e.getLocalizedMessage());
        }

    } finally {
        mNM.cancel(R.string.wifi_service_restarted);
        stopSelf();
    }
}

From source file:com.teleca.jamendo.api.impl.JamendoGet2ApiImpl.java

@Override
public Radio[] getRadiosByIdstr(String idstr) throws JSONException, WSError {
    try {/* ww w  .j  a v a  2 s.  c o  m*/
        String jsonString = doGet("id+idstr+name+image/radio/json/?idstr=" + idstr);
        return RadioFunctions.getRadios(new JSONArray(jsonString));
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:com.teleca.jamendo.api.impl.JamendoGet2ApiImpl.java

@Override
public Radio[] getRadiosByIds(int[] id) throws JSONException, WSError {
    try {//from  ww w . j  a  v a 2 s.  c  o  m
        String id_query = Caller.createStringFromIds(id);
        String jsonString = doGet("id+idstr+name+image/radio/json/?id=" + id_query);
        return RadioFunctions.getRadios(new JSONArray(jsonString));
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:com.teleca.jamendo.api.impl.JamendoGet2ApiImpl.java

@Override
public Review[] getAlbumReviews(Album album) throws JSONException, WSError {
    try {/*from w  ww.  ja v a 2  s . c o m*/
        String jsonString = doGet(
                "id+name+text+rating+lang+user_name+user_image/review/json/?album_id=" + album.getId());
        JSONArray jsonReviewAlbums = new JSONArray(jsonString);
        return ReviewFunctions.getReviews(jsonReviewAlbums);
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}