The method If(boolean) is undefined

"The method If(boolean) is undefined "
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
     The method If(boolean) is undefined for the type TestCalculator
     Syntax error, insert ";" to complete Statement
I'm having some trouble using conditional statements in my code for some reason. I've recently had a lot of problems with my JRE's in eclipse and I thought I was finally past them. Could this error be related to something like that?
Do I have to make any special declarations at the beginning of my code invoking the boolean method?
Thanks

Thanks for the help. Here's the code...
import java.util.Scanner; // importing the scanner to be able to accept user input
public class BensCalculator { // declaring the public class, make sure it matches the filename
     public static void main(String[] args) { // mandatory command used to cue the program's start
          Scanner scannerObject = new Scanner(System.in);
String operator;
          int firstNumber, secondNumber;
System.out.println("Type two single digit integers separated by spaces and one legal operator.");
firstNumber = scannerObject.nextInt();
If (firstNumber > 10)
System.out.print("Error! --> Please enter an integer between 1 and 9.");
___________________________________________________________________________________

Similar Messages

  • The method is undefined for the type

    HI I have a javabean class:
    package database;
    import java.util.*;
    import java.io.*;
    public class CompanyFormBean implements Serializable{
      private String companyparentid;          
      private String companyname;               
      private Hashtable errors;
      //private String notify;
    public boolean validate() {
        boolean allOk=true;
        if (companyname.equals("")) {
          errors.put("companyname","Please enter your Company Name.");
          companyname="";
          allOk=false;
        return allOk;
      public String getErrorMsg(String s) {
        String errorMsg =(String)errors.get(s.trim());
        return (errorMsg == null) ? "":errorMsg;
    // public CompanyFormBean(){}
      public CompanyFormBean() {
        companyparentid          = "";
        companyname               = "";
        errors = new Hashtable();
      public String getCompanyparentid() {
        return companyparentid;
      public String getCompanyname() {
        return companyname;
      public void setCompanyparentid(String fcompanyparentid) {
        companyparentid = fcompanyparentid;
      public void setCompanyname(String fcompanyname) {
        companyname = fcompanyname;
      public void setErrors(String key, String msg) {
        errors.put(key,msg);
    }after the form is submitted I try to display the values
    <%@ page import="database.CompanyFormBean" %>
    <jsp:useBean id="formHandler" class="database.CompanyFormBean" scope="session"/>
    <html>
    <head>
    <title></title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author: Irene Nessa" content="">
    <meta name="Keywords" content="">
    <meta name="Description: creates a new member account" content="">
    </head>
    <body>
    <form name="reg" method="post" action="ProcessMemberRegistration.jsp" onsubmit='return formValidator()'>
    <table>
         <tr>
         <td>Create A New Account</td>
         </tr>
         <tr>
              <td>Existing Company</td>
              <td>
                   <input type="text" name="companyparentid" value='<%=formHandler.getCompanyparentid()%>'>
                   <!-- <select name="campanyparentid" onchange="setcompany(this)">
                        <option>Better Homes</option>
                        <option>Emaar</option>
                   </select>
                   <font size="" color="#FF0033"><b><i>OR</i></b></font>-->
              </td>
         </tr>
         <tr>
              <td>Company Name *</td>
              <td><input type="text" name="companyname" value='<%=formHandler.getCompanyname()%>'>
              </td>
         </tr>
    </table>
    <br>
         <br>
         <input type="reset">  <input type="submit" value='Check Form' />
    </form>
    </body>
    </html>But I keep getting the following errors:*The method getCompanyparentid() is undefined for the type CompanyFormBean* But it defind and the bean class complies. Any idea what am doing wrong.
    thanks.

    I actually got the same error in the same situation the following is my error and Stacktrace. I was trying to using AJAX to retrieve the message from DB and display it in a text area when user click a radio button. It works well untill I add a new method getMessage(String), please help!
    Mar 2, 2009 10:01:03 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    org.apache.jasper.JasperException: Unable to compile class for JSP:
    An error occurred at line: 22 in the jsp file: /getmessage.jsp
    The method getMessage(String) is undefined for the type Item
    19: <jsp:setProperty name="items" property="categoryId" value="<%=catid%>" />
    20: <jsp:setProperty name="items" property="effectiveIndicator" value="C" />
    21: <%
    22: String msg = items.getMessage(id);
    23: String decodedmsg = new String(msg.getBytes("iso-8859-1"), "Big5");
    24: System.out.print("MSG: " + msg);
    25: System.out.print("Deco-MSG: " + decodedmsg);
    An error occurred at line: 26 in the jsp file: /getmessage.jsp
    The method write(String) is undefined for the type HttpServletResponse
    23: String decodedmsg = new String(msg.getBytes("iso-8859-1"), "Big5");
    24: System.out.print("MSG: " + msg);
    25: System.out.print("Deco-MSG: " + decodedmsg);
    26: response.write(decodedmsg);
    27: %>
    Stacktrace:
    at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:517)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:686)
    at java.lang.Thread.run(Thread.java:619)

  • Method fprint(String) is undefined for the type JspWriter.

    please help me with this problem
    below is the jsp code written to access the data from the database and to display it in the new page.
    <%@ page
         import = "java.io.*"
         import = "java.lang.*"
         import = "java.sql.*"
    %>
    <%
         Connection dbconn=null;
         ResultSet results;
         PreparedStatement sql=null;     
                   String empid1=request.getParameter("empids");     
              try
    String driver = "com.mysql.jdbc.Driver";
              Class.forName(driver).newInstance();
                   dbconn =DriverManager.getConnection("jdbc:mysql://localhost/hris","root","redhat");
                   int empid11;
                   empid11=Integer.parseInt(empid1);
                   sql = dbconn.prepareStatement("select * from employee where empid=?");
                   sql.setInt(1,empid11);
                   results=sql.executeQuery();
                   results.next();
    out.print("<html>");
    out.print("<head>");
    out.print("</head>");
    out.print("<body>");
    out.print("<table width=810 border=0>");
    out.print("<tr>");
    out.print("<td width=210>");
    out.print("Employee Id");
    out.print("</td>");
    out.print("<td width=584>");
    int emp=results.getInt("empid");
    out.print(emp);
    out.print("</td>");
    out.print("</tr>");
    out.print("<tr>");
    out.print("<td>");
    out.print("FirstName");
    out.print("</td>");
    out.print("<td>");
    String first=results.getString("fname");
    out.print(first);
    out.print("</td>");
    out.fprint("</tr>");
              catch (SQLException s)
                   out.println("SQL Error <br>"+s);
    catch ( Exception x )
                   x.printStackTrace();
    %>
    but when i click the submit button , the error is
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 9 in the jsp file: /HRIS/empsearch1.jsp
    Generated servlet error:
    The method fprint(String) is undefined for the type JspWriter
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 9 in the jsp file: /HRIS/empsearch1.jsp
    Generated servlet error:
    The method fprint(String) is undefined for the type JspWriter
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.15 logs.
    i am not able to rectify the error.

    JavaB wrote:
    Hi ,
    I have a method defined in my dataManagerDAO classIs it dataManagerDAO or DataManagerDAO?
    getNoc( strRppsId) throws Exception {}That's not a legal Java method declaration, so it's clearly not your actual declaration, so I have no idea what your actual declaration is, so I can't tell you what you're doing wrong.
    Now I am calling this method inside my JSP page :
    DataManagerDAO dataMgr = new DataManagerDAO();
    dataMgr.getNoc(strRppsId)..
    But whenver I am running it locally , it fails to compile and gives following error msg :
    The method getNoc(String) is undefined for the type DataManagerDAOQuite obviously you're calling a method getNoc(String) but that method doesn't exist on the DataManagerDAO class. No matter how much you may think you know that it does, you're wrong and the compiler is right.
    Maybe you misspelled or mis-capitalized something. Maybe you're passing the wrong type of argument. Maybe you're still using an older version of the DataManagerDAO class from before you added that method. Not enough information here to say for sure.
    ny clue wats going wrong in here ?I assume you mean "any", not "ny" and "what's", not "wats". Clear, correct, precise communication counts with folks here almost as much as it does with the Java compiler.

  • Custom iterator problem - The method createChildIterator() is undefined for

    Hi there, this is my first post here, still quite new to Java. I'm having trouble with a custom iterator when trying to test it with JUnit. The reason to write a custom iterator is this: I want to get the object in the array, then for each item I want to get it's child items with a new iterator call.
    It's quite complicated because naturally I'm trying to hide the implementation from the "user". The iterator holds a list of classes called StandardSortElement. Each of these classes holds a class called AvailableResouce
    which in turn holds an AbstractResource, and it's AbstractResource that I want the iterator to return. My JUnit testing shows that this part works correctly.
    For the child items, they are also held inside the StandardSortElement as an array list. Here is the error I get
    "The method createChildIterator() is undefined for the type Iterator<AbstractResource>"
    First here is an interface for the custom iterator:
    public interface SortIteratorInterface extends Iterator<AbstractResource>{
         public abstract Iterator<BookingInterface> createChildIterator();
    }Here is the iterator class:
    public class StandardSortIterator implements SortIteratorInterface {
         ArrayList<StandardSortElement> items;
         Integer position = 0;
         * a constructor that passes in a sorted list of StandardSortElement
         public StandardSortIterator(ArrayList<StandardSortElement> items) {
              this.items = items;
         * Return bookings associated with the currently iterated StandardSortElement
         public Iterator<BookingInterface> createChildIterator() {
              return items.get(position).createBookingIterator();
         * Determine if there is another item in the list
         public boolean hasNext() {
              if (position >= items.size()) {
                   return false;
              } else {
                   return true;
         * Return the next resource in the list. We have a list of StandardSortElement but
         * we want to return the resource within.
         public AbstractResource next() {
              StandardSortElement ssa = items.get(position);                                             // Get a handle on the StandardSortElement     
              AbstractResource ar = ssa.getResource();                                                  // Now get the resource that's packaged up inside
              position++;                                                                                          // Increment the position
              return ar;                                                                                          // return the resource
         * Do not implement - mandatory interface implementation but not required here.
         public void remove() {
              // TODO Auto-generated method stub
    }This is the code taken from the JUnit test class
         * This iterator also has an interal child iterator. Check this works as expected
         @Test
         public void testChildIterator() {
              Iterator<AbstractResource> iterator = new StandardSortIterator(items);
              Integer i = 0;
              while (iterator.hasNext()) {
                   AbstractResource abstractResource = (AbstractResource)iterator.next();
                    if (i.equals(0)) {
                         // The first element should contain children - check it works
                         Iterator<BookingInterface> childIterator = iterator.createChildIterator(); // ERROR OCCURS HERE
                   i++;               
              assertTrue(i.equals(items.size()));
         /************************************************************************************/Thank you in advance for any help you can provide!
    Paul

    Your unit test is coded against the Iterator interface, not your SortIteratorInterface, which is where the createChildIterator method is defined. You need to use a reference to a SortIteratorInterface, not an Iterator. Incidentally, when defining an interface, it's unnecessary to declare the methods as public and abstract. They're implicitly that anyway

  • How can i change the method that get a Bitmap file and return 15 new Bitmaps so the new Bitmaps will be also PixelFormat Format8bppIndexed ?

    This is the method:
    public static Bitmap[] get_images_with_clouds(Bitmap radar_image)
    int e = 0;
    int f = 0;
    int image_clock_area_x = 0;
    int image_clock_area_y = 0;
    int image_clock_area_x1 = 140;
    int image_clock_area_y1 = 21;
    Bitmap[] localImages;
    localImages = new Bitmap[15];
    Bitmap image;
    image = new Bitmap(Properties.Resources.radar_without_clouds);
    BitmapData bmD = null;
    BitmapData bmD2 = null;
    try
    bmD = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
    bmD2 = radar_image.LockBits(new Rectangle(0, 0, radar_image.Width, radar_image.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
    IntPtr sc0 = bmD.Scan0;
    unsafe
    int* p = (int*)sc0.ToPointer();
    int* p2 = (int*)bmD2.Scan0.ToPointer();
    for (e = image_clock_area_x; e < image_clock_area_x + image_clock_area_x1; e++)
    for (f = image_clock_area_y; f < image_clock_area_y + image_clock_area_y1; f++)
    Color clock_color = Color.FromArgb(p2[e + f * bmD2.Width]);
    p[e + f * bmD.Width] = clock_color.ToArgb();
    image.UnlockBits(bmD);
    radar_image.UnlockBits(bmD2);
    catch
    try
    image.UnlockBits(bmD);
    catch
    try
    radar_image.UnlockBits(bmD2);
    catch
    int c;
    for (c = 0; c < localImages.Length; c++)
    localImages[c] = new Bitmap(image);
    Bitmap new_image = new Bitmap(Properties.Resources.radar_without_clouds);
    Bitmap new_image1 = new Bitmap(Properties.Resources.radar_without_clouds);
    Bitmap localbmptest = black_and_white(new_image, radar_image);
    Image image1 = black_and_white(new_image, radar_image);
    image1.Save(@"c:\temp\testclouds666.jpg");
    Bitmap clouds = new Bitmap(image1);
    int x;
    int y;
    int a;
    int b;
    int d = 0;
    Bitmap redImage;
    redImage = new Bitmap(512, 512);
    using (Graphics g = Graphics.FromImage(redImage))
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
    g.Clear(Color.Red);
    BitmapData bmData = null;
    BitmapData bmData2 = null;
    BitmapData bmDataArray = null;
    try
    bmData = clouds.LockBits(new Rectangle(0, 0, clouds.Width, clouds.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
    bmData2 = radar_image.LockBits(new Rectangle(0, 0, radar_image.Width, radar_image.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
    IntPtr scan0 = bmData.Scan0;
    IntPtr scan02 = bmData2.Scan0;
    unsafe
    int* p = (int*)scan0.ToPointer();
    int* p2 = (int*)scan02.ToPointer();
    double h, mm;
    for (d = 0; d < localImages.Length; d++)
    bmDataArray = localImages[d].LockBits(new Rectangle(0, 0, localImages[d].Width, localImages[d].Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
    IntPtr scan0Array = bmDataArray.Scan0;
    int* pArray = (int*)scan0Array.ToPointer();
    for (a = 0; a < new_image.Width; a++)
    for (b = 0; b < new_image.Height; b++)
    Color color1 = Color.FromArgb(p[a + b * bmData.Width]);
    Color color2 = Color.FromArgb(p2[a + b * bmData2.Width]);
    if (color1.R != 0 || color1.G != 0 || color1.B != 0)
    h = color2.GetHue();
    mm = RadarAnalysis.Hue2MMPerHour(h);
    if (mm >= treshhold_array[14 - d])
    pArray[a + b * bmDataArray.Width] = color2.ToArgb();
    localImages[d].UnlockBits(bmDataArray);
    clouds.UnlockBits(bmData);
    radar_image.UnlockBits(bmData2);
    catch (Exception error)
    try
    clouds.UnlockBits(bmData);
    catch
    try
    radar_image.UnlockBits(bmData2);
    catch
    try
    localImages[d].UnlockBits(bmDataArray);
    catch
    Logger.Write("Error Exception ==> " + error);
    MessageBox.Show("Error Exception ==> " + error);
    return localImages;
    In the end i'm getting 15 Bitmaps in localImages.
    localImages is Bitmap[]
    The method get a Bitmap and the Bitmap pixel format is: Format8bppIndexed
    I want that in the end the 15 Bitmaps in localImages will be also pixel format of Format8bppIndexed.
    The problem is that if i change everywhere in the method from: PixelFormat.Format32bppArgb to PixelFormat.Format8bppIndexed
    I'm getting exception on the line:
    pArray[a + b * bmDataArray.Width] = color2.ToArgb();
    Attempted to read or write protected memory. This is often an indication that other memory is corrupt
    System.AccessViolationException was unhandled
      HResult=-2147467261
      Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
      Source=My Weather Station
      StackTrace:
           at mws.ImagesComparison.get_images_with_clouds(Bitmap radar_image) in d:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\ImagesComparison.cs:line 469
           at mws.ScanningClouds.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in d:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\ScanningClouds.cs:line 695
           at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
           at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
           at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
           at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
           at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
           at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
           at System.Threading.ThreadPoolWorkQueue.Dispatch()
           at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
      InnerException: 
    Line 469 is: pArray[a + b * bmDataArray.Width] = color2.ToArgb();

    Thorsten Hi,
    Too complicated for me i will try to look on it.
    Also if you will have time later maybe you could look at it too ? 
    For now what i tried was to get the returned 15 new Bitmaps to a local array:
    bitmaps = ImagesComparison.get_images_with_clouds(b1);
    for (int i = 0; i < bitmaps.Length; i++)
    ConvertTo1or8Bit.ColorToGrayscale(bitmaps[i]);
    break;
    Then make a convertion with a new class trying to convert the Bitmaps to 8 bit in the memory without saving them first to the hard disk. This is the new class:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Drawing.Imaging;
    using System.Drawing;
    using System.IO;
    namespace mws
    class ConvertTo1or8Bit
    public ConvertTo1or8Bit()
    public static Bitmap ColorToGrayscale(Bitmap bmp)
    int w = bmp.Width,
    h = bmp.Height,
    r, ic, oc, bmpStride, outputStride, bytesPerPixel;
    PixelFormat pfIn = bmp.PixelFormat;
    ColorPalette palette;
    Bitmap output;
    BitmapData bmpData, outputData;
    //Create the new bitmap
    output = new Bitmap(w, h, PixelFormat.Format8bppIndexed);
    //Build a grayscale color Palette
    palette = output.Palette;
    for (int i = 0; i < 256; i++)
    Color tmp = Color.FromArgb(255, i, i, i);
    palette.Entries[i] = Color.FromArgb(255, i, i, i);
    output.Palette = palette;
    //No need to convert formats if already in 8 bit
    if (pfIn == PixelFormat.Format8bppIndexed)
    output = (Bitmap)bmp.Clone();
    //Make sure the palette is a grayscale palette and not some other
    //8-bit indexed palette
    output.Palette = palette;
    return output;
    //Get the number of bytes per pixel
    switch (pfIn)
    case PixelFormat.Format24bppRgb: bytesPerPixel = 3; break;
    case PixelFormat.Format32bppArgb: bytesPerPixel = 4; break;
    case PixelFormat.Format32bppRgb: bytesPerPixel = 4; break;
    default: throw new InvalidOperationException("Image format not supported");
    //Lock the images
    bmpData = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly,
    pfIn);
    outputData = output.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.WriteOnly,
    PixelFormat.Format8bppIndexed);
    bmpStride = bmpData.Stride;
    outputStride = outputData.Stride;
    //Traverse each pixel of the image
    unsafe
    byte* bmpPtr = (byte*)bmpData.Scan0.ToPointer(),
    outputPtr = (byte*)outputData.Scan0.ToPointer();
    if (bytesPerPixel == 3)
    //Convert the pixel to it's luminance using the formula:
    // L = .299*R + .587*G + .114*B
    //Note that ic is the input column and oc is the output column
    for (r = 0; r < h; r++)
    for (ic = oc = 0; oc < w; ic += 3, ++oc)
    outputPtr[r * outputStride + oc] = (byte)(int)
    (0.299f * bmpPtr[r * bmpStride + ic] +
    0.587f * bmpPtr[r * bmpStride + ic + 1] +
    0.114f * bmpPtr[r * bmpStride + ic + 2]);
    else //bytesPerPixel == 4
    //Convert the pixel to it's luminance using the formula:
    // L = alpha * (.299*R + .587*G + .114*B)
    //Note that ic is the input column and oc is the output column
    for (r = 0; r < h; r++)
    for (ic = oc = 0; oc < w; ic += 4, ++oc)
    outputPtr[r * outputStride + oc] = (byte)(int)
    ((bmpPtr[r * bmpStride + ic] / 255.0f) *
    (0.299f * bmpPtr[r * bmpStride + ic + 1] +
    0.587f * bmpPtr[r * bmpStride + ic + 2] +
    0.114f * bmpPtr[r * bmpStride + ic + 3]));
    //Unlock the images
    bmp.UnlockBits(bmpData);
    output.UnlockBits(outputData);
    return output;
    But they are still 32 bit. So i guess i didn't realy understand yet how to do it.

  • How to use the method finalize () ? It has protected access...

    Here is the program : the structure is the way I would write in Pascal.
    I need new object question at each turn in the loop ! But question is already defined outside the loop. So, I thought to the method finalize (). But the compilator doesn't agree.... It would be a good thing however to destroy objects wich are obsolete !
    public class MM {
       public static void main (String [] args) {
          Base base = new Base ();
          base.demanderNbCouleurs ();
          base.demanderNbPions ();
          Combi solution = new Combi ();
          solution.demander ();
          Combi question = new Combi ();
          question.cueillir ();
          question.afficher ();
          Reponse reponse = new Reponse ();
          reponse.demander ();
          boolean trouve = reponse.getBP () == base.getNbPions ();
          boolean erreur = false;
          while (! trouve & ! erreur) {
             question.enregistrer (reponse.getBP (), reponse.getMP ());
             question.finalize ();
             Combi question = new Combi ();
             question.cueillir ();
             while (! question.compatible () & ! question.getVide ()) {
                question.cueillir ();
             if (question.compatible ()) {
                question.afficher ();
                reponse.demander ();
                trouve = reponse.getBP () == base.getNbPions ();
             } else {
                erreur = true;
          conclusion (trouve);
       }

    So, I did ;
             question = new Combi ();And it's magical ! The program works...
    Now, I would like to give colors to my researcher Mastermind :
    1 2 3 4
    4 4 1 1 ... BP MP : 0 2
    1 1 6 5 ... BP MP : 1 0
    1 3 4 3 ... BP MP : 1 2
    1 2 3 4 ... BP MP : 4 0
    Trouve !
    I want the 1 to be red, the 2 be yellow, the 3 be green and so on...
    Is there any procedure " textColor " ?
    here is my method afficher () :
       public void afficher () {
          // Affiche le tableau 'combi'.
          for (int i = 0; i < NB_PIONS; i++) {
             // textColor (couleur [combi );
    System.out.print (" " + combi [i]);

  • How the method IviSpecAn_ConfigureLevel work in the agesa driver?

    I have trouble with the IVI-driver for the Spectrum Analyzer. When I call the method IviSpecAn_ConfigureLevel in the SpecAn class driver I get an error message, but only when I call it for the first time. After the first time it works like charm. When I read out the error message I got from the intrument it tells "Undefined header". I use the latest IviSpacan driver (agesa_MS.msi) download from this site and the modell of Spectrum Analyzer is E4445A. Whats is wrong? Is there any settings I forgot?
    Best Regards,
    Mattias Danielsson

    Hello Vesna!
    Thank you for your answer!
    I think I have figure out a bug in the agesa driver. It works fine after I have done the following changes in the agesa.c:
    ViStatus _VI_FUNC agesa_ConfigureLevel
    Removed:
    viCheckParm( Ivi_SetAttributeViReal64 ( vi,
    NULL,
    AGESA_ATTR_INPUT_IMPEDANCE,
    0, inputImpedance),
    3, "inputImpedance");
    static ViStatus agesa_RecalculateLevelToDBM
    Removed:
    checkErr( Ivi_GetAttributeViReal64(vi, VI_NULL, AGESA_ATTR_INPUT_IMPEDANCE, 0, &impedance));
    It seems to be that the E4445A cant set the input impedance.
    I can temporary run on my own modified driver but are there any chances to get an update driver soon?
    Best Regards,
    Mattias Danielsson

  • Name of the method.

    Good day,
    Within a class, the name of the class can bet determined via a call to the "getClass().getName()" method, right ?
    How do we get the name of the method itself ?
    ================
    class magic {
    magician () {
    xx = getClass().getName(); // --> Will give "magic"
    // How do we get "magician" ?
    ================
    Regards

    Good day,
    By all means, I'm far from being an expert or even being to point to consider myself "at ease" with Java.
    Simply put, I have few applets sources that are using the "simple" things such as the following :
    "public boolean mouseEnter(Event Event1, int int2, int int3)"
    When compiled with SDK v1.3, there is a mention that the API is deprecated. I looked into the deprecated APIs and functions documentation, and I must admit, I'm completely lost in that jungle!
    What I would like to see/have, is how it is being done using the "new" or "proper" way. The lack of basic real and simple examples is a tad irritating, at least for me.
    As far as I can see, the Java language is not quite easy to learn for self-training people and taking Java classes is not part of my budget for now.
    The above is only on example.
    Anyhow, as far as getting the "Method Name", I guess the idea of adding it to my //#INC line would be the easiest and most performance effective way.
    As far as the doclet approach with JavaDoc, I think this is a good idea is good, however I'm far from being at the stage of creating such thing.
    Adding a new "throwable()" and getting the stacktrace is something to consider, however for the moment being I just want to apply the KISS rule, so I'm not throwing that idea away. ;-)
    I'll look at the different samples that came with the JDK, however I would appreciate if some of you could provide me with links to simple samples that are "respecting" the JDK v1.3/v1.4 calling conventions, would that be for the mouse example mentioned above, or some other of those "deprecated" things.
    I know for a fact that some of them are requiring a simply syntax adjustment, I can easily cope with that. Some others are a bit "fancier" to adapt, such as the alternate approach to eliminate a call to the "threadname.stop()" method. That one was easy to do simply because there was an example in the docs, that I was lucky enough to find. For some others, I simply need help to figure it out, so this is why I'm enquiring for some assistance and help.
    Best regards.

  • Multiple annotations found at this line, the method  ......

    There,
    I got an error when I used sql tag lib.
    Error Message:
    Multiple annotations found at this line, the method getStartdate() is undefined for the type map.
    Before, I used JSTL 1.0, it worked fine, after I upgraded it to 1.1, I got the problem.
    Any help and idea are appreciated.
    Wolf
    <%@ page session="true" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <sql:query var="monthlyList" dataSource="jdbc/Booking" scope="request">
    select date as d, count(d_code) as c, (sum(seconds)) as t
    from inservicehistory where date>='<c:out value="${param.startdate}" />'  and date <='<c:out value="${param.enddate}" />'
    group by d
    </sql:query>
    <jsp:forward page="list_daily.jsp" />

    Very strange.
    What server are you using?
    You realise that JSTL1.1 requires a JSP2.0 container (eg Tomcat 5?)
    Does your web.xml declare itself as version 2.4?
    Is there any more to the error message?
    Also I would write the query like this:
    <sql:query var="monthlyList" dataSource="jdbc/Booking" scope="request">
    select date as d, count(d_code) as c, (sum(seconds)) as t
    from inservicehistory where date>= ?
    and date <= ?
    group by d
    <c:param value="${param.startdate}" />
    <c:param value="${param.enddate}" />
    </sql:query>

  • Implements the method defined in interface

    I defined a interface such as
    interface IAuthorizer{
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> Permission);
    In java 5, why does compiler not accept the method checkPermission signature of the following class
    class Auth1 implements IAuthorizer{
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> Permission){
    Iclass Auth1 implements IAuthorizer{
    boolean checkPermission(Set subj, Set Permission){
    nstead, the compiler only accepts

    <If you compile the interface and the class in the same time (eg not having the interface in a jar file against which to compile the class), the compiler should accept your code.>
    The interface and class is even in the same package. The compiler does not accept method signature as
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> perms)
    <If your interface is part of a library jar file, could it be that
    - the library is obfuscated using an obfuscater that doesn't know about generics?
    - the class is written against JDK 1.4 API (in which Set is not generic)?
    - the class is compiled using java 1.4 compiler?
    >
    no library is involved in the issue.
    class is written in JDK 1.5 API and use JDK 1.5 compiler.

  • Getting an error when calling the method of the bean

    Hi,
    I have the following problem:
    From my action class I'm calling a method on EJB through Business Object and getting the following error:
    org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class gov.nyc.fisa.wbas.exceptions.ServerException
    [3/6/08 13:53:44:700 EST] 1acdd938 WebGroup E SRVE0026E: [Servlet Error]-[SERVER EXCEPTION CALLING searchBenefitGroups() METHOD ]: gov.nyc.fisa.wbas.exceptions.ServerException: SERVER EXCEPTION CALLING searchBenefitGroups() METHOD
    The following are parts of my code:
    In Action Class:
    BenefitGroupBO bo = new BenefitGroupBO();
    BenefitGroupsColView cView = new BenefitGroupsColView();
    try{
        cView = bo.searchBenefitGroups(transferObject,true);
    catch (ServerException e){
        throw new ServerException("SERVER EXCEPTION CALLING searchFunds() METHOD ",e);
    In Business Object:
    private BenefitGroupImpl benGrpImpl = null;
        try{
               System.out.println("1. BenefitGroupBO - searchBenefitGroups()");
               collectionView = benGrpImpl.searchBenefitGroups(transferObject, isSearch);
               System.out.println("2. BenefitGroupBO - searchBenefitGroups()");
    catch (RemoteException e){
                throw new ServerException("Remote exception calling BenefitGroupImplBean: searchBenefitGroups()", e);
    .....It never executes the second print statement in the method
    In Remote Interface:
    public BenefitGroupsColView searchBenefitGroups(BenefitGroupVO transferObject, boolean isSearch)
                                                                           throws ServerException, java.rmi.RemoteException;
    In the EJB
    public BenefitGroupsColView searchBenefitGroups(BenefitGroupVO transferObject, boolean isSearch){
                                                                        throws ServerException                
             System.out.println("1. BenefitGroupImplBean - searchBenefitsGroups() method");
             BenefitGroupsColView collectionView = new BenefitGroupsColView();
             System.out.println("2. BenefitGroupImplBean - searchBenefitsGroups() method");
              return collectionView;
    .....It never executes first Print statement in that method and I do not think it ever goes into the actual EJB class.
    Can anyone tell me what am I doing wrong?
    Thank you
    Edited by: SolutionsQuest on Mar 6, 2008 11:14 AM
    Edited by: SolutionsQuest on Mar 6, 2008 11:15 AM

    Hi,
    Refer below threads:
    You are trying to access a page that is no longer active
    You are trying to access a page that is no longer active.
    You are trying to access a page that is no longer active.
    --Sushant                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • The method clone() from the type Object is not visible

    Hi,
    This is my 1st post here for a few years, i have just returned to java.
    I am working through a java gaming book, and the "The method clone() from the type Object is not visible" appears, preventing the program from running. I understand "clone" as making a new copy of an object, allowing multiple different copies to be made.
    The error occurs here
    public Object clone() {
            // use reflection to create the correct subclass
            Constructor constructor = getClass().getConstructors()[0];
            try {
                return constructor.newInstance(new Object[] {
                    (Animation)left.clone(),
                    (Animation)right.clone(),
                    (Animation)deadLeft.clone(),
                    (Animation)deadRight.clone()
            catch (Exception ex) {
                // should never happen
                ex.printStackTrace();
                return null;
        }The whole code for this class is here
    package tilegame.sprites;
    import java.lang.reflect.Constructor;
    import graphics.*;
        A Creature is a Sprite that is affected by gravity and can
        die. It has four Animations: moving left, moving right,
        dying on the left, and dying on the right.
    public abstract class Creature extends Sprite {
            Amount of time to go from STATE_DYING to STATE_DEAD.
        private static final int DIE_TIME = 1000;
        public static final int STATE_NORMAL = 0;
        public static final int STATE_DYING = 1;
        public static final int STATE_DEAD = 2;
        private Animation left;
        private Animation right;
        private Animation deadLeft;
        private Animation deadRight;
        private int state;
        private long stateTime;
            Creates a new Creature with the specified Animations.
        public Creature(Animation left, Animation right,
            Animation deadLeft, Animation deadRight)
            super(right);
            this.left = left;
            this.right = right;
            this.deadLeft = deadLeft;
            this.deadRight = deadRight;
            state = STATE_NORMAL;
        public Object clone() {
            // use reflection to create the correct subclass
            Constructor constructor = getClass().getConstructors()[0];
            try {
                return constructor.newInstance(new Object[] {
                    (Animation)left.clone(),
                    (Animation)right.clone(),
                    (Animation)deadLeft.clone(),
                    (Animation)deadRight.clone()
            catch (Exception ex) {
                // should never happen
                ex.printStackTrace();
                return null;
            Gets the maximum speed of this Creature.
        public float getMaxSpeed() {
            return 0;
            Wakes up the creature when the Creature first appears
            on screen. Normally, the creature starts moving left.
        public void wakeUp() {
            if (getState() == STATE_NORMAL && getVelocityX() == 0) {
                setVelocityX(-getMaxSpeed());
            Gets the state of this Creature. The state is either
            STATE_NORMAL, STATE_DYING, or STATE_DEAD.
        public int getState() {
            return state;
            Sets the state of this Creature to STATE_NORMAL,
            STATE_DYING, or STATE_DEAD.
        public void setState(int state) {
            if (this.state != state) {
                this.state = state;
                stateTime = 0;
                if (state == STATE_DYING) {
                    setVelocityX(0);
                    setVelocityY(0);
            Checks if this creature is alive.
        public boolean isAlive() {
            return (state == STATE_NORMAL);
            Checks if this creature is flying.
        public boolean isFlying() {
            return false;
            Called before update() if the creature collided with a
            tile horizontally.
        public void collideHorizontal() {
            setVelocityX(-getVelocityX());
            Called before update() if the creature collided with a
            tile vertically.
        public void collideVertical() {
            setVelocityY(0);
            Updates the animaton for this creature.
        public void update(long elapsedTime) {
            // select the correct Animation
            Animation newAnim = anim;
            if (getVelocityX() < 0) {
                newAnim = left;
            else if (getVelocityX() > 0) {
                newAnim = right;
            if (state == STATE_DYING && newAnim == left) {
                newAnim = deadLeft;
            else if (state == STATE_DYING && newAnim == right) {
                newAnim = deadRight;
            // update the Animation
            if (anim != newAnim) {
                anim = newAnim;
                anim.start();
            else {
                anim.update(elapsedTime);
            // update to "dead" state
            stateTime += elapsedTime;
            if (state == STATE_DYING && stateTime >= DIE_TIME) {
                setState(STATE_DEAD);
    }Any advice? Is it "protected"? Is the code out-of-date?
    thankyou,
    Lance 28

    Lance28 wrote:
    Any advice? Is it "protected"? Is the code out-of-date?Welcome to the wonderful world of Cloneable. In answer to your first question: Object's clone() method is protected.
    A quote from Josh Bloch's "Effective Java" (Item 10):
    "A class that implements Cloneable is expected to provide a properly functioning public clone() method. It is not, in general, possible to do so unless +all+ of the class's superclasses provide a well-behaved clone implementation, whether public or protected."
    One way to check that would be to see if super.clone() works. Their method uses reflection to try and construct a valid Creature, but it relies on Animation's clone() method, which itself may be faulty. Bloch suggests the following pattern:public Object clone() throws CloneNotSupportedException {
       ThisClass copy = (ThisClass) super.clone();
       // do any additional initialization required...
       return copy
    if that doesn't work, you +may+ be out of luck.
    Another thing to note is that Object's clone() method returns a +shallow+ copy of the original object. If it contains any data structures (eg, Collections or arrays) that point to other objects, you may find that your cloned object is now sharing those with the original.
    Good luck.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Tutorial ErrorBehavior method from tutorial is undefined

    Hi,
    every time I try to use the <i>reportInvalidContextAttributeMessage</i> method in the ErrorBehavior project, like it is suggested in tutorial 3, NetWeaver Developer Studio informs me that this method is undefined for the type <i>IWDMessageManager</i>.
    I did the necessary imports like adviced in the tutorial.
    Can anyone please help me in finding a solution?
    Regards,
    Stefan

    Hi Stefan,
    Following are the signatures of the method mentioned by you.
    void com.sap.tc.webdynpro.progmodel.api.IWDMessageManager.
    reportInvalidContextAttributeException(IWDAttributePointer attribute, WDNonFatalException ex)
    Report an exception as error message that is associated with an invalid context attribute value.
    Parameters:
         attribute is the invalid attribute
         ex is the exception raised by some validation routine
    void com.sap.tc.webdynpro.progmodel.api.IWDMessageManager.
    reportInvalidContextAttributeException(IWDAttributePointer attribute, WDNonFatalException ex)
    Report an exception as error message that is associated with an invalid context attribute value.
    Parameters:
         attribute is the invalid attribute
         ex is the exception raised by some validation routine
    Following methods are or will be depricated
    void com.sap.tc.webdynpro.progmodel.api.IWDMessageManager.
    reportInvalidContextAttributeException(IWDAttributePointer attribute, WDNonFatalException ex)
    Report an exception as error message that is associated with an invalid context attribute value.
    Parameters:
         attribute is the invalid attribute
         ex is the exception raised by some validation routine
    void com.sap.tc.webdynpro.progmodel.api.IWDMessageManager.
    reportInvalidContextAttributeException(IWDAttributePointer attribute, WDNonFatalException ex)
    Report an exception as error message that is associated with an invalid context attribute value.
    Parameters:
         attribute is the invalid attribute
         ex is the exception raised by some validation routine
    Regards
    Ayyapparaj

  • What class calls the method?

    If there is a method in a class that could be called by any one of, lets say, one hundred other classes, in that method is there a way of printing out the name of the class that called it ?
    So if class Xyz calls the method I would like to just do a println in the method saying that class Xyz called it ?

    Yup... Thread.currentThread().getStackTrace();
    package krc.utilz;
    import java.io.PrintStream;
    public class Tracer
      public static PrintStream out = null;
      public boolean enabled = true;
      public enum Format { LONG, SHORT }
      public Format format;
      public Tracer() {
        this(System.err, Tracer.Format.LONG);
      public Tracer(PrintStream out) {
        this(out, Tracer.Format.LONG);
      public Tracer(Format format) {
        this(System.err, format);
      public Tracer(PrintStream out, Format format) {
        this.out = out;
        this.format = format;
      public String toString() {
        return get(5);
      public String get() {
        return get(2);
      public String get(int i) {
        StackTraceElement[] st = Thread.currentThread().getStackTrace();
        if (i>=st.length) i = st.length-1; //don't go past top of stack
        StackTraceElement t = st;
    String s = t.getFileName()+":"+t.getLineNumber()+":";
    if (this.format == Format.LONG) {
    s += t.getClassName()+"."+t.getMethodName();
    return(s);
    public void debug(String msg) {
    if(!enabled)return;
    out.println("DEBUG: "+msg);
    public void print(String msg) {
    if(!enabled)return;
    if (out==null) return;
    out.println(get(3)+" : "+msg);
    public void print() {
    if(!enabled)return;
    if (out==null) return;
    out.println(get(3));
    public void print(int i) {
    if(!enabled)return;
    if (out==null) return;
    out.println(get(i));
    public static String getCurrentMethodName() {
    StackTraceElement[] st = Thread.currentThread().getStackTrace();
    return(st[2].getMethodName());

  • Urgent help req : work item id not getting passed in the method

    Hi ,
    I have created a subtype zcats of business object CATS and delegated it .
    I have created a new method Approve1 ( with attributes  SYNCRONUS & DIALOG )  in zcats which is similar in coding  to Approve method of CATS ( DIALOG) .
    I have include the method Approve1 of business object zcats in a standard task .
    The problem is that when the eorkflow gets triggered ,  the workitem id is not getting passed in the method APProve1 of zcats.
    Can someone please help me with this .
    Points would surely be awarded .

    BEGIN_METHOD APPROVE1 CHANGING CONTAINER.                 
      DATA: WORKITEMID_IMP LIKE OBJECT-KEY-ITEMID.              
      DATA: WI_CHCKWI LIKE SWWWIHEAD-WI_ID.                     
      DATA: WORKITEM TYPE SWC_OBJECT.                           
       <u> WORKITEMID_IMP = OBJECT-KEY-ITEMID</u>.                     
        SWC_GET_ELEMENT CONTAINER '_WORKITEM' WORKITEM.         
        SWC_GET_PROPERTY WORKITEM 'WorkitemReference' WI_CHCKWI.
        IF SY-SUBRC EQ 0 AND NOT WI_CHCKWI IS INITIAL.          
          WORKITEMID_IMP = WI_CHCKWI.                           
        ENDIF.                                                  
        CALL FUNCTION 'CATS_WF_APPROVAL'                        
          EXPORTING                                             
            WORKITEMID_IMP = WORKITEMID_IMP                     
          TABLES                                                
            CONT_IMP = CONTAINER.                               
      END_METHOD.                                               
    hi ,
    the above is the code in the method .
    At the first step of execution underlined above , the work item id is appearing blank .
    I think that the value is not passed to the container , but i am not sure og how to pass data to this conatiner

Maybe you are looking for

  • Probably a stupid question but how do I designate a default location where documents are stored?

    Ideally, I'd like the default to be the last location I saved a file.  I hate starting at the top of the file structure every time!

  • My Droid Mini is eating my messages.

    I have tried everything on the troubleshooting page, but more often than not I'm not receiving several messages from at least one of my contacts. I have tried everything on the troubleshooting page, but nothing works. I'm only receiving a few of the

  • Apache plug-in for weblogic server under linux

    Ladies and gents,           Having problems getting the plug-in working..............           System components:           RedHat linux 6.1           BEA Weblogic server 5.1           Apache web server 1.3.19 (WLS supports the plug-in)           I

  • Error calling web services

    Hi there! I'm new to web services. I'm using NetBeans and running under Windows to develop this program. I've created an application that call 2 web services. the output from webserviceA will be an input to webserviceB. in webserviceA I used a socket

  • Just one homepage does not open

    Neither Safari Version 4.0.4 (6531.21.10) nor Firefox open the site www.geogebra.org on my computer (OS X 10.6.2). Other Macs do open this page. What's wrong, what to do? This homepage is most important for my work: A Java-app always should get there