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:ar.edu.taco.simplejml.methodinfo.MethodInformationBuilder.java

public MethodInformation getMethodInformation(JMethodCallExpression jMethodCallExpression) {
    ConcreteMethodInformation concreteMethodInformation = null;

    if (jMethodCallExpression.method() != null) {
        concreteMethodInformation = new ConcreteMethodInformation();

        boolean isStatic = jMethodCallExpression.method().isStatic();
        boolean isModelMethod = (jMethodCallExpression.prefix() == null)
                && (jMethodCallExpression.method() == null);
        boolean isConstructor = jMethodCallExpression.method().isConstructor();

        concreteMethodInformation.setStatic(isStatic);
        concreteMethodInformation.setConstructor(isConstructor);
        concreteMethodInformation.setModelMethod(isModelMethod);
        if (jMethodCallExpression.getType() != null) {
            CType cType = jMethodCallExpression.getType();
            concreteMethodInformation.setReturnType(cType);
        }/*from w  w w  . ja  v  a  2 s.c  o  m*/

        JavaClassNameNormalizer classNameNormalizer = new JavaClassNameNormalizer(
                jMethodCallExpression.method().receiverType().toVerboseString());
        concreteMethodInformation.setQualifiedReceiverType(classNameNormalizer.getQualifiedClassName());

    } else if (jMethodCallExpression.prefix() instanceof JLocalVariableExpression
            || jMethodCallExpression.prefix() instanceof JNameExpression) {
        concreteMethodInformation = new ConcreteMethodInformation();

        concreteMethodInformation.setStatic(false);
        concreteMethodInformation.setConstructor(false);
        concreteMethodInformation.setModelMethod(true);
        if (jMethodCallExpression.getType() != null) {
            CType cType = jMethodCallExpression.getType();
            concreteMethodInformation.setReturnType(cType);
        } else {

            concreteMethodInformation.setReturnType(CStdType.Object);
        }

    } else {
        String className = getCapitalizedClassName(jMethodCallExpression.prefix().toString());
        try {
            String packageName = MethodInformationSupplier.class.getPackage().getName();
            MethodInformationSupplier methodInformationSupplier = (MethodInformationSupplier) Class
                    .forName(packageName + ".MI_" + className).newInstance();
            concreteMethodInformation = methodInformationSupplier
                    .getInformationForMethod(jMethodCallExpression.ident());
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    return concreteMethodInformation;
}

From source file:com.github.nicktgn.mvp.MvpFragment.java

/**
 * Use this helper method to get another View (Fragment)
 * with extras containing provided arguments indented for Presenter of this new View
 * @param arguments arguments from this View's Presenter intended for Presenter of another View
 * @return intent to another View (Activity) (or null if failed to instantiate)
 *//*from w  w  w . j ava 2  s  .c  o  m*/
protected <T extends MvpFragment> T getMvpFragment(Class<T> targetView, MvpBundle arguments) {
    try {
        T fragment = targetView.getConstructor().newInstance();
        Bundle bundle = new Bundle();
        bundle.putBundle(Constants.ARGUMENTS_DATA, arguments.getRealBundle());
        fragment.setArguments(bundle);
        return fragment;
    } catch (java.lang.InstantiationException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.tmendes.birthdaydroid.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   ww  w.  jav  a2  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);
    if (drawer != null) {
        drawer.addDrawerListener(toggle);
        toggle.syncState();
    }

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        navigationView.setNavigationItemSelectedListener(this);
    }

    birthdayAlarm = new BirthDayAlarm(this);

    this.birthdays = BirthDayDataList.getBirthDayDataList(this.getApplicationContext());

    Fragment fragment;
    try {
        fragment = ContactListFragment.class.newInstance();
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:net.morematerials.manager.HandlerManager.java

public void inject(Class<? extends GenericHandler> clazz) {
    String useName = clazz.getName().split("Handler")[0].split("net.morematerials.handlers.")[1];

    try {/*from  w w  w . j  a  v a 2 s  .co  m*/
        Object object = clazz.newInstance();
        GenericHandler handler = (GenericHandler) object;
        handler.init(this.plugin);
        this.handlers.put(useName, handler);
        this.plugin.getUtilsManager().log("Loaded Internal MM handler: " + useName);
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.nova.geracao.portfolio.BlogServlet.java

private Object getInstanceFromPropertiesMap(Entity entity, Class<?> klass) {
    Object result = null;/*w  w w  .j  ava2s  . co  m*/
    try {
        Field[] fields = klass.getDeclaredFields();
        result = klass.newInstance();
        for (int i = 0; i < fields.length; i++) {
            if (entity.hasProperty(fields[i].getName())) {
                fields[i].setAccessible(true);
                Object value = entity.getProperty(fields[i].getName());
                if (!ClassUtils.isAssignable(fields[i].getType(), BaseDataClass.class)) {
                    fields[i].set(result, value);
                } else {
                    Object embedValue = getInstanceFromPropertiesMap((EmbeddedEntity) value,
                            fields[i].getType());
                    fields[i].set(result, embedValue);
                }
            }
        }

        Field fieldId = klass.getDeclaredField("id");
        fieldId.setAccessible(true);
        fieldId.set(result, entity.getKey().getId());
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.nova.geracao.portfolio.BlogServlet.java

private Object getInstanceFromPropertiesMap(EmbeddedEntity entity, Class<?> klass) {
    Object result = null;/*from w  w w.  ja v  a  2s.  co  m*/
    try {
        Field[] fields = klass.getDeclaredFields();
        result = klass.newInstance();
        for (int i = 0; i < fields.length; i++) {
            if (entity.hasProperty(fields[i].getName())) {
                fields[i].setAccessible(true);
                Object value = entity.getProperty(fields[i].getName());
                if (!ClassUtils.isAssignable(fields[i].getType(), BaseDataClass.class)) {
                    fields[i].set(result, value);
                } else {
                    Object embedValue = getInstanceFromPropertiesMap((EmbeddedEntity) value,
                            fields[i].getType());
                    fields[i].set(result, embedValue);
                }
            }
        }

        Field fieldId = klass.getDeclaredField("id");
        fieldId.setAccessible(true);
        fieldId.set(result, entity.getKey().getId());
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.tmendes.birthdaydroid.MainActivity.java

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

    switch (id) {
    case R.id.nav_birthday_list:
        fragmentClass = ContactListFragment.class;
        break;
    case R.id.nav_statistics:
        fragmentClass = StatisticsFragment.class;
        break;
    case R.id.nav_scan_now:
        if (this.birthdays.isThereAnyBirthDayToday()) {
            Toast.makeText(this, getResources().getString(R.string.birthday_scan_found), Toast.LENGTH_LONG)
                    .show();
        } else {
            Toast.makeText(this, getResources().getString(R.string.birthday_scan_not_found), Toast.LENGTH_LONG)
                    .show();
        }
        break;
    case R.id.nav_settings:
        fragmentClass = SettingsFragment.class;
        break;
    case R.id.nav_about:
        fragmentClass = AboutUsFragment.class;
        break;
    }

    if (fragmentClass != null) {
        try {
            fragment = (Fragment) fragmentClass.newInstance();
            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

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

From source file:ejava.examples.ejbear6.dmv.client.ProtocolClient.java

/**
 * This method returns an action class that can carry out the provided
 * link if known.//from  w  w w.j  av  a 2s . com
 * @param link
 * @return action object if link is known -- otherwise null
 */
public Action createAction(Link link) {
    Action action = null;
    Class<? extends Action> clazz = actions.get(link.getRel());
    if (clazz != null) {
        try {
            action = clazz.newInstance();
            action.setHttpClient(httpClient);
            action.setLink(link);
        } catch (InstantiationException ex) {
            ex.printStackTrace();
            throw new RuntimeException("error instantiating action class", ex);
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }
    return action;
}

From source file:com.parse.simple.SimpleParseCache.java

public Object getObject(Class<?> klass) {
    Object object = objectsCache.get(klass);

    if (object == null) {
        try {//  w w  w  . j a  v  a  2 s. com
            object = (Object) klass.newInstance();
            objectsCache.put(klass, object);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    return object;
}

From source file:com.parse.simple.SimpleParseCache.java

public Filter getFilter(Class<? extends Filter> klass) {
    Filter filter = filtersCache.get(klass);

    if (filter == null) {
        try {/*from  w  w w . j  av  a  2s . c o m*/
            filter = (Filter) klass.newInstance();
            filtersCache.put(klass, filter);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    return filter;
}