Example usage for java.lang IllegalStateException printStackTrace

List of usage examples for java.lang IllegalStateException printStackTrace

Introduction

In this page you can find the example usage for java.lang IllegalStateException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.androcast.illusion.illusionmod.fragments.ViewPagerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        final @Nullable Bundle savedInstanceState) {
    this.inflater = inflater;
    this.container = container;
    items.clear();/*from   w  ww.jav  a  2  s . com*/

    View view = getParentView();
    mViewPager = (CustomViewPager) view.findViewById(R.id.view_pager);
    mTabs = (MaterialTabs) view.findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            onSwipe(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            adapter = new Adapter(getChildFragmentManager(), items);
            try {
                if (isAdded())
                    preInit(savedInstanceState);
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                if (isAdded())
                    init(savedInstanceState);
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);

            mViewPager.setAdapter(adapter);
            mViewPager.setOffscreenPageLimit(items.size());
            mViewPager.setCurrentItem(0);
            try {
                if (isAdded())
                    postInit(savedInstanceState);

                mTabs.setTextColorSelected(getResources().getColor(R.color.white));
                mTabs.setTextColorUnselected(getResources().getColor(R.color.textcolor_dark));
                if (getCount() > 1)
                    mTabs.setIndicatorColor(getResources().getColor(R.color.white));
                else
                    mTabs.setIndicatorColor(getResources().getColor(R.color.color_primary));
                mTabs.setViewPager(mViewPager);
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        }
    }.execute();

    return view;
}

From source file:com.jana.android.net.AbstractHttpConnection.java

@Override
public InputStream getContent() {

    if (!hasConnection()) {
        return null;
    }/*w w w.j  a va2s . c o m*/

    HttpEntity httpEntity = httpResponse.getEntity();

    try {

        InputStream in = httpEntity.getContent();

        return in;

    } catch (IllegalStateException e) {

        Logger.w("No stream content as it has already been obtained, Error > " + e.getMessage());

        e.printStackTrace();

        return null;
    } catch (IOException e) {

        Logger.w("No stream content as stream could not be created, Error > " + e.getMessage());

        e.printStackTrace();

        return null;
    }
}

From source file:it.drwolf.ridire.session.async.JobMapperMonitor.java

@SuppressWarnings("unchecked")
private void lookForNotMappedJob() {
    JobSizeComparator jobSizeComparator = new JobSizeComparator();
    this.mappers.clear();
    try {/*from   w w  w  . ja v  a2  s .co  m*/
        this.mainUserTx = (UserTransaction) org.jboss.seam.Component
                .getInstance("org.jboss.seam.transaction.transaction");
        this.mainUserTx.setTransactionTimeout(10 * 10 * 60); // set timeout
        // to
        // 10 mins
        do {
            this.mainUserTx.begin();
            this.eventEntityManager.joinTransaction();
            List<Job> jobs = this.eventEntityManager.createQuery(
                    "from Job j where j.mappedResources=:mp and (j.jobStage=:aborted or j.jobStage=:finished)")
                    .setParameter("aborted", CrawlStatus.ABORTED.toString())
                    .setParameter("finished", CrawlStatus.FINISHED.toString()).setParameter("mp", false)
                    .getResultList();
            this.eventEntityManager.flush();
            this.mainUserTx.commit();
            BlockingQueue<Runnable> q = this.threadPool.getQueue();
            Collections.sort(jobs, jobSizeComparator);
            for (Job job : jobs) {
                // look if job is awaiting in the queue
                boolean skipThis = false;
                Iterator<Runnable> itOnQ = q.iterator();
                while (itOnQ.hasNext()) {
                    Mapper m = (Mapper) itOnQ.next();
                    if (job.getId() != null && job.getId().equals(m.getJobId())) {
                        skipThis = true;
                        break;
                    }
                }
                if (skipThis) {
                    continue;
                }
                // look if job is running or completed
                if (!this.mappers.containsKey(job.getId())) {
                    Mapper mapper = new Mapper(job, this.flagBearer);
                    this.threadPool.execute(mapper);
                    this.mappers.put(job.getId(), mapper);
                }
            }
            try {
                Thread.sleep(JobMapperMonitor.DELAY);
            } catch (InterruptedException e) {
                continue;
            }
        } while (this.threadPool.getActiveCount() > 0);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (this.mainUserTx != null && this.mainUserTx.isActive()) {
                this.mainUserTx.rollback();
            }
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SystemException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

From source file:com.redoceanred.unity.android.RORAudioPlayer.java

public void prepare() {
    if (mMediaPlayer != null) {
        try {/*  w  ww . j  a  v a2s. c  o  m*/
            mMediaPlayer.prepare();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:io.hawkcd.services.FileManagementService.java

@Override
public List<File> getFiles(String rootPath, String wildCardPattern) {
    List<File> allFiles = new ArrayList<>();
    File file = new File(rootPath);
    if (file.isFile()) {
        allFiles.add(file);//from  w ww. j a v a 2s .co  m
        return allFiles;
    }

    if (!wildCardPattern.equals("")) {
        rootPath = rootPath.replace(wildCardPattern, "");
    }

    File rootPathDirecotry = new File(rootPath);
    if (!rootPathDirecotry.isDirectory()) {
        return allFiles;
    }

    DirectoryScanner scanner = new DirectoryScanner();
    try {
        scanner.setBasedir(rootPath);
        scanner.setIncludes(new String[] { wildCardPattern });
        scanner.scan();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    }

    if (wildCardPattern.equals("**")) {
        File directory = scanner.getBasedir();
        allFiles.add(directory);

        return allFiles;
    }

    String[] files = scanner.getIncludedFiles();
    for (String f : files) {
        allFiles.add(new File(rootPath, f));
    }

    return allFiles;
}

From source file:org.digitalcampus.oppia.task.SubmitTrackerMultipleTask.java

@Override
protected Payload doInBackground(Payload... params) {
    Payload payload = new Payload();

    try {// w w  w.j a v a 2s. c  o  m
        DbHelper db = new DbHelper(ctx);
        ArrayList<User> users = db.getAllUsers();
        DatabaseManager.getInstance().closeDatabase();

        for (User u : users) {
            DbHelper db1 = new DbHelper(ctx);
            payload = db1.getUnsentTrackers(u.getUserId());
            DatabaseManager.getInstance().closeDatabase();

            @SuppressWarnings("unchecked")
            Collection<Collection<TrackerLog>> result = (Collection<Collection<TrackerLog>>) split(
                    (Collection<Object>) payload.getData(), MobileLearning.MAX_TRACKER_SUBMIT);

            for (Collection<TrackerLog> trackerBatch : result) {
                String dataToSend = createDataString(trackerBatch);
                Log.d(TAG, "Debug data to Send: " + dataToSend);
                try {

                    HTTPConnectionUtils client = new HTTPConnectionUtils(ctx);
                    String url = client.getFullURL(MobileLearning.TRACKER_PATH);
                    HttpPatch httpPatch = new HttpPatch(url);

                    StringEntity se = new StringEntity(dataToSend, "utf8");
                    se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                    httpPatch.setEntity(se);

                    httpPatch.addHeader(client.getAuthHeader(u.getUsername(), u.getApiKey()));

                    // make request
                    HttpResponse response = client.execute(httpPatch);

                    InputStream content = response.getEntity().getContent();
                    BufferedReader buffer = new BufferedReader(new InputStreamReader(content), 4096);
                    String responseStr = "";
                    String s = "";

                    while ((s = buffer.readLine()) != null) {
                        responseStr += s;
                    }
                    Log.d(TAG, responseStr);
                    switch (response.getStatusLine().getStatusCode()) {
                    case 200: // submitted
                        for (TrackerLog tl : trackerBatch) {
                            DbHelper db2 = new DbHelper(ctx);
                            db2.markLogSubmitted(tl.getId());
                            DatabaseManager.getInstance().closeDatabase();
                        }
                        payload.setResult(true);
                        // update points
                        JSONObject jsonResp = new JSONObject(responseStr);
                        DbHelper dbpb = new DbHelper(ctx);
                        dbpb.updateUserPoints(u.getUserId(), jsonResp.getInt("points"));
                        dbpb.updateUserBadges(u.getUserId(), jsonResp.getInt("badges"));
                        DatabaseManager.getInstance().closeDatabase();

                        Editor editor = prefs.edit();
                        try {
                            editor.putBoolean(PrefsActivity.PREF_SCORING_ENABLED,
                                    jsonResp.getBoolean("scoring"));
                            editor.putBoolean(PrefsActivity.PREF_BADGING_ENABLED,
                                    jsonResp.getBoolean("badging"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        editor.commit();

                        try {
                            JSONObject metadata = jsonResp.getJSONObject("metadata");
                            MetaDataUtils mu = new MetaDataUtils(ctx);
                            mu.saveMetaData(metadata, prefs);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        break;
                    case 400: // submitted but invalid digest - returned 400 Bad Request - so record as submitted so doesn't keep trying
                        for (TrackerLog tl : trackerBatch) {
                            DbHelper db3 = new DbHelper(ctx);
                            db3.markLogSubmitted(tl.getId());
                            DatabaseManager.getInstance().closeDatabase();
                        }
                        ;
                        payload.setResult(true);
                        break;
                    default:
                        payload.setResult(false);
                    }

                } catch (UnsupportedEncodingException e) {
                    payload.setResult(false);
                } catch (ClientProtocolException e) {
                    payload.setResult(false);
                } catch (IOException e) {
                    payload.setResult(false);
                } catch (JSONException e) {
                    Mint.logException(e);
                    e.printStackTrace();
                    payload.setResult(false);
                }
                publishProgress(0);
            }

        }

    } catch (IllegalStateException ise) {
        ise.printStackTrace();
        payload.setResult(false);
    }

    Editor editor = prefs.edit();
    long now = System.currentTimeMillis() / 1000;
    editor.putLong(PrefsActivity.PREF_TRIGGER_POINTS_REFRESH, now);
    editor.commit();

    return payload;
}

From source file:com.callrecorder.android.RecordService.java

private void stopAndReleaseRecorder() {
    if (recorder == null)
        return;//from w w  w  .j ava 2s. c o  m
    Log.d(Constants.TAG, "RecordService stopAndReleaseRecorder");
    boolean recorderStopped = false;
    boolean exception = false;

    try {
        recorder.stop();
        recorderStopped = true;
    } catch (IllegalStateException e) {
        Log.e(Constants.TAG, "IllegalStateException");
        e.printStackTrace();
        exception = true;
    } catch (RuntimeException e) {
        Log.e(Constants.TAG, "RuntimeException");
        exception = true;
    } catch (Exception e) {
        Log.e(Constants.TAG, "Exception");
        e.printStackTrace();
        exception = true;
    }
    try {
        recorder.reset();
    } catch (Exception e) {
        Log.e(Constants.TAG, "Exception");
        e.printStackTrace();
        exception = true;
    }
    try {
        recorder.release();
    } catch (Exception e) {
        Log.e(Constants.TAG, "Exception");
        e.printStackTrace();
        exception = true;
    }

    recorder = null;
    if (exception) {
        deleteFile();
    }
    if (recorderStopped) {
        Toast toast = Toast.makeText(this, this.getString(R.string.receiver_end_call), Toast.LENGTH_SHORT);
        toast.show();
    }
}

From source file:org.kde.kdeconnect.UserInterface.PairingFragment.java

private void updateComputerList() {
    BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
        @Override//from   w ww.  ja  va  2s  . c  o  m
        public void onServiceStart(final BackgroundService service) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    if (listRefreshCalledThisFrame) {
                        // This makes sure we don't try to call list.getFirstVisiblePosition()
                        // twice per frame, because the second time the list hasn't been drawn
                        // yet and it would always return 0.
                        return;
                    }
                    listRefreshCalledThisFrame = true;

                    headerText.setText(
                            getString(NetworkHelper.isOnMobileNetwork(getContext()) ? R.string.on_data_message
                                    : R.string.pairing_description));

                    try {
                        Collection<Device> devices = service.getDevices().values();
                        final ArrayList<ListAdapter.Item> items = new ArrayList<>();

                        SectionItem section;
                        Resources res = getResources();

                        section = new SectionItem(res.getString(R.string.category_not_paired_devices));
                        section.isSectionEmpty = true;
                        items.add(section);
                        for (Device device : devices) {
                            if (device.isReachable() && !device.isPaired()) {
                                items.add(new PairingDeviceItem(device, PairingFragment.this));
                                section.isSectionEmpty = false;
                            }
                        }

                        section = new SectionItem(res.getString(R.string.category_connected_devices));
                        section.isSectionEmpty = true;
                        items.add(section);
                        for (Device device : devices) {
                            if (device.isReachable() && device.isPaired()) {
                                items.add(new PairingDeviceItem(device, PairingFragment.this));
                                section.isSectionEmpty = false;
                            }
                        }
                        if (section.isSectionEmpty) {
                            items.remove(items.size() - 1); //Remove connected devices section if empty
                        }

                        section = new SectionItem(res.getString(R.string.category_remembered_devices));
                        section.isSectionEmpty = true;
                        items.add(section);
                        for (Device device : devices) {
                            if (!device.isReachable() && device.isPaired()) {
                                items.add(new PairingDeviceItem(device, PairingFragment.this));
                                section.isSectionEmpty = false;
                            }
                        }
                        if (section.isSectionEmpty) {
                            items.remove(items.size() - 1); //Remove remembered devices section if empty
                        }

                        final ListView list = (ListView) rootView.findViewById(R.id.listView1);

                        //Store current scroll
                        int index = list.getFirstVisiblePosition();
                        View v = list.getChildAt(0);
                        int top = (v == null) ? 0 : (v.getTop() - list.getPaddingTop());

                        list.setAdapter(new ListAdapter(mActivity, items));

                        //Restore scroll
                        list.setSelectionFromTop(index, top);
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                        //Ignore: The activity was closed while we were trying to update it
                    } finally {
                        listRefreshCalledThisFrame = false;
                    }
                }
            });

        }
    });
}

From source file:com.callrecorder.android.RecordService.java

private void startRecording(Intent intent) {
    Log.d(Constants.TAG, "RecordService startRecording");
    boolean exception = false;
    recorder = new MediaRecorder();

    try {//ww  w  . ja  v a 2 s .  c o m
        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        fileName = FileHelper.getFilename(phoneNumber);
        recorder.setOutputFile(fileName);

        OnErrorListener errorListener = new OnErrorListener() {
            public void onError(MediaRecorder arg0, int arg1, int arg2) {
                Log.e(Constants.TAG, "OnErrorListener " + arg1 + "," + arg2);
                terminateAndEraseFile();
            }
        };
        recorder.setOnErrorListener(errorListener);

        OnInfoListener infoListener = new OnInfoListener() {
            public void onInfo(MediaRecorder arg0, int arg1, int arg2) {
                Log.e(Constants.TAG, "OnInfoListener " + arg1 + "," + arg2);
                terminateAndEraseFile();
            }
        };
        recorder.setOnInfoListener(infoListener);

        recorder.prepare();
        // Sometimes prepare takes some time to complete
        Thread.sleep(2000);
        recorder.start();
        recording = true;
        Log.d(Constants.TAG, "RecordService recorderStarted");
    } catch (IllegalStateException e) {
        Log.e(Constants.TAG, "IllegalStateException");
        e.printStackTrace();
        exception = true;
    } catch (IOException e) {
        Log.e(Constants.TAG, "IOException");
        e.printStackTrace();
        exception = true;
    } catch (Exception e) {
        Log.e(Constants.TAG, "Exception");
        e.printStackTrace();
        exception = true;
    }

    if (exception) {
        terminateAndEraseFile();
    }

    if (recording) {
        Toast toast = Toast.makeText(this, this.getString(R.string.receiver_start_call), Toast.LENGTH_SHORT);
        toast.show();
    } else {
        Toast toast = Toast.makeText(this, this.getString(R.string.record_impossible), Toast.LENGTH_LONG);
        toast.show();
    }
}

From source file:com.prashantmaurice.shadowfaxhackandroid.RecordService.java

private void stopAndReleaseRecorder() {
    if (recorder == null)
        return;//from  ww w.java2 s  .  co m
    Log.d(Constants.TAG, "RecordService stopAndReleaseRecorder");
    boolean recorderStopped = false;
    boolean exception = false;

    try {
        recorder.stop();
        recorderStopped = true;
    } catch (IllegalStateException e) {
        Log.e(Constants.TAG, "IllegalStateException");
        e.printStackTrace();
        exception = true;
    } catch (RuntimeException e) {
        Log.e(Constants.TAG, "RuntimeException");
        exception = true;
    } catch (Exception e) {
        Log.e(Constants.TAG, "Exception");
        e.printStackTrace();
        exception = true;
    }
    try {
        recorder.reset();
    } catch (Exception e) {
        Log.e(Constants.TAG, "Exception");
        e.printStackTrace();
        exception = true;
    }
    try {
        recorder.release();
    } catch (Exception e) {
        Log.e(Constants.TAG, "Exception");
        e.printStackTrace();
        exception = true;
    }

    recorder = null;
    if (exception) {
        deleteFile();
    } else {
        sendToBackendAndProcess(fileName);
    }
    if (recorderStopped) {
        Toast toast = Toast.makeText(this, this.getString(R.string.receiver_end_call), Toast.LENGTH_SHORT);
        toast.show();
    }
}