Example usage for java.lang InstantiationException printStackTrace

List of usage examples for java.lang InstantiationException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:net.evendanan.pushingpixels.FragmentChauffeurActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    mIsActivityShown = true;/*from  ww w  . j av  a 2  s.com*/
    if (savedInstanceState == null) {
        //setting up the root of the UI.
        setRootFragment(createRootFragmentInstance());
        //now, checking if there is a request to add a fragment on-top of this one.
        Bundle activityArgs = getIntent().getExtras();
        if (activityArgs != null && activityArgs.containsKey(KEY_FRAGMENT_CLASS_TO_ADD)) {
            Class<? extends Fragment> fragmentClass = (Class<? extends Fragment>) activityArgs
                    .get(KEY_FRAGMENT_CLASS_TO_ADD);
            //not sure that this is a best-practice, but I still need to remove this from the activity's args
            activityArgs.remove(KEY_FRAGMENT_CLASS_TO_ADD);
            try {
                Fragment fragment = fragmentClass.newInstance();
                if (activityArgs.containsKey(KEY_FRAGMENT_ARGS_TO_ADD)) {
                    fragment.setArguments(activityArgs.getBundle(KEY_FRAGMENT_ARGS_TO_ADD));
                    activityArgs.remove(KEY_FRAGMENT_CLASS_TO_ADD);
                }
                addFragmentToUi(fragment, FragmentUiContext.RootFragment);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:blue.orchestra.blueSynthBuilder.BSBCloneTest.java

public void testClone() {
    BSBObjectEntry[] bsbObjects = BSBObjectRegistry.getBSBObjects();

    for (int i = 0; i < bsbObjects.length; i++) {
        BSBObjectEntry entry = bsbObjects[i];

        Class class1 = entry.bsbObjectClass;

        BSBObject bsbObj = null;//w  w w  . j  a  v  a 2 s . c o m

        try {
            bsbObj = (BSBObject) class1.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        assertNotNull(bsbObj);

        if (bsbObj == null) {
            continue;
        }

        Object obj = ObjectUtilities.clone(bsbObj);
        assertNotNull(obj);

        boolean isEqual = EqualsBuilder.reflectionEquals(bsbObj, obj);

        if (!isEqual) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("Problem with class: ").append(class1.getName()).append("\n");
            buffer.append("Original Object\n");
            buffer.append(ToStringBuilder.reflectionToString(bsbObj)).append("\n");
            buffer.append("Cloned Object\n");
            buffer.append(ToStringBuilder.reflectionToString(obj)).append("\n");

            System.out.println(buffer.toString());

        }

        assertTrue(isEqual);

        Element elem1 = bsbObj.saveAsXML();

        Element elem2 = ((BSBObject) obj).saveAsXML();

        assertEquals(elem1.getTextString(), elem2.getTextString());
    }

}

From source file:org.dkpro.bigdata.io.hadoop.Text2CASInputFormat.java

@Override
public RecordReader<Text, CASWritable> getRecordReader(InputSplit split, JobConf jobConf, Reporter reporter)
        throws IOException {
    DocumentTextExtractor textConverter = null;
    String textConverterClass = jobConf.get("dkpro.uima.text2casinputformat.documenttextextractor");
    if (textConverterClass != null) {
        try {//from   w  w w  .  j  a  va  2 s.  c om
            textConverter = (DocumentTextExtractor) Class.forName(textConverterClass).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    DocumentMetadataExtractor metadataConverter = null;
    String metadataConverterClass = jobConf.get("dkpro.uima.text2casinputformat.documentmetadataextractor");
    if (metadataConverterClass != null) {
        try {
            metadataConverter = (DocumentMetadataExtractor) Class.forName(metadataConverterClass).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    return new Text2CASRecordReader((FileSplit) split, jobConf, reporter, textConverter, metadataConverter);
}

From source file:edu.umn.cs.spatialHadoop.mapred.IndexedRectangle.java

@SuppressWarnings("unchecked")
@Override//from   ww w  .  j  a va  2 s. co m
public InputSplit[] getSplits(final JobConf job, int numSplits) throws IOException {
    // Get a list of all input files. There should be exactly two files.
    final Path[] inputFiles = getInputPaths(job);
    GlobalIndex<Partition> gIndexes[] = new GlobalIndex[inputFiles.length];

    BlockFilter blockFilter = null;
    try {
        Class<? extends BlockFilter> blockFilterClass = job.getClass(SpatialSite.FilterClass, null,
                BlockFilter.class);
        if (blockFilterClass != null) {
            // Get all blocks the user wants to process
            blockFilter = blockFilterClass.newInstance();
            blockFilter.configure(job);
        }
    } catch (InstantiationException e1) {
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        e1.printStackTrace();
    }

    if (blockFilter != null) {
        // Extract global indexes from input files

        for (int i_file = 0; i_file < inputFiles.length; i_file++) {
            FileSystem fs = inputFiles[i_file].getFileSystem(job);
            gIndexes[i_file] = SpatialSite.getGlobalIndex(fs, inputFiles[i_file]);
        }
    }

    final Vector<CombineFileSplit> matchedSplits = new Vector<CombineFileSplit>();
    if (gIndexes[0] == null || gIndexes[1] == null) {
        // Join every possible pair (Cartesian product)
        InputSplit[][] inputSplits = new InputSplit[inputFiles.length][];

        for (int i_file = 0; i_file < inputFiles.length; i_file++) {
            JobConf temp = new JobConf(job);
            setInputPaths(temp, inputFiles[i_file]);
            inputSplits[i_file] = super.getSplits(temp, 1);
        }
        LOG.info("Doing a Cartesian product of blocks: " + inputSplits[0].length + "x" + inputSplits[1].length);
        for (InputSplit split1 : inputSplits[0]) {
            for (InputSplit split2 : inputSplits[1]) {
                CombineFileSplit combinedSplit = (CombineFileSplit) FileSplitUtil.combineFileSplits(job,
                        (FileSplit) split1, (FileSplit) split2);
                matchedSplits.add(combinedSplit);
            }
        }
    } else {
        // Filter block pairs by the BlockFilter
        blockFilter.selectCellPairs(gIndexes[0], gIndexes[1], new ResultCollector2<Partition, Partition>() {
            @Override
            public void collect(Partition p1, Partition p2) {
                try {
                    List<FileSplit> splits1 = new ArrayList<FileSplit>();
                    Path path1 = new Path(inputFiles[0], p1.filename);
                    splitFile(job, path1, splits1);

                    List<FileSplit> splits2 = new ArrayList<FileSplit>();
                    Path path2 = new Path(inputFiles[1], p2.filename);
                    splitFile(job, path2, splits2);

                    for (FileSplit split1 : splits1) {
                        for (FileSplit split2 : splits2) {
                            matchedSplits.add(
                                    (CombineFileSplit) FileSplitUtil.combineFileSplits(job, split1, split2));
                        }
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    LOG.info("Matched " + matchedSplits.size() + " combine splits");

    // Return all matched splits
    return matchedSplits.toArray(new InputSplit[matchedSplits.size()]);
}

From source file:br.com.frs.foodrestrictions.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from   w  w w  .  j  a  v a  2  s  .  co m
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    Fragment fragment = null;
    Class fragmentClass = null;

    switch (id) {
    case R.id.nav_icons:
        if (checkConfig()) {
            fragmentClass = FoodIconGrid.class;
        } else {
            fragmentClass = FoodIconConfig.class;
        }
        break;

    case R.id.nav_text:
        if (checkConfig()) {
            fragmentClass = FoodMessages.class;
        } else {
            fragmentClass = FoodIconConfig.class;
        }
        break;

    case R.id.nav_app_settings:
        fragmentClass = AppConfig.class;
        break;

    case R.id.nav_veg_vegan:
        fragmentClass = MessageLanguageSelector.class;
        break;

    case R.id.nav_food_settings:
        fragmentClass = FoodIconConfig.class;
        break;

    case R.id.nav_about_us:
        fragmentClass = AboutUs.class;
        break;
    }

    if (fragmentClass != null) {
        try {
            fragment = (Fragment) fragmentClass.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:br.com.frs.foodrestrictions.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   w  w  w .  j  av  a  2 s .  c o m*/

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    settingsApp = AppSettings.getSettingsApp(this);
    settingsFood = FoodIconSettings.getFoodIconSettings(this);
    foodIconList = new FoodIconList();

    if (showHelp) {
        if (settingsApp.isHelpDialog()) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getResources().getString(R.string.help_title));
            builder.setMessage(getResources().getString(R.string.help_message));
            builder.setPositiveButton(getResources().getString(R.string.help_not_show),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            settingsApp.setHelpDialog(false);
                            dialog.dismiss();
                        }
                    });

            builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            AlertDialog alert = builder.create();
            alert.show();
        }
        showHelp = false;
    }

    Fragment fragment = null;

    try {
        if (checkConfig()) {
            fragment = FoodIconGrid.class.newInstance();
        } else {
            fragment = FoodIconConfig.class.newInstance();
        }
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

}

From source file:blue.orchestra.blueSynthBuilder.BSBCloneTest.java

public void testLoadSave() {
    BSBObjectEntry[] bsbObjects = BSBObjectRegistry.getBSBObjects();

    for (int i = 0; i < bsbObjects.length; i++) {
        BSBObjectEntry entry = bsbObjects[i];

        Class class1 = entry.bsbObjectClass;

        BSBObject bsbObj = null;//from   w  ww . j a  va2 s  .  c o  m

        try {
            bsbObj = (BSBObject) class1.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        assertNotNull(bsbObj);

        if (bsbObj == null) {
            continue;
        }

        Element elem1 = bsbObj.saveAsXML();

        Method m = null;
        try {
            m = class1.getMethod("loadFromXML", new Class[] { Element.class });
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (NoSuchMethodException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        BSBObject bsbObj2 = null;

        assertNotNull(m);
        if (m == null) {
            continue;
        }

        try {
            bsbObj2 = (BSBObject) m.invoke(bsbObj, new Object[] { elem1 });
        } catch (IllegalArgumentException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } catch (IllegalAccessException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } catch (InvocationTargetException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }

        boolean isEqual = EqualsBuilder.reflectionEquals(bsbObj, bsbObj2);

        if (!isEqual) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("Problem with class: ").append(class1.getName()).append("\n");
            buffer.append("Original Object\n");
            buffer.append(ToStringBuilder.reflectionToString(bsbObj)).append("\n");
            buffer.append("Cloned Object\n");
            buffer.append(ToStringBuilder.reflectionToString(bsbObj2)).append("\n");

            System.out.println(buffer.toString());

        }

        assertTrue(isEqual);

    }

}

From source file:com.intel.hadoop.graphbuilder.preprocess.mapreduce.CreateGraphMR.java

/**
 * Set the intermediate key value class.
 * /*  w  w w  .  j  av  a 2 s  . c om*/
 * @param valClass
 */
public void setValueClass(Class valClass) {
    try {
        this.mapvaltype = (VertexEdgeUnionType) valClass.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.ricemap.spateDB.mapred.IndexedPrism.java

@SuppressWarnings("unchecked")
@Override/* ww w  .ja  v a 2 s.  c  o m*/
public InputSplit[] getSplits(final JobConf job, int numSplits) throws IOException {
    // Get a list of all input files. There should be exactly two files.
    final Path[] inputFiles = getInputPaths(job);
    GlobalIndex<Partition> gIndexes[] = new GlobalIndex[inputFiles.length];

    BlockFilter blockFilter = null;
    try {
        Class<? extends BlockFilter> blockFilterClass = job.getClass(SpatialSite.FilterClass, null,
                BlockFilter.class);
        if (blockFilterClass != null) {
            // Get all blocks the user wants to process
            blockFilter = blockFilterClass.newInstance();
            blockFilter.configure(job);
        }
    } catch (InstantiationException e1) {
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        e1.printStackTrace();
    }

    if (blockFilter != null) {
        // Extract global indexes from input files

        for (int i_file = 0; i_file < inputFiles.length; i_file++) {
            FileSystem fs = inputFiles[i_file].getFileSystem(job);
            gIndexes[i_file] = SpatialSite.getGlobalIndex(fs, inputFiles[i_file]);
        }
    }

    final Vector<CombineFileSplit> matchedSplits = new Vector<CombineFileSplit>();
    if (gIndexes[0] == null || gIndexes[1] == null) {
        // Join every possible pair (Cartesian product)
        BlockLocation[][] fileBlockLocations = new BlockLocation[inputFiles.length][];
        for (int i_file = 0; i_file < inputFiles.length; i_file++) {
            FileSystem fs = inputFiles[i_file].getFileSystem(job);
            FileStatus fileStatus = fs.getFileStatus(inputFiles[i_file]);
            fileBlockLocations[i_file] = fs.getFileBlockLocations(fileStatus, 0, fileStatus.getLen());
        }
        LOG.info("Doing a Cartesian product of blocks: " + fileBlockLocations[0].length + "x"
                + fileBlockLocations[1].length);
        for (BlockLocation block1 : fileBlockLocations[0]) {
            for (BlockLocation block2 : fileBlockLocations[1]) {
                FileSplit fsplit1 = new FileSplit(inputFiles[0], block1.getOffset(), block1.getLength(),
                        block1.getHosts());
                FileSplit fsplit2 = new FileSplit(inputFiles[1], block2.getOffset(), block2.getLength(),
                        block2.getHosts());
                CombineFileSplit combinedSplit = (CombineFileSplit) FileSplitUtil.combineFileSplits(job,
                        fsplit1, fsplit2);
                matchedSplits.add(combinedSplit);
            }
        }
    } else {
        // Filter block pairs by the BlockFilter
        blockFilter.selectCellPairs(gIndexes[0], gIndexes[1], new ResultCollector2<Partition, Partition>() {
            @Override
            public void collect(Partition p1, Partition p2) {
                try {
                    List<FileSplit> splits1 = new ArrayList<FileSplit>();
                    Path path1 = new Path(inputFiles[0], p1.filename);
                    splitFile(job, path1, splits1);

                    List<FileSplit> splits2 = new ArrayList<FileSplit>();
                    Path path2 = new Path(inputFiles[1], p2.filename);
                    splitFile(job, path2, splits2);

                    for (FileSplit split1 : splits1) {
                        for (FileSplit split2 : splits2) {
                            matchedSplits.add(
                                    (CombineFileSplit) FileSplitUtil.combineFileSplits(job, split1, split2));
                        }
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    LOG.info("Matched " + matchedSplits.size() + " combine splits");

    // Return all matched splits
    return matchedSplits.toArray(new InputSplit[matchedSplits.size()]);
}

From source file:com.intel.hadoop.graphbuilder.preprocess.mapreduce.CreateGraphMR.java

/**
 * Set user defined function for reduce duplicate vertex and edges.
 * //from   w ww.  j ava  2s.c o  m
 * @param vertexfunc
 * @param edgefunc
 */
public void setFunctionClass(Class vertexfunc, Class edgefunc) {
    try {
        if (vertexfunc != null)
            this.vertexfunc = (Functional) vertexfunc.newInstance();
        if (edgefunc != null)
            this.edgefunc = (Functional) edgefunc.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}