Skip to main content

Posts

Showing posts with the label exception

When should I create a new Exception class

I notice that a number of Java exception classes differ only in the name of the class and do not add any new functionality. Most exceptions for example just seem to override Exception() or Exception(String message) . This goes against the tenets of inheritance ie:- inherit to add new functionality.

ArrayIndexOutOfBoundsException with custom Android Adapter for multiple views in ListView

I am attempting to create a custom Adapter for my ListView since each item in the list can have a different view (a link, toggle, or radio group), but when I try to run the Activity that uses the ListView I receive an error and the app stops. The application is targeted for the Android 1.6 platform. The code: public class MenuListAdapter extends BaseAdapter { private static final String LOG_KEY = MenuListAdapter.class.getSimpleName(); protected List<MenuItem> list; protected Context ctx; protected LayoutInflater inflater; public MenuListAdapter(Context context, List<MenuItem> objects) { this.list = objects; this.ctx = context; this.inflater = (LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i(LOG_KEY, "Position: " + position + "; convertView = " + convertView + "; parent=" + parent); MenuItem item = list.get(p

Why java people frequently consume exception silently?

I never did any serious Java coding before, but I learned the syntax, libraries, and concepts based on my existing skills (Delphi & C#). One thing I hardly understand is that I've seen soo much code that silently consume exceptions after "printStackTrace" like this: public void process() { try { System.out.println("test"); } catch(Exception e) { e.printStackTrace(); } } There is similar code like this one in almost every Java article & project I ran into. Based on my knowledge this is very bad. The exception should almost always be forwarded to the outer context like this: public void process() { try { System.out.println("test"); } catch(Exception e) { e.printStackTrace(); throw new AssertionError(e); } } Most of the time the exception should end up being handled at the outermost loop which belongs to the underlying framework (Jav

JAVA Exception in main thread java.lang.NoDefFounderror: net/&hellip;/AbstractClock

I have a clock program as AbstractClock.java in C:\Users\Neeraj\Prg folder . CLASSPATH is specified as C:\Users\Neeraj\Prg COMPILED javac AbstractClock.java with no errors. RUN AS java -cp . net.sf.fmj.ejmf.toolkit.media.AbstractClock Getting errors as Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/fmj/ejmf/toolkit/media/AbstractClock Caused by: java.lang.ClassNotFoundException: net/sf/fmj/ejmf/toolkit/media/AbstractClock at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:315) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) Could not find the main class: com.hib.TranslateSQL. Program will exit. PRO

MonoTouch - type load exception, updated program not registered in simulator

I've installed trial version of MonoTouch, and I'm evaluating it for use. This strange error has occurred: Could not load 'MyProductName' for registration. This could be due to an outdated assembly kept by the simulator, location: /PathToMyProduct Followed by: A type load exception has occurred. My guess is that, somehow some assembly is not up to date. So I've tried to remove it from the given path. But still it's there. So I performed a purge (reinstalled MonoTouch, removed binary build path, in simulator path, uninstalled from simulator, reset simulator, and finally restarted the OSX). But still it's there. Any hints on how to solve this peculiar problem? regards, Kate

Clarify what is asked for in java Exceptions assignment

It does not appear evident to me what is asked in a java assignment I have received. Does anyone understand what is needed: In the previous assignment, you implemented a stack and a list that both inherited from the abstract class ArrayIntCollection. In this task you are supposed to extend that implementation by make it throw exceptions if you try to perform operations that are not allowed (for example, if you try to call pop or peek on an empty stack or if you try to remove an element from a non existing position). You shall create and use the exception class CollectionException, of the type UncheckedException. Also write a test program ExceptionMain.java that generates and catches exceptions from your modified methods. The way I understand it, I need to create a exception class called CollectionException , and it needs to extend UncheckedException . (this itself is not working, as I cannot find a class called UncheckedException ). Also, it is obvious if I am to use t

Java applet AWT-EventQueue-1 Exception

I wrote a simple implementation of the Game of life with java applets. Here's is the source code for the Applet and the Model. When I click the button to get the next iteration these Exceptions get thrown. Z:\GameOfLife>appletviewer driver.html Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 65 at GameOfLifeApplet.mouseClicked(GameOfLifeApplet.java:63) at java.awt.Component.processMouseEvent(Component.java:6219) at java.awt.Component.processEvent(Component.java:5981) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4583) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4413) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre ad.java:269) at java.awt.E

Preventing Java from printing the stack trace on certain exceptions

I have a security class that throws an AccessDeniedException on a user not being authorized for a certain operation. I made it even neat and put a msg in there with the info I need. The problem is that now my logs are full of stack traces for every single time I throw. I don't care to see the stack trace for THIS exception, and the stack traces are bloating my logs. Is there a way to tell Java not to print the stack trace to the logs if it's this exception? Thanks! -- llappall

Android Exception trying to open a new Activity - Surface::lock failed, already locked

When I try to open a new activity on a button press i get an Exception : 01-19 14:55:08.327: E/Surface(15454): Surface::lock failed, already locked 01-19 14:55:08.327: E/SurfaceHolder(15454): Exception locking surface 01-19 14:55:08.327: E/SurfaceHolder(15454): java.lang.IllegalArgumentException I have a game that draws on a surfaceview canvas with a thread, that runs with the main process, I'm trying to open a new dialog box for input and nothing worked so I'm simply trying to open a new Activity that will Exception, I'm using the lock and unlock and well synchronized, I tried stopping the thread and even placing a couple of views. Any help is good Thanks.

method called after release() exception unable to resume with android camera

while developing a camera app i'v encountered an exception that only happend when I switch to other intent (onPause for my app) or go to preference in my app(same, onPause) 01-15 17:22:15.017: E/AndroidRuntime(14336): FATAL EXCEPTION: main 01-15 17:22:15.017: E/AndroidRuntime(14336): java.lang.RuntimeException: Method called after release() 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.hardware.Camera.setPreviewDisplay(Native Method) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.hardware.Camera.setPreviewDisplay(Camera.java:357) 01-15 17:22:15.017: E/AndroidRuntime(14336): at com.sora.cbir.yuki.image.leaf.CameraPreview.surfaceCreated(CameraPreview.java:32) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.view.SurfaceView.updateWindow(SurfaceView.java:551) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:213) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.view.V