ToString problem...

Hi,
I couldn't find out what is the problem in this code...
     public String toString()
          return (getName() + " containing " + getNumFish() + " fish.");
     }I always get an "')' is expected" error...

I always get an "')' is expected" error...When you have mismatched parenthesis the error may not be where it's reported. I guess you have more methods so carefully check that the ( mathches the ) in the class all the way through.

Similar Messages

  • Arrays.toString problem

    Hello,
    I'm trying to print out the values of an integer array using the method toString(int a[]) of the Arrays's class. While doing it, I encounter the following error:
    Array.java:17: toString() in java.lang.Object cannot be applied to (int[])
              System.out.println (Arrays.toString(a));
    The source code is the following:
    import java.util.*;
    class Array{
         public static void main (String[] args){
              int[] a = new int[10];
              Random rand = new Random ();
              for (int i=0; i<a.length; i++)
                   a= rand.nextInt(10);
              Arrays.sort(a);
              System.out.println (Arrays.toString(a));
    Hope someone can help me!
    Thanks a lot.
    Gabriel

    sabre150 wrote:
    Sounds like an interesting little project. I've been trying to write an article on cross platform/language encryption so I've been doing little bits of C/C++/C#/Python/PHP/JNI . I don't find writing easy so the task is turning out to be a lot bigger than I anticipated.
    I have fond memories of electric shock treatment. Having trained as an Electrical Engineer I spend the first 4 years of my working life trying to kill myself. Nearly succeeded twice. Now I long to get back to the sort of breadboards that you are working on but no real chance. I would like to create a playing card dealing system but my hardware knowledge is so out of date that I don't really have a hope.Stay far away from hardware; I once fell for it and designed a little logic game in hardware (Nim); I got it all together, including the total costs (just a few bucks) and happily went to the electrickery store. They laughed at me and told me about power supplies and debouncing switches and buffers for the LEDs and what have you. After an hour I stood outside again after having spent almost 200 bucks. I started soldering and I soldered and soldered; in the end I had a big blob of spaghetti and it didn't work. I started all over again and I ended up with an even bigger blob of spaghetti that didn't even fit anymore in the little box I bought. But it worked.
    I had fun for almost 10 minutes until my little rabbit (I kept it as a cat) saw it, chewed on the spaghetti blob and it never worked again ... so far for hardware; don't go there.
    kind regards,
    Jos ;-)

  • ArrayList problem ....i can remove my object from my arrayList

    hi all, i am going to remove a object from my array by using arrayList.However, it can`t work properly and did nth for me..i don`t know why...could anyone give me some suggestion and show me what i did wrong on my code ....i stated more detail next to my code...plesae help...
    public class MusicCd
         private String musicCdsTitle;
            private int yearOfRelease;
         public MusicCd()
              musicCdsTitle = "";
              yearOfRelease = 1900;
         public MusicCd(String newMusicCdsTitle)
              musicCdsTitle = newMusicCdsTitle;
              //yearOfRelease = newYearOfRelease;
         public MusicCd(String newMusicCdsTitle, int newYearOfRelease)
              musicCdsTitle = newMusicCdsTitle;
              yearOfRelease = newYearOfRelease;
         public String getTitle()
              return musicCdsTitle;
         public int getYearOfRelease()
              return yearOfRelease;
         public void setTitle(String newMusicCdsTitle)
              musicCdsTitle = newMusicCdsTitle;
         public void setYearOfRelease(int newYearOfRelease)
              yearOfRelease = newYearOfRelease;
         public boolean equalsName(MusicCd otherCd)
              if(otherCd == null)
                   return false;
              else
                   return (musicCdsTitle.equals(otherCd.musicCdsTitle));
         public String toString()
              return("Music Cd`s Title: " + musicCdsTitle + "\t"
                     + "Year of release: " + yearOfRelease + "\t");
    import java.util.ArrayList;
    import java.io.*;
    public class MusicCdStore
       ArrayList<MusicCd> MusicCdList;
       public void insertCd()
            MusicCdList = new ArrayList<MusicCd>( ); 
            readOperation theRo = new readOperation();
            MusicCd theCd;
            int muiseCdsYearOfRelease;
            String muiseCdsTitle;
              while(true)
                    String continueInsertCd = "Y";
                   do
                        muiseCdsTitle = theRo.readString("Please enter your CD`s title : ");
                        muiseCdsYearOfRelease = theRo.readInt("Please enter your CD`s year of release : ");
                        MusicCdList.add(new MusicCd(muiseCdsTitle, muiseCdsYearOfRelease));
                        MusicCdList.trimToSize();
                        continueInsertCd = theRo.readString("Do you have another Cd ? (Y/N) : ");
                   }while(continueInsertCd.equals("Y") || continueInsertCd.equals("y") );
                   if(continueInsertCd.equals("N") || continueInsertCd.equals("n"));
                                                    //MusicCdList.add(new MusicCd(muiseCdsTitle, muiseCdsYearOfRelease));                              
                                  break;
                      //System.out.println("You `ve an invalid input " + continueInsertCd + " Please enter (Y/N) only!!");
       public void displayAllCd()
                    System.out.println("\nOur CD collection is: \n" );
              System.out.println(toString());
       public String toString( )
            String result= " ";
            for( MusicCd tempCd : MusicCdList)
                 result += tempCd.toString() + "\n";
            return result;
       public void searchingMusicCd()
            readOperation theRo = new readOperation();
            String keyword = theRo.readString("Enter a CD `s Title you are going to search : ") ;
            ArrayList<MusicCd> results = searchForTitle(keyword );
              System.out.println("The search results for " + keyword + " are:" );
              for(MusicCd tempCd : results)
                   System.out.println( tempCd.toString() );
       //encapsulate the A
       public void removeCd()
            readOperation theRo = new readOperation();
            String keyword = theRo.readString("Please enter CD `s title you are going to remove : ") ;
            ArrayList<MusicCd> removeMusicCdResult = new ArrayList<MusicCd>();
                  System.out.println("The CD that you just removed  is " + keyword );
              for(MusicCd tempCd : removeMusicCdResult)
                   System.out.println( tempCd.toString() );
       //problem occurs here : i am so confused of how to remove the exactly stuff from my arrayList
       //pls help
       private ArrayList<MusicCd> removeCdForTitle(String removeCdsTitle)
             MusicCd tempMusicCd = new MusicCd();
             tempMusicCd.setTitle(removeCdsTitle);
            // tempMusicCd.setTitle(removeCdsTitle);
            //tempMusicCd.getTitle() = removeCdsTitle;
            ArrayList<MusicCd> removeMusicCdResult = new ArrayList<MusicCd>();
            for(MusicCd currentMusicCd : MusicCdList)
                 if((currentMusicCd.getTitle()).equals(tempMusicCd.getTitle()))
                     // removeMusicCdResult.remove(currentMusicCd);
                         MusicCdList.remove(currentMusicCd);
            removeMusicCdResult.trimToSize();
            return removeMusicCdResult;
       private ArrayList<MusicCd> searchForTitle(String searchString)
            ArrayList<MusicCd> searchResult = new ArrayList<MusicCd>();
            for(MusicCd currentMusicCd : MusicCdList)
                 if((currentMusicCd.getTitle()).indexOf(searchString) != -1)
                      searchResult.add(currentMusicCd);
            searchResult.trimToSize();
            return searchResult;
    import java.util.*;
    public class MusicCdStoreEngine{
         public static void main(String[] args)
              MusicCdStore mcs = new MusicCdStore( );
              mcs.insertCd();
              //display the Cd that you just insert
              mcs.displayAllCd();
              mcs.removeCd();
              mcs.displayAllCd();
              mcs.searchingMusicCd();
    //Acutally result
    //Please enter your CD`s title : ivan
    //Please enter your CD`s year of release : 1992
    //Do you have another Cd ? (Y/N) : y
    //Please enter your CD`s title : hero
    //Please enter your CD`s year of release : 1992
    //Do you have another Cd ? (Y/N) : n
    //Our CD collection is:
    // Music Cd`s Title: ivan     Year of release: 1992
    //Music Cd`s Title: hero     Year of release: 1992     
    //Please enter CD `s title you are going to remove : hero
    //The CD that you just removed  is hero
    //Our CD collection is:
    // Music Cd`s Title: ivan     Year of release: 1992
    //Music Cd`s Title: hero     Year of release: 1992     
    //Enter a CD `s Title you are going to search : hero
    //The search results for hero are:
    //Music Cd`s Title: hero     Year of release: 1992
    //>Exit code: 0
    //Expected result
    //Please enter your CD`s title : ivan
    //Please enter your CD`s year of release : 1992
    //Do you have another Cd ? (Y/N) : y
    //Please enter your CD`s title : hero
    //Please enter your CD`s year of release : 1992
    //Do you have another Cd ? (Y/N) : n
    //Our CD collection is:
    // Music Cd`s Title: ivan     Year of release: 1992
    //Music Cd`s Title: hero     Year of release: 1992     
    //Please enter CD `s title you are going to remove : hero
    //The CD that you just removed  is hero
    //Our CD collection is:
    // Music Cd`s Title: ivan     Year of release: 1992
    //Music Cd`s Title: hero     Year of release: 1992<<-- it is not supposed to display cos i have deleted it from from array     
    //Enter a CD `s Title you are going to search : hero
    //The search results for hero are:
    //Music Cd`s Title: hero     Year of release: 1992<<-- i should have get this reuslt...cos it is already delete from my array
    //>Exit code: 0
    import java.util.*;
    public class readOperation{
         public String readString(String userInstruction)
              String aString = null;
              try
                         Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   aString = scan.nextLine();
              catch (NoSuchElementException e)
                   //if no line was found
                   System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
              catch (IllegalStateException e)
                   // if this scanner is closed
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aString;
         public char readTheFirstChar(String userInstruction)
              char aChar = ' ';
              String strSelection = null;
              try
                   //char charSelection;
                         Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   strSelection = scan.next();
                   aChar =  strSelection.charAt(0);
              catch (NoSuchElementException e)
                   //if no line was found
                   System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
              catch (IllegalStateException e)
                   // if this scanner is closed
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aChar;
         public int readInt(String userInstruction) {
              int aInt = 0;
              try {
                   Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   aInt = scan.nextInt();
              } catch (InputMismatchException e) {
                   System.out.println("\nInputMismatchException error occurred (the next token does not match the Integer regular expression, or is out of range) " + e);
              } catch (NoSuchElementException e) {
                   System.out.println("\nNoSuchElementException error occurred (input is exhausted)" + e);
              } catch (IllegalStateException e) {
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aInt;
    }

    //problem occurs hereI'm not sure that the problem does occur within the
    removeCdForTitle() method.
    Your main() method calls removeCd() which obtains the title of
    the CD to be removed (keyword). But remoceCd() never
    calls removeCdForTitle(), so nothing is ever removed.

  • Problem in parsing XML using DOM

    I am getting one XML file as string like <?xml version="1.0" encoding="ISO-8859-1" ?> <DMSI-ACTIVITY-COMMENTS> </DMSI-ACTIVITY-COMMENTS>
    Every time I want to add new node <ACTIVITY>
              <NAME></NAME>
              <ID></ID>
              <COMMENT></COMMENT>
         </ACTIVITY> whenever user make any change in my application.
    I wrote code....
    InputStream inputStream = new ByteArrayInputStream(file.getBytes());
    Document doc = docBuilder.parse(inputStream);
    Element activityNode = doc.createElement("ACTIVITY");
    Element nameNode = doc.createElement("NAME");
    activityNode.appendChild(nameNode);
    Text nametextNode = doc.createTextNode(name);
    nameNode.appendChild(nametextNode);
    Element root = doc.getDocumentElement();
    root.appendChild(activityNode);
    String resultUDA = doc.toString();
    Problem: Here I am getting value of resultUDA is [#document: null]. I need updated XML as String....
    any one can give me suggestion or any other option to solve this issue...
    thanks in advance...

    I got it ....pls check on it
    http://www.theserverside.com/discussions/thread.tss?thread_id=26060

  • How to access checkbox in mx:list

    I'm trying to access the checkboxes in my list
    <mx:List itemRenderer="mx.controls.CheckBox" x="0" y="153" id="listVocab" height="297" width="313"></mx:List>
    but I can't find a way. This is what I'm doing
            for(var i:int = 0 ; i < listVocab.numChildren; i++)
                    if (  I want to access the checkbox here to see if it's checked  then do the below but I don't know how to access the checkboxes??? )
                    // This gives me access to the text but                 
                   var word:String = listVocab.dataProvider[i].toString() ;

    Problem is with dataProvider your assigning to dataGrid is of type Array of Strings so thats why its saying selected property is not available on String.
    Code given above by me will work for arrayCollection having objects of following type instead of just plain strings:
    public class CustomClass
             public var data:String; // here id you can store
            public var label:String; // here word you can store
            public var selected:Boolean;
    You can make modification to
    public class CustomVocabulary
            public var sentence:String;
            public var type:String;
            public var dbId:String;
            public var words:ArrayCollection; // this will contain objects of type CustomClass.
    <mx:List id="list" dataProvider="{ customVocabulary.words }"

  • Migration of Fxcop Custom Rules to Visuatl Studio 2012

    I have an existing custom rule which was written in visual studio 2008 using fxocp SDK 1.35 and Microsoft.CCI 1.35. Now i am migrating it to latest version of Fxcop 11.0 and Microsoft .cci 11.0 using Vistual Studio 2012.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    //using Microsoft.FxCop.Sdk.Introspection;
    //using Microsoft.Cci;
    using Microsoft.FxCop.Sdk;
    using System.Collections;
    using System.IO;
    namespace LDOFxCopCustomRules.Rules.Design
    class DisposableObjectsShouldBeDisposed : BaseDesignRules
    string sFileName = System.Configuration.ConfigurationSettings.AppSettings["FolderForOutput"] + "\\" + @"DisposableObjectsShouldBeDisposed.Xls";
    bool bDisplayErrors = String.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["FolderForOutput"]);
    //string sExceptionLogFileName = @"D:\RTE.txt";
    static string sLockString = "Lock";
    string sFormat = "{0}\t{1}\t{2}\t{3}\n";
    string sAssemblyName;
    string sClassName;
    string sLineNumber;
    // Fields
    private Hashtable m_fieldsOwnedByType;
    private Hashtable m_fieldsWithDispose;
    private Method m_method;
    // Methods
    public DisposableObjectsShouldBeDisposed()
    : base("DisposableObjectsShouldBeDisposed")
    this.m_fieldsWithDispose = new Hashtable();
    this.m_fieldsOwnedByType = new Hashtable();
    if (!bDisplayErrors && !File.Exists(sFileName))
    if (!bShowInAllReport)
    lock (sLockString)
    File.WriteAllText(sFileName, string.Format(sFormat, "Assembly", "Class", "Method (fully qualified name)", "Line number"));
    public override ProblemCollection Check(Member member)
    string sTemp = member.FullName;
    bool bFinally = false;
    bool bDataReader = false;
    bool bDisposedCalled = false;
    int nDataReaderCount = 0;
    Local oCheckLocal;
    Method oMethod = null;
    int nCurrent = 0;
    InstructionList oList = null;
    this.m_method = RuleUtilities.GetMethod(member);
    if (this.m_method == null)
    return null;
    this.m_fieldsWithDispose.Clear();
    this.m_fieldsOwnedByType.Clear();
    //if (!this.m_method.DeclaringType.IsAssignableTo(SystemTypes.IDisposable))
    // return null;
    //if (RuleUtilities.ExtendsControl(this.m_method.DeclaringType))
    // return null;
    //if (!RuleUtilities.IsDisposeBool(this.m_method) && (!RuleUtilities.IsDisposeMethod(this.m_method) || HasDisposeBoolMethod(this.m_method.DeclaringType)))
    // return null;
    if (this.m_method.DeclaringType.IsAssignableTo(SystemTypes.IDisposable))
    if (RuleUtilities.ExtendsControl(this.m_method.DeclaringType))
    return null;
    if (!RuleUtilities.IsDisposeBool(this.m_method) && (!RuleUtilities.IsDisposeMethod(this.m_method) || HasDisposeBoolMethod(this.m_method.DeclaringType)))
    return null;
    sClassName = m_method.DeclaringType.Name.Name;
    sAssemblyName = m_method.DeclaringType.DeclaringModule.ContainingAssembly.ModuleName;
    MemberList members = this.m_method.DeclaringType.Members;
    for (int i = 0; i < members.Length; i++)
    switch (members[i].NodeType)
    case NodeType.Field:
    Field field = members[i] as Field;
    if (!field.IsStatic && field.Type.IsAssignableTo(SystemTypes.IDisposable))
    this.m_fieldsWithDispose[field] = null;
    break;
    case NodeType.InstanceInitializer:
    case NodeType.Method:
    this.VisitMethod(members[i] as Method);
    break;
    new DisposeVisitor(this.m_fieldsWithDispose).Visit(this.m_method);
    if (this.m_fieldsWithDispose.Count > 0)
    foreach (Field field2 in this.m_fieldsWithDispose.Keys)
    if (this.m_fieldsOwnedByType.Contains(field2))
    string str = RuleUtilities.Format(this.m_method.DeclaringType);
    string str2 = RuleUtilities.Format(field2.Type);
    sLineNumber = field2.SourceContext.StartLine.ToString();
    Problem item = new Problem(base.GetResolution(new string[] { str, field2.Name.Name, str2 }), field2.Name.Name);
    if (bDisplayErrors)
    base.Problems.Add(item);
    else
    if (bShowInAllReport)
    lock (LockClass.objLockAllReport)
    File.AppendAllText(sSingleReportName, string.Format(sSingleReportFormat, sAssemblyName, sClassName, m_method.FullName, sLineNumber, "DisposableObjectsShouldBeDisposed"));
    else
    lock (sLockString)
    File.AppendAllText(sFileName, string.Format(sFormat, sAssemblyName, sClassName, m_method.FullName, sLineNumber));
    else
    if (member.NodeType == NodeType.Method)
    oMethod = member as Method;
    // The below block is to identify if any of the method's class is implemented from the interface IDataReader.
    // If that is the case, the method will be skipped and next method will be picked.
    // Ideally, this should be changed to scanning each class, skipping if it has implemented IDataReader and then
    // scan the methods for proper usage of IDataReader. But due to time constraints, this change is not done
    TypeNode typ = oMethod.DeclaringType;
    InterfaceList intList = typ.Interfaces; // get the list of interfaces of the class and check for IDataReader
    foreach (Interface intf in intList)
    if (intf.FullName.Contains("IDataReader"))
    return null;
    // Start the actual logic
    if (oMethod != null)
    oList = oMethod.Instructions;
    Instruction oInstruction;
    for (nCurrent = 0; nCurrent < oList.Length; nCurrent++)
    oInstruction = oList[nCurrent];
    if (oInstruction.OpCode == OpCode._Locals)
    LocalList oLocalList = oInstruction.Value as LocalList;
    int nCount = oLocalList.Length;
    for (int nIdx = 0; nIdx < nCount; nIdx++)
    if (oLocalList[nIdx].Type.Name.Name == "IDataReader")
    bDataReader = true;
    nDataReaderCount++;
    if (nDataReaderCount > 0)
    if (oInstruction.OpCode == OpCode._Finally)
    bFinally = true;
    if (bFinally)
    if (oInstruction.OpCode == OpCode.Callvirt)
    oCheckLocal = oList[nCurrent - 1].Value as Local;
    if (oCheckLocal != null && oCheckLocal.Type != null && oCheckLocal.Name != null && oCheckLocal.Type.Name.Name != null && oCheckLocal.Type.Name.Name == "IDataReader")
    bDisposedCalled = true;
    //nDataReaderCount--;
    // Microsoft.FxCop.Sdk.Problem oProblem = new Microsoft.FxCop.Sdk.Problem(base.GetResolution(sTemp1), oMethod.Name.Name);
    if (bDataReader && !bDisposedCalled)
    sClassName = oMethod.DeclaringType.Name.Name;
    sAssemblyName = oMethod.DeclaringType.DeclaringModule.ContainingAssembly.ModuleName;
    sLineNumber = nCurrent > 0 && nCurrent < oList.Length? oList[0].SourceContext.StartLine.ToString().Trim() : string.Empty;
    if (bDisplayErrors)
    Microsoft.FxCop.Sdk.Problem oProblem = new Microsoft.FxCop.Sdk.Problem(base.GetResolution(sTemp), sClassName);
    base.Problems.Add(oProblem);
    else
    if (bShowInAllReport)
    lock (LockClass.objLockAllReport)
    File.AppendAllText(sSingleReportName, string.Format(sSingleReportFormat, sAssemblyName, sClassName, m_method.FullName, sLineNumber, "DisposableObjectsShouldBeDisposed"));
    else
    lock (sLockString)
    File.AppendAllText(sFileName, string.Format(sFormat, sAssemblyName, sClassName, oMethod.FullName, sLineNumber));
    return base.Problems;
    private static bool HasDisposeBoolMethod(TypeNode type)
    MemberList members = type.Members;
    int num = 0;
    int length = members.Length;
    while (num < length)
    Method method = members[num] as Method;
    if ((method != null) && RuleUtilities.IsDisposeBool(method))
    return true;
    num++;
    return false;
    public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
    MemberBinding target = assignment.Target as MemberBinding;
    if (target != null)
    Field boundMember = target.BoundMember as Field;
    if (((boundMember != null) && (boundMember.DeclaringType == this.m_method.DeclaringType)) && (assignment.Source is Construct))
    this.m_fieldsOwnedByType[boundMember] = null;
    return base.VisitAssignmentStatement(assignment);
    // Properties
    public override TargetVisibilities TargetVisibility
    get
    return TargetVisibilities.All;
    // Nested Types
    private class DisposeVisitor : StandardVisitor
    // Fields
    private Hashtable m_fieldsWithDispose;
    private Method m_method;
    private Hashtable m_recursionCache = new Hashtable();
    private Hashtable m_variableToFieldMap = new Hashtable();
    // Methods
    internal DisposeVisitor(Hashtable fieldsWithDispose)
    this.m_fieldsWithDispose = fieldsWithDispose;
    public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
    Local target = assignment.Target as Local;
    if (target != null)
    MemberBinding source = assignment.Source as MemberBinding;
    if (source != null)
    Field boundMember = source.BoundMember as Field;
    if ((boundMember != null) && (boundMember.DeclaringType == this.m_method.DeclaringType))
    this.m_variableToFieldMap[target] = boundMember;
    return base.VisitAssignmentStatement(assignment);
    public override Method VisitMethod(Method method)
    this.m_method = method;
    return base.VisitMethod(method);
    public override Expression VisitMethodCall(MethodCall call)
    MemberBinding callee = call.Callee as MemberBinding;
    if (callee != null)
    Method boundMember = callee.BoundMember as Method;
    if (boundMember == null)
    return base.VisitMethodCall(call);
    MemberBinding targetObject = callee.TargetObject as MemberBinding;
    Field key = null;
    if (targetObject == null)
    Local local = callee.TargetObject as Local;
    if (local != null)
    key = this.m_variableToFieldMap[local] as Field;
    else
    key = targetObject.BoundMember as Field;
    if (((key != null) && this.m_fieldsWithDispose.ContainsKey(key)) && (((boundMember.Name.Name == "Dispose") || (boundMember.Name.Name == "Close")) || ((boundMember.Name.Name == "Clear") && boundMember.DeclaringType.IsAssignableTo(FrameworkTypes.HashAlgorithm))))
    this.m_fieldsWithDispose.Remove(key);
    else if ((boundMember.DeclaringType == this.m_method.DeclaringType) && !this.m_recursionCache.Contains(boundMember))
    this.m_recursionCache[boundMember] = null;
    this.VisitMethod(boundMember);
    return base.VisitMethodCall(call);
    Below errors are raised. Please let me know the solution
    1. Error 2 Inconsistent accessibility: base class 'Microsoft.FxCop.Sdk.StandardVisitor' is less accessible than class 'LDOFxCopCustomRules.Rules.Design.DisposableObjectsShouldBeDisposed.DisposeVisitor' D:\LDOFxCopCustomRules\DisposableObjectsShouldBeDisposed.cs 287 23 LDOFxCopCustomRules
    Error 3 'Microsoft.FxCop.Sdk.StandardVisitor' is inaccessible due to its protection level D:\LDOFxCopCustomRules\DisposableObjectsShouldBeDisposed.cs 287 40 LDOFxCopCustomRules
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    //using Microsoft.FxCop.Sdk.Introspection;
    //using Microsoft.Cci;
    using Microsoft.FxCop.Sdk;
    using System.Collections;
    using System.IO;
    namespace LDOFxCopCustomRules.Rules.Design
    class AvoidUnusedParameters : BaseDesignRules
    string sFileName = System.Configuration.ConfigurationSettings.AppSettings["FolderForOutput"] + "\\" + @"AvoidUnusedParameters.Xls";
    bool bDisplayErrors = String.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["FolderForOutput"]);
    //string sExceptionLogFileName = @"D:\RTE.txt";
    static string sLockString = "Lock";
    string sFormat = "{0}\t{1}\t{2}\t{3}\n";
    string sAssemblyName;
    string sClassName;
    string sLineNumber;
    private Hashtable m_parameterUsage;
    public AvoidUnusedParameters()
    : base("AvoidUnusedParameters")
    this.m_parameterUsage = new Hashtable();
    if (!bDisplayErrors && !File.Exists(sFileName))
    if (!bShowInAllReport)
    lock (sLockString)
    File.WriteAllText(sFileName, string.Format(sFormat, "Assembly", "Class", "Method (fully qualified name)", "Line number"));
    public override ProblemCollection Check(Member member)
    Method method = member as Method;
    if (!ShouldAnalyze(method))
    return null;
    this.m_parameterUsage.Clear();
    if (CallGraph.FunctionPointersFor(method).Length > 0)
    return null;
    if (method.DeclaringType.IsAssignableTo(SystemTypes.Delegate))
    return null;
    if (RuleUtilities.IsEventHandling(method))
    return null;
    if (RuleUtilities.IsVisualBasicModule(method.DeclaringType.DeclaringModule) && (method.Name.Name == "Dispose__Instance__"))
    return null;
    if (RuleUtilities.HasCustomAttribute(method, SystemTypes.ConditionalAttribute))
    return null;
    for (int i = 0; i < method.Instructions.Length; i++)
    switch (method.Instructions[i].OpCode)
    case OpCode.Ldarg_0:
    case OpCode.Ldarg_1:
    case OpCode.Ldarg_2:
    case OpCode.Ldarg_3:
    case OpCode.Ldarg_S:
    case OpCode.Ldarga_S:
    case OpCode.Ldarg:
    case OpCode.Ldarga:
    Parameter parameter = method.Instructions[i].Value as Parameter;
    this.m_parameterUsage[parameter] = null;
    break;
    sClassName = method.DeclaringType.Name.Name;
    sAssemblyName = method.DeclaringType.DeclaringModule.ContainingAssembly.ModuleName;
    sLineNumber = method.SourceContext.StartLine.ToString();
    for (int j = 0; j < method.Parameters.Length; j++)
    Parameter key = method.Parameters[j];
    if (!this.m_parameterUsage.ContainsKey(key))
    FixCategories breaking = FixCategories.Breaking;
    if (!method.IsVisibleOutsideAssembly)
    breaking = FixCategories.NonBreaking;
    string str = RuleUtilities.Format(method);
    string name = method.Parameters[j].Name.Name;
    Problem item = new Problem(base.GetResolution(new string[] { name, str }), name);
    item.FixCategory = breaking;
    if (bDisplayErrors)
    base.Problems.Add(item);
    else
    if (bShowInAllReport)
    lock (LockClass.objLockAllReport)
    File.AppendAllText(sSingleReportName, string.Format(sSingleReportFormat, sAssemblyName, sClassName, method.FullName, sLineNumber, "AvoidUnusedParameters"));
    else
    lock (sLockString)
    File.AppendAllText(sFileName, string.Format(sFormat, sAssemblyName, sClassName, method.FullName, sLineNumber));
    this.m_parameterUsage.Clear();
    return base.Problems;
    private static bool IsVSUnitTestInitializer(Method method)
    if ((method.IsStatic && (method.ReturnType == SystemTypes.Void)) && ((method.Parameters.Length == 1) && (method.Parameters[0].Type.Name.Name == "TestContext")))
    for (int i = 0; i < method.Attributes.Length; i++)
    AttributeNode node = method.Attributes[i];
    if ((node.Type.Name.Name == "AssemblyInitializeAttribute") || (node.Type.Name.Name == "ClassInitializeAttribute"))
    return true;
    return false;
    private static bool ShouldAnalyze(Method method)
    if (method == null)
    return false;
    if ((method.Parameters.Length == 0) && method.IsStatic)
    return false;
    if (method.IsVirtual)
    return false;
    if (method.IsExtern)
    return false;
    if (method.IsAbstract)
    return false;
    if (RuleUtilities.IsFinalizer(method))
    return false;
    if (method.Name.Name == "__ENCUpdateHandlers")
    return false;
    Module declaringModule = method.DeclaringType.DeclaringModule;
    if (method.Name.Name.StartsWith("__", StringComparison.Ordinal) && RuleUtilities.IsAspAssembly(declaringModule))
    return false;
    if (RuleUtilities.IsISerializableConstructor(method))
    return false;
    if (IsVSUnitTestInitializer(method))
    return false;
    if (RuleUtilities.MethodOrItsTypeMarkedWithGeneratedCode(method))
    return false;
    return true;
    // Properties
    public override TargetVisibilities TargetVisibility
    get
    return TargetVisibilities.All;
    Below Errors are raised
    Error 8 The name 'SystemTypes' does not exist in the current context D:\AvoidUnusedParameters.cs 53 49 LDOFxCopCustomRules
    Error 9 'Microsoft.FxCop.Sdk.RuleUtilities' does not contain a definition for 'IsVisualBasicModule' D:\AvoidUnusedParameters.cs 61 27 LDOFxCopCustomRules
    Error 11 'Microsoft.FxCop.Sdk.BaseIntrospectionRule.FixCategories' is a 'property' but is used like a 'type' D:\AvoidUnusedParameters.cs 98 17 LDOFxCopCustomRules
    Error 12 The best overloaded method match for 'Microsoft.FxCop.Sdk.RuleUtilities.Format(Microsoft.FxCop.Sdk.AttributeNode)' has some invalid arguments D:\AvoidUnusedParameters.cs 103 30 LDOFxCopCustomRules
    Error 13 Argument 1: cannot convert from 'Microsoft.FxCop.Sdk.Method' to 'Microsoft.FxCop.Sdk.AttributeNode' D:\AvoidUnusedParameters.cs 103 51 LDOFxCopCustomRules
    Error 14 The name 'SystemTypes' does not exist in the current context D:\AvoidUnusedParameters.cs 136 55 LDOFxCopCustomRules
    Error 16 The type or namespace name 'Module' could not be found (are you missing a using directive or an assembly reference?) D:\LDOFxCopCustomRules\AvoidUnusedParameters.cs 180 9 LDOFxCopCustomRules
    Error 17 'Microsoft.FxCop.Sdk.RuleUtilities' does not contain a definition for 'IsAspAssembly' D:\AvoidUnusedParameters.cs 181 90 LDOFxCopCustomRules
    Error 18 'Microsoft.FxCop.Sdk.RuleUtilities' does not contain a definition for 'MethodOrItsTypeMarkedWithGeneratedCode' D:\AvoidUnusedParameters.cs 193 27 LDOFxCopCustomRules

    Hi sathishkumarV,
    I am trying to involve someone familiar with this topic to further look at this issue. There might
    be some time delay. Appreciate your patience.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • File I/O and encoding (J2SDK 1.4.2 on Windows)

    I encountered a strange behavior using the FileReader / Writer classes for serializing the contents of a java string. What I did was basically this:
    String string = "some text";
    FileWriter out = new FileWriter(new File("C:/foo.txt"));
    out.write(string);
    out.flush();
    out.close();In a different method, I read the contents of the file back:
    FileReader in = new FileReader(new File("C:/foo.txt"));
    StringWriter out = new StringWriter();
    char[] buf = new char[128];
    for (int len=in.read(buf); len>0; len=in.read(buf)) {
        out.write(buf, 0, buf.length);
    out.flush(); out.close(); in.close();
    return out.toString();Problems arise as soon as the string contains non ascii characters. After writing and reading, the value of the string differs from the original. It seems that different character encodings are used when reading and writing, although the doc states that, if no explicit encoding is specified, the platform's default encoding (in my case CP1252) will be used.
    If I use streams directly instead of writers, it does not work, either, as long as I do not specify the encoding when converting bytes to strings and vice versa.
    When I specify the encoding (no matter which one, as long as I specify the same for reading as for writing), the resulting string is equal to the original one.
    If I replace the FileReader and Writer by StringReader and StringWriter (bypassing the serialization), it works, too (without specifying the encoding).
    Is this a bug in the file i/o classes or did I miss something?
    Thanks for your help
    Ralph

    first.... if you are writing String objects via serialization, encoding doesn't matter whatsoever. Not sure you were saying you tried that, but just for future reference.
    For String.getBytes() and String(byte[]) or InputStreamReader and OutputStreamWriter: If you don't specify an encoding, the system default (or default specified on the command-line or set in some other way) will be used in all cases.
    For byte streams: If you are reading/writing bytes thru streams, then the character conversion is up to you. You call getBytes on a string or create a string with the byte[] constructor.
    For readers/writers: If you are reading/writing characters thru readers/writers, then the character conversion is done by that class.
    However, StringReader and StringWriter are just writing to/from String objects and they are writing Unicode char's, so it's really a special case.
    Okay...
    So if you have a string which has characters outside the range of the encoding being used (default or explicitly specified), then when it's written to the file, those characters are messed up. So say you have a Chinese character which needs 2 bytes. Generally, the 2 bytes are written, but when read back, that one character shows as 2. Whether 2 bytes are written or 1, probably depends on the encoding. But the result is the same, you get a munged up string.
    Generally speaking, you are going to get better storage on most text when using UTF-8 as your encoding. You need to specify it always for reads and writes, or set it as the default. The reason is that chars are written in as many bytes as needed. And it'll support anything Unicode supports, thus anything String supports.

  • Java program HELPPPP!!!!!

    Hello, I'm very new to Java programming, and well I'm taking Computer Science as my major, and I need a little help to this program:
    You will develop an inheritance hierarchy of classes to enhance your understanding of inheritance, encapsulation, and polymorphism.
    All classes developed must be complete including:
    appropriate symbolic constants
    appropriate data fields
    constructors (default, complete, and, if appropriate, partial)
    accessor methods
    mutator methods
    standard methods inherited and overridden from Object:
    boolean equals(Object other)
    String toString()
    problem specific methods
    The project involves working with washers. A Washer is a circular metallic disc with its circular center removed. As such, the relevant data fields for a washer are:
    the outer diameter (OD) of the larger circle
    the inner diameter (ID) of the smaller circle
    the thickness of the disc
    When constructing or mutating these data fields remember that they need to be validated such that all fields are greater than zero and the outer diameter must be larger than the inner diameter (use helper methods for validation so that the code only appears once).
    In addition to the Washer class you will also need to define two derived classes based on the type of metal used for the washer. These will be BrassWasher and SteelWasher. Brass has a density of 8.4 g/cm3 while steel has a density of 7.8 g/cm3 (both of these numbers are approximate since both metals are alloys and their densities depend on the composition of the alloys). The densities should be defined as symbolic constants in the appropriate derived classes.
    The problem specific methods needed are:
    double volume()
    double weight()
    These should be placed in the appropriate classes.
    The main program (in class TestWashers) will create an array of Washer instances (generate reasonable values for the inner and outer diameters and thickness of the washers as well as the material types by using random numbers (see Math.random())) (discussed in class and look up the documentation). The program will then compute the total weight of the collection of washers as stored in the array. The program will display the list of washers (i.e., by using toString() for each array element) and then the total weight of the whole collection of washers (properly annotated).
    My question is what should I put in the Washer class? you know the parent class. Because I'm confuse on the boolean equals(object other) and String toString(), and the double volume and double weight.
    and how to do the Math.random()?
    This is the program that my teacher told us to do, but I'm having problems on how to start.
    Thanks.

    Please change your code tags. Even you must see that they aren't working.
    You can do this by changing your curly braces to square braces[code]
    Your code is still editable so you can do this without having to repost the whole thing.
    regarding toString: if you wanted a quick way to represent what data a Washer object contains, what would this one line string look like?  Model your toString() after this.
    regarding your equals: what object variables need to be all equal for two washers to be the same type?  Write an equals method to match that.  Note that equals must be passed an object as its parameter.  So the first thing you must do is check to make sure that the passed parameter object is in fact a Washer object (use instanceOf for this).  If not, return false.
    Edited by: Encephalopathic on Oct 1, 2008 7:28 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem with inheritance and outputting values in toString.

    Hey guys, i'm having a major problem with inheritances.
    What i'm trying to do with my program is to create objects in my demo class. Values are passed to several other objects that each do their own calculations of grades and results and then outputs the result in my toString. I followed step by step the instructions in my book on how to setup the inheritance and such. I can only output everything that was created in my superclass, any other thing that was created in an object that belongs to a subclass does not display in the output at all.
    Even if I change or create new instance variables, I can't figure out for the life of myself how to output the other values.
    Because there's so much code to be splitting on the forums, I zipped my whole project in a RAR. I'll link it here
    http://www.4shared.com/file/ZleBitzP/Assign7.html
    The file to run the program is CourseGradesDemo class, everything else is either a subclass or superclass to some part of the program. After you run CourseGradesDemo, you will see the output, and understand what displays and what stays at 0.0 value. If anyone can help me out with this it would be greatly appreciated
    Thanks in advance.

    Basshunter36 wrote:
    Hey guys, i'm having a major problem with inheritances.
    What i'm trying to do with my program is to create objects in my demo class. Values are passed to several other objects that each do their own calculations of grades and results and then outputs the result in my toString. I followed step by step the instructions in my book on how to setup the inheritance and such. I can only output everything that was created in my superclass, any other thing that was created in an object that belongs to a subclass does not display in the output at all.
    Even if I change or create new instance variables, I can't figure out for the life of myself how to output the other values.No idea what you're talking about. Provide an [url http://sscce.org]SSCCE.
    Because there's so much code to be splitting on the forums, I zipped my whole project in a RAR. I'll link it here
    http://www.4shared.com/file/ZleBitzP/Assign7.html
    Not gonna happen. Provide an [url http://sscce.org]SSCCE. And don't say you can't. You definitely can. You may have to spend an hour building a new program from scratch and getting it to reproduce the problem, but if you can't or won't do that, you'll find few people here willing to bother with it.

  • 4.1.1 new theme cloudy 24 problem with javascript toString

    the following statement works fine for theme 21 but when I change the theme to new cloudy 24 it is giving error
    var origAction = $('button[value=Create]').attr('onclick').toString();
    Uncaught TypeError: Cannot call method 'toString' of undefined

    Hi pkpanda,
    I think the problem is that theme 24 is using the &lt;a> tag to render buttons instead of using the &lt;button> tag that's why you jQuery selector will not find anything.
    Which causes the "Cannot call method 'toString' of undefined", because toString is not a valid method for undefined.
    Change your selector to
    var origAction = $('#YOUR_BUTTON_STATIC_ID').attr('href').toString();and set the "Static ID" attribute of your button to a unique name within your page. First of all this will perform better and second it also has the advantage that if somebody changes the "label" of your button or code will not break.
    Regards
    Patrick
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • Problem with Float.toString

    Hi,
    I have a small problem with wrapper class Float.
    For example
    float f = 99999999999999999f;
    f.toString(); returns a mentioned in the api doc: 9.9999999999999999E16
    while I wanted the original 17 times a 9,
    how can I achieve this??
    THX

    I tried to use the DecimalFormat class with the patter 17 * #, but the string it prints is no longer the same as in the original Float (17 * 9), now I get 17 chars but they are no all 9

  • Problem Using toString method from a different class

    Hi,
    I can not get the toString method to work from another class.
    // First Class Separate file MyClass1.java
    public class MyClass1 {
         private long num1;
         private double num2;
       public MyClass1 (long num1, double num2) throws OneException, AnotherException {
            // Some Code Here...
        // Override the toString() method
       public String toString() {
            return "Number 1: " + num1+ " Number 2:" + num2 + ".";
    // Second Class Separate file MyClass2.java
    public class MyClass2 {
        public static void main(String[] args) {
            try {
               MyClass1 myobject = new MyClass1(3456789, 150000);
               System.out.println(myobject);
             } catch (OneException e) {
                  System.out.println(e.getMessage());
             } catch (AnotherException e) {
                  System.out.println(e.getMessage());
    }My problem is with the System.out.println(myobject);
    If I leave it this way it displays. Number 1: 0 Number 2: 0
    If I change the toSting method to accept the parameters like so..
    public String toString(long num1, double num2) {
          return "Number 1: " + num1 + " Number 2:" + num2 + ".";
       }Then the program will print out the name of the class with some garbage after it MyClass1@fabe9. What am I doing wrong?
    The desired output is:
    "Number 1: 3456789 Number 2: 150000."
    Thanks a lot in advance for any advice.

    Well here is the entire code. All that MyClass1 did was check the numbers and then throw an error if one was too high or too low.
    // First Class Separate file MyClass1.java public class MyClass1 {
         private long num1;
         private double num2;
         public MyClass1 (long num1, double num2) throws OneException, AnotherException {              
         // Check num2 to see if it is greater than 200,000
         if (num2 < 10000) {
                throw new OneException("ERROR!:  " +num2 + " is too low!");
         // Check num2 to see if it is greater than 200,000
         if (num2 > 200000) {
                throw new AnotherException ("ERROR!:  " +num2 + " is too high!");
         // Override the toString() method
         public String toString() {
              return "Number 1: " + num1+ " Number 2:" + num2 + ".";    
    // Second Class Separate file MyClass2.java
    public class MyClass2 {
        // Main method where the program begins.
        public static void main(String[] args) {
            // Instantiate first MyClass object.
            try {
               MyClass1 myobject = new MyClass1 (3456789, 150000);
               // if successful use MyClass1 toString() method.
               System.out.println(myobject);
                         // Catch the exceptions within the main method and print appropriate
                         // error messages.
             } catch (OneException e) {
                  System.out.println(e.getMessage());
             } catch (AnotherException e) {
                  System.out.println(e.getMessage());
             }I am not sure what is buggy. Everything else is working fine.

  • Having some problems with toString method.

    Hi well my toString method is fine but what I don't understand is why am I getting the ouput for the toString where I am not supposed to.
    import java.text.DecimalFormat;
        public class Sphere
       //Variable Declarations.
          private int diameter;
          private double radius;
       //Constructor: Accepts and initialize instance data.
           public Sphere(int sp_diameter)
             diameter = sp_diameter;     
             radius =(double)diameter/2.0;
       //Set methods: Diameter
           public void setDiameter(int new_diameter)
             diameter = new_diameter;
             radius = (double) diameter/2.0;
       //Get methods: Diameter
           public int getDiameter()
             return diameter;
       //Compute volume and surface area of the sphere
           public double getVolume()
             return  4 * Math.PI * radius * radius * radius / 3;
           public double getArea()
             return  4 * Math.PI * radius * radius;
       //toString method will return one line description of the sphere
           public String toString()     
             DecimalFormat fmt1=new DecimalFormat("0.###");
             String result = "Diameter : " + fmt1.format(diameter)+ "\tVolume: " + fmt1.format(getVolume()) + "\tArea: " +fmt1.format(getArea());
             return result; // This is fine .. the problem is the driver
    Driver
           public static void main(String[]args)
             Sphere sphere1, sphere2, sphere3;
             sphere1 = new Sphere(10);
             sphere2 = new Sphere(12);
             sphere3 = new Sphere(20);
             System.out.println("The sphere diameter are: "); //Here is the problem  for the output I only want the diameter, but I am getting the toString output here too..
             System.out.println("\tFirst Sphere diameter is: " + sphere1);
             System.out.println("\tSecond Sphere diameter is: "+ sphere2);
             System.out.println("\tThird Sphere diameter is: " + sphere3);
          //Prints the Sphere Volume and  Surface Area.
             DecimalFormat fmt = new DecimalFormat("0.###");
             System.out.println("\nTheir Volume and Surface Area: ");
             System.out.println("\tSphere1: " + "Volume: " + fmt.format(sphere1.getVolume()) + "\tSurface Area: " + fmt.format(sphere1.getArea()));
             System.out.println("\tSphere2: " + "Volume: " + fmt.format(sphere2.getVolume()) + "\tSurface Area: " + fmt.format(sphere2.getArea()));
             System.out.println("\tSphere3: " + "Volume: " + fmt.format(sphere3.getVolume()) + "\tSurface Area: " + fmt.format(sphere3.getArea()));
          //Change the diameter of the sphere.
             sphere1.setDiameter(11);
             sphere2.setDiameter(15);
             sphere3.setDiameter(25);
             System.out.println("\nNew diameter is: ");
             System.out.println("\tFirst Sphere diameter is: " + sphere1);
             System.out.println("\tSecond Sphere diameter is: " + sphere2);
             System.out.println("\tThird Sphere diameter is: " + sphere3);
          //Prints the Sphere Volume and  Surface Area.
             System.out.println("\nTheir Volume and Surface Area: ");
             System.out.println("\tSphere1: " + "Volume: " + fmt.format(sphere1.getVolume()) + "\t\tSurface Area: " + fmt.format(sphere1.getArea()));
             System.out.println("\tSphere2: " + "Volume: " + fmt.format(sphere2.getVolume()) + "\tSurface Area: " + fmt.format(sphere2.getArea()));
             System.out.println("\tSphere3: " + "Volume: " + fmt.format(sphere3.getVolume()) + "\tSurface Area: " + fmt.format(sphere3.getArea()));
          //Using the toString Method.
             System.out.println("\nFirst sphere: " + sphere1);
             System.out.println("\nSecond sphere: " + sphere2);
             System.out.println("\nThird sphere: " + sphere3);
     

    System.out.println("The sphere diameter are: "); //Here is the problem for the output I only want the diameter, but I am getting the toString output here too..
    System.out.println("\tFirst Sphere diameter is: " + sphere1);
    System.out.println("\tSecond Sphere diameter is: "+ sphere2);
    System.out.println("\tThird Sphere diameter is: " + sphere3);
    If you only want the Diameter, than use a formatter and get the diameter like you did when you printed the surface area and volume. Or, print shpere1.getDiameter();
    You have already demonstrated the solution to your problem elsewhere in your code, I think you need to re-read and understand what you have done so far.

  • Problems with toString()

    This is probably a weird question, but how do I get this program to return the result using toString()? It's for a homework assignment...
    import java.util.Scanner;
    public class LED_Digit {
         private int myTop, myTopBothSides, myTopLeft, myTopRight, myMiddle, myBottomBothSides, myBottomLeft, myBottomRight, myBottom;
         public void drawLED_Digit(int top, int topBothSides, int topLeft, int topRight, int middle, int bottomBothSides, int bottomLeft,
                   int bottomRight, int bottom) {
         for (int t = 1; t <= top; t++) {
              System.out.print(" - "); }
              System.out.println();
         for (int tbth = 1; tbth <= topBothSides; tbth++) {
              System.out.println("|   |");}
         for (int tl =1; tl <= topLeft; tl++) {
                   System.out.println("|   "); }
         for (int tr = 1; tr <= topRight; tr++) {
                   System.out.println("    |"); }
         for (int m = 1; m <= middle; m++) {
                   System.out.print(" - "); }
         for (int bbth = 1; bbth <= bottomBothSides; bbth++) {
                   System.out.println();
                   System.out.println("|   |");}
         for (int bl = 1; bl <= bottomLeft; bl++) {
                   System.out.println();
                   System.out.println("|   "); }
         for (int br = 1; br <= bottomRight; br++) {
                   System.out.println();
                   System.out.println("    |"); }
         for (int b = 1; b <= bottom; b++) {
                   System.out.print(" - "); }
         myTop = top;
         myTopBothSides = topBothSides;
         myTopLeft = topLeft;
         myTopRight = topRight;
         myMiddle = middle;
         myBottomBothSides = bottomBothSides;
         myBottomLeft = bottomLeft;
         myBottomRight = bottomRight;
         myBottom = bottom;
         public static void main(String[] args) {
              Scanner keyboard = new Scanner(System.in);
              System.out.print("What is the number? " );
              int num = keyboard.nextInt();
              findDig(num);
         public static void findDig(int num) {
         if (num == 0) {
              LED_Digit zero = new LED_Digit();
              zero.drawLED_Digit(2, 3, 0, 0, 0, 0, 0, 0, 2);
              System.out.println(); }
         else if (num == 1){
              LED_Digit one = new LED_Digit();
              one.drawLED_Digit(0, 0, 0, 4, 0, 0, 0, 0, 0);
              System.out.println(); }
         else if (num == 2) {
              LED_Digit two = new LED_Digit();
              two.drawLED_Digit(2, 0, 0, 1, 2, 0, 1, 0, 2);
              System.out.println(); }
         else if (num == 3) {
              LED_Digit three = new LED_Digit();
              three.drawLED_Digit(2, 0, 0, 1, 2, 0, 0, 1, 2);
              System.out.println(); }
         else if (num == 4) {
              LED_Digit four = new LED_Digit();
              four.drawLED_Digit(0, 1, 0, 0, 2, 0, 0, 1, 0);
              System.out.println(); }
         else if (num == 5) {
              LED_Digit five = new LED_Digit();
              five.drawLED_Digit(2, 0, 1, 0, 2, 0, 0, 1, 2);
              System.out.println(); }
         else if (num == 6) {
              LED_Digit six = new LED_Digit();
              six.drawLED_Digit(2, 0, 1, 0, 2, 1, 0, 0, 2);
              System.out.println(); }
         else if (num == 7) {
              LED_Digit seven = new LED_Digit();
              seven.drawLED_Digit(2, 0, 0, 1, 0, 0, 0, 1, 0);
              System.out.println(); }
         else if (num == 8) {
              LED_Digit eight = new LED_Digit();
              eight.drawLED_Digit(2, 1, 0, 0, 2, 1, 0, 0, 2);
              System.out.println(); }
         else if (num == 9) {
              LED_Digit nine = new LED_Digit();
              nine.drawLED_Digit(2, 1, 0, 0, 2, 0, 0, 1, 2); }
         else {
              System.err.println("Not a valid digit"); }
    }

    That seems like it puts me more on the right track, but I must be doing it wrong because now it says I have a "NullPointerException". And I'm still not sure how to incorporate toString() (it is at the bottom of the code).
    import java.util.Scanner;
    public class LED_Digit {
         static StringBuilder sb;
         public void drawLED_Digit(int top, int topBothSides, int topLeft, int topRight, int middle, int bottomBothSides, int bottomLeft,
                   int bottomRight, int bottom) {
         for (int t = 1; t <= top; t++) {
                   sb.append(" - "); }
                   sb.append('\n');
         for (int tbth = 1; tbth <= topBothSides; tbth++) {
                   sb.append("|   |" + '\n');}
         for (int tl =1; tl <= topLeft; tl++) {
                   sb.append("|   " + '\n'); }
         for (int tr = 1; tr <= topRight; tr++) {
                   sb.append("    |" + '\n'); }
         for (int m = 1; m <= middle; m++) {
                   sb.append(" - "); }
         for (int bbth = 1; bbth <= bottomBothSides; bbth++) {
                   sb.append('\n');
                   sb.append("|   |" + '\n');}
         for (int bl = 1; bl <= bottomLeft; bl++) {
                   sb.append('\n');
                   sb.append("|   " + '\n'); }
         for (int br = 1; br <= bottomRight; br++) {
                   sb.append('\n');
                   sb.append("    |" + '\n'); }
         for (int b = 1; b <= bottom; b++) {
                   sb.append(" - "); }
         public static void main(String[] args) {
              Scanner keyboard = new Scanner(System.in);
              System.out.print("What is the number? " );
              int num = keyboard.nextInt();
              findDig(num);
              StringBuilder();
         public static void StringBuilder() {
              // TODO Auto-generated method stub
              System.out.print(sb);
         public static void findDig(int num) {
         if (num == 0) {
              LED_Digit zero = new LED_Digit();
              zero.drawLED_Digit(2, 3, 0, 0, 0, 0, 0, 0, 2);}
         else if (num == 1){
              LED_Digit one = new LED_Digit();
              one.drawLED_Digit(0, 0, 0, 4, 0, 0, 0, 0, 0);}
         else if (num == 2) {
              LED_Digit two = new LED_Digit();
              two.drawLED_Digit(2, 0, 0, 1, 2, 0, 1, 0, 2); }
         else if (num == 3) {
              LED_Digit three = new LED_Digit();
              three.drawLED_Digit(2, 0, 0, 1, 2, 0, 0, 1, 2);}
         else if (num == 4) {
              LED_Digit four = new LED_Digit();
              four.drawLED_Digit(0, 1, 0, 0, 2, 0, 0, 1, 0);}
         else if (num == 5) {
              LED_Digit five = new LED_Digit();
              five.drawLED_Digit(2, 0, 1, 0, 2, 0, 0, 1, 2);}
         else if (num == 6) {
              LED_Digit six = new LED_Digit();
              six.drawLED_Digit(2, 0, 1, 0, 2, 1, 0, 0, 2); }
         else if (num == 7) {
              LED_Digit seven = new LED_Digit();
              seven.drawLED_Digit(2, 0, 0, 1, 0, 0, 0, 1, 0);}
         else if (num == 8) {
              LED_Digit eight = new LED_Digit();
              eight.drawLED_Digit(2, 1, 0, 0, 2, 1, 0, 0, 2); }
         else if (num == 9) {
              LED_Digit nine = new LED_Digit();
              nine.drawLED_Digit(2, 1, 0, 0, 2, 0, 0, 1, 2); }
         else {
              System.err.println("Not a valid digit"); }
         public String toString() { return ; }
    }

  • Vector.toString creates problems!!

    here goes a chunk of code
    /*unChkedValues is of type java.util.Vector and is not empty*/
           int size = unChkedValues.size();
            String tempStr="";
            for(int k =0 ; k < size; k++){
                tempStr = unChkedValues.elementAt(k).toString();
                System.out.println(tempStr);
            }Lets suppose unChkedValues Vector contains "abc" in first compartment and "def" in the second and the loops iterates two times then the program should print
    abc
    defbut the program always prints
    abc
    abcwhat is the reason?

    I think its working fine....
    chk this
    Vector unChkedValues=new Vector();
              unChkedValues.add("abc");
              unChkedValues.add("def");
              unChkedValues.add("ght");
    int size = unChkedValues.size();
    String tempStr="";
    for(int k =0 ; k < size; k++){
    tempStr = unChkedValues.elementAt(k).toString();
    System.out.println(tempStr);
    }

Maybe you are looking for

  • Assignment Number updation

    Hi, Scenario 1: Contract --> Invoice --> Credit memo Request --> Credit Memo. In the above process cycle, we have the contract number appearing in the assignment number field of the credit memo - As desired. Scenario 2: Sales Order --> Returns Order

  • Calling secured webservices from BPEL 10.1.3.5 (oc4j)

    Hi all, I'm trying to call a username/password secured service on a SAP system - it works perfectly with SoapUI. After some time I managed to get it working also in BPEL with <property name="basicHeaders">credentials</property> <property name="basicU

  • Cloning : hot cloning and cold cloning

    hi how to clone in EBS R12.I am a core DBA student currenly working as trainee in EBS dba. can anyone explain .... i am requesting some details on hot cloning , cold cloning and user managed cloning techniques. in user managed cloning i need to run a

  • OBI - Migration between environments

    Does anyone have a best practice document or even a document on how to migrate reports from OBI 10.1.3.4 between a dev to prod environment? Can't seem to find anything on the Oracle website.

  • Chances of getting IOS 7.1.2 instead of 8 on iPhone 5s

    Hey guys, I wanted to know what is the chance of me getting an iPhone 5s 64gb from Apple's express replacement service on IOS 7.1.2(or any version of 7.1.x) instead of 8. I have battery issues with my phone and the people at the genius bar refuse to