~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It is always a good solution to google for the base exception message. Chances are that someone else has already encountered this error and found a solution for the same. Searching around, it seems that using Glassfish + Eclipse has some problems when it comes to dealing with object persistence when the entity class is updated. Are you using Glassfish with eclipse? If that blog post doesn't solve your issue, then read some other articles and see if that helps.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is there a quick way to create a constructor, or any method for that matter, where the type of data structure created is decided when the method is called

Yes, the new Java collections API is full of examples of the same. Pick any class from the collections API and look at its source to get a feel of how things are done. Read a bit about generics and you are good to go.

comSysStudent commented: concise, to the point, excellent links +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

One should declare a String paker[][]= new String[4][13]; to store all (52) the cards

IMO better to have a "Card" class with "rank" and "suit" as member variables. The toString() of this class would take care of concatenating the toString() method output of the respective "card" and "rank" enum members. Here is a simple example taken from the Java specification:

import java.util.*;
public class Card implements Comparable<Card>, java.io.Serializable {
    public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN,JACK, 
QUEEN, KING, ACE }
    public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
    private final Rank rank;
    private final Suit suit;
    private Card(Rank rank, Suit suit) {
        if (rank == null || suit == null)
            throw new NullPointerException(rank + ", " + suit);
        this.rank = rank;
        this.suit = suit;
    }
    public Rank rank() { return rank; }
    public Suit suit() { return suit; }
    public String toString() { return rank + " of " + suit; }
    // Primary sort on suit, secondary sort on rank
    public int compareTo(Card c) {
        int suitCompare = suit.compareTo(c.suit);
        return (suitCompare != 0 ? suitCompare : rank.compareTo(c.rank));
    }
    private static final List<Card> prototypeDeck = new ArrayList<Card>(52);
    static {
        for (Suit suit : Suit.values())
            for (Rank rank : Rank.values())
                prototypeDeck.add(new Card(rank, suit));
    }
    // Returns a new deck
    public static List<Card> newDeck() {
        return new ArrayList<Card>(prototypeDeck);
    }
}

In API one may see Enum class while in coding one sees enum. Hence I would ask what is the differences between Enum and …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
I know there's more to this than just helping the OP, etc. But seriously, could this be done? The profile panel of an idiot would then have some sort of icon (only visible to the idiot-applying user of course).

Use the ignore list feature provided by vBulletin. If I've added a member to the ignore list, all the posts by that user would be hidden by default and a message would be shown. Something like:

Access the ignore list feature here .

BTW, you are not on my ignore list, it was just for demonstration purposes. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You guys don't know what's an anime

There is nothing wrong with having ones own preferences. BTW, there are many other *better* anime out there apart from the mainstream ones you mentioned.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Would it be possible to have a tutorials forum where people can post tutorials where admin can sort through to transfer/edit/delete into the appropriate positions

Unfortunately that would attract more spammers/content thieves than members who are genuinely interested in posting tutorials. More like one more forum to moderate for spam with the additional responsibility of checking the content for its originality.

Also another idea which I have brought up before is daniweb open source projects

You can of course start this initiative but it would IMO turn out to be a nightmare for the one who is mentoring. If no mentor is present for the project, it would be more like the "blind leading the blind". Not to mention being spammed by college kids for "enhancing" the project for their own use.

Of course I'm being a big pessimist here. But given that the developer community here at Daniweb isn't large, dedicated and experienced when compared to the "consumers", it would be difficult to pull off the stuff you are mentioning. But if you are planning on continuing with the open-source thing, good luck. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I've noticed how there seems to be a lack of 'talk' about JSP compared to PHP and ASP.NET on the web, lack of up-to-date 'printed' books and just news in general.

IMO, this kind of reasoning is flawed. Java is a pretty established language, as are C and C++. Do you still see a lot of C/C++ books these days? No. Can these languages be called dead? Hell no. You are confusing popularity/noise with liveness of a language or a framework. Sure, no one blogs about C/C++/Java these days, but that doesn't imply these languages are dead.

I get the impression that JSP is either 'dying' or never really took off and is just a bit of a niché language/environment (whatever the right term is).

View technology would be a right term. JSP's were primarily meant to reduce the effort required by a developer to render a view. Before JSP's web applications typically had this sort of code:

public void doGet(HttpServletRequest req, HttpServletResponse res) {
	PrintWriter out = // get printwriter
	out.println("<html><head><title>HELLO</title></head><body>");
	// a crapload of embedded HTML
	out.println("<p class=\"p\">Bye</p>")
}

Imagine having to render a complex view and maintaining it using the above syntax, yuck (btw, been there, done that, believe me, it's a nightmare). The solution? Come up with a view technology in which the content is given more importance and values are placed in placeholders on fly. Enter JSP. But then again, after writing a significant amount of JSP, developers realized its weakness (embedded Java code …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

also it gives me nullpointerxception though i have used a if condition specifying (c==null)

This is because the condition is executed after the length check of the for loop. The condition cookie == null needs to be placed outside the FOR loop and not inside it.

when i close my browser and open it for the next time, i should be able to get the value stored in the cookie

Set the maxAge of the cookie accordingly. Have you looked at the docs for the setMaxAge method? It says that the cookie is persisted for the number of seconds you pass in to the setMaxAge method which in your case is only 20. Set it to something higher like 60 * 60 * 24 for persisting the cookie for an entire day.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, the data is not "damaged" if the serialization is successful. You can use a debugger to confirm the same (inspect the fields of your de-serialized object). Also, it's not that the == "does not work", it's just that it has a difference purpose than the one which you seek.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

== compares object references or stands for reference equality which would never hold true for objects which are loaded from a serialized file after being saved. The serialization mechanism uses the serialized byte stream to create a *new* object having the same state as the original saved object. Override the equals method of the Object class for your custom classes if you need logical equality.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes. Simply put, you have an object (your application) whose behaviour needs to change based on the state of that object (password valid or not). Going back to the example I posted, the 'Application' object has a variable (part of application state) called `validationState`. In order to modify the behaviour of our application, we need to do a couple of things.

Create a common state interface which would the super-type for all the state objects created. So what method should this State interface have? This interface normally harbours methods which are called on your application object. In our case, the method is called `setValidationStage`. This method would be called whenever you need to modify the "state" of your validationStage variable. Since it is the behaviour of this "state change" which we want to abstract, internally, this method would call the relevant "State" object by passing in a reference to self. The difference between the `setValidationStage` method of the `Application` object and the `State` object is that, the State object requires a reference to the `Application` also called as "context" in the wiki article, to modify its behaviour. Hence our State object would have a method called `setValidationStage(Application, ValidationStage)`.

Notice that the reference to state object in the Application is of type `PasswordIndicatorState`. This property would be set to the default state when the application initializes; which in our case is the `DefaultPasswordIndicatorState`. So, how is all this put in action? When the user clicks on the "Validate" button, …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Thanks, Almost but still have empty slot. split seems a lot harder to use than StringTokenizer Regular Expressions can be tough to figure out.

No, not really. That's correct output because you are effectively asking it to "split" based on a whitespace. The empty slot is because there is a blank string before the whitespace. Simply use String#trim before splitting and it should work out fine for all cases.

String data = " there  are some spaces  here ";
String[] splitData = data.trim().split("\\s+");
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

String#split accepts a regular expression string. Just use the normal regular expression constructs and you should be fine:

String s = "there  are some spaces  here";
// \s here means any whitespace and + means one or more occurrences
String[] arr = s.split("\\s+");
// output: ["there", "are", "some", "spaces", "here"]

References:
http://www.regular-expressions.info/
http://www.javamex.com/tutorials/regular_expressions/

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, it seems that you'd have to use String#split to split the date into parts and validate each component (date, day, year) separately.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This allows you to compress the whiole interface/mutiple state classes thing into a single enum

...thereby making it view dependent and reducing its general purpose usability. IMO, enums are much more useful if treated as data containers rather than behaviour containers since a given enum can be applicable to more than one scenarios. Enum methods generally operate on their state variables without any dependence on the application state.

Also, how would the `paintBox` in your code exactly work? Won't it require some kind of reference to the paint component?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

also I don't understand the point of having this setStatus. it just sets a string right?

I posted an example for your understanding which you'd need to adjust according to your specific needs. The state class normally has an extra parameter which is the reference to the class whose behaviour you would want to control.

I was wondering if I could take up 3 static ints in my UI and use them as enums?

Yes, but enums are better for a lot others reasons, the most important being type safety.

is my code, as you can see the setState has 2 parameters, and my function has only 1 parameter within it. what do you suggest that I do?

It seems that you are still struggling with the concept behind using the state pattern otherwise you wouldn't have asked this question. Read the wiki article again along with this article.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't use a StringTokenizer or any sort of String splitter for validating dates. As already mentioned, use Date utility classes like SimpleDateFormat for validating dates unless the purpose of the exercise given to you is to implement Date validation. Also, StringTokenizer has been deprecated in favour of the String#split method.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I have an interface with a function, and 3 classes implementing interface...each class doing its own work. now I have to call up interface by making an object of it. then I utilize the function in my frame to call up different class via interface. thats what im assuming.. :/

Sounds good. You just have to make sure that any processing related to state variable which triggers change in state should be delegated to your current state implementation. A trivial example would look something like:

interface PasswordIndicatorState {
    void setValidationStage(Application app, ValidationStage stage);
}

class OkPasswordIndicatorState implements PasswordIndicatorState {
    @Override
    public void setValidationStage(Application app, ValidationStage stage) {
        if(stage == ValidationStage.DEFAULT) {
            app.setStatus("DEFAULT");
            app.setState(new DefaultPasswordIndicatorState());
        }
    }
}

class WrongPasswordIndicatorState implements PasswordIndicatorState {
    @Override
    public void setValidationStage(Application app, ValidationStage stage) {
        if(stage == ValidationStage.DEFAULT) {
            app.setStatus("DEFAULT");
            app.setState(new DefaultPasswordIndicatorState());
        }
    }
}

class DefaultPasswordIndicatorState implements PasswordIndicatorState {
    @Override
    public void setValidationStage(Application app, ValidationStage stage) {
        if(stage == ValidationStage.OK) {
            app.setStatus("OK");
            app.setState(new OkPasswordIndicatorState());
        } else if(stage == ValidationStage.WRONG) {
            app.setStatus("WRONG");
            app.setState(new WrongPasswordIndicatorState());
        }
    }
}

enum ValidationStage {
    DEFAULT, OK, WRONG
}

class Application {

    private PasswordIndicatorState state;

    private String status;

    private ValidationStage validationStage;

    private Application() {
        setState(new DefaultPasswordIndicatorState());
        setValidationStage(ValidationStage.DEFAULT);
    }

    public static Application newApplication() {
        return new Application();
    }

    public void setState(PasswordIndicatorState state) {
        this.state = state;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setValidationStage(ValidationStage stage) {
        this.validationStage = stage;
        this.state.setValidationStage(this, stage);
    }

}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

For all scenarios dealing with arbitrary precision calculations use BigInteger/BigDecimal.

class FactorialCalculator {
    public BigInteger compute(int num) {
        if(num < 0) {
            throw new IllegalArgumentException("negative number passed for factorial computation");
        }
        if(num < 2) {
            return BigInteger.ONE;
        }
        BigInteger factorial = BigInteger.ONE;
        while(num > 1) {
            factorial = factorial.multiply(BigInteger.valueOf(num--));
        }
        return factorial;
    }
}

BTW, for coding something which requires factorials, maintaining a hash of the number and its factorial is much more efficient as compared to computing it every time a factorial is request.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Depends on the scope of your bean and how your flow is structured. Does the JPS/Servlet which creates the bean is in the same flow as the JSP in which you want to access your bean? Is the bean placed in request/session scope?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hey i have one more question.
I am using eXist native XMl database, and want the jsp code to retrieve the stored xml file from db and show up in the browser.
How should i go about it. Right now i now how to retrieve a file present in the db, by registering the db inside the jsp code and giving file path and name.

My final aim is to have a jsp page showing up collections stored in the db, and the user can access the collection and see xml files in them, just read accessibility.

A better way would be to move the entire XML loading logic to a servlet. Also, register/load the required classes/resources only once instead of doing it for every request. Create your own context listener which would be invoked after the servlet context has been initialized (once for every web application as per servlet specification) and do the common loading and registration there. Your servlet should be smart enough to know the intent of the user. If the request is for something like "http://localhost:8080/myapp/all" then display the links to list of all the XML files you have in your database. If the URL is something like "http://localhost:8080/myapp/view/XXX", then show the XML file XXX to the user and so on. I hope you catch the drift..

Also, I've never worked with the native XMLDB product you mention so I won't know what would be an efficient way of …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The "tree" structure of XML is shown only if you render an XML file, not when you a try to render a XML file within an HTML. If your requirement is the latter i.e. to mix and match HTML and XML you'd need to use a Javascript library to emulate the same. For e.g. the following code works and shows a tree structured XML file in IE and FF:

<%@ page language="java" contentType="text/xml; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
 <head>
  <title>
    Insert title here
  </title>
 </head>
 <body>HI</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Of course, as per the same origin policy it won't work if you are requesting resources which are not part of the same domain. It was a sample snippet posted for someone who probably wasn't aware of Ajax hence the 'google' domain.

BTW, given that this policy is enforced on the client side, an initiative has been taken by Firefox by introducing a new header, which hopefully might get implemented as a standard in like say 10 years? :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The IP you get from whatsmyip.org is called the "face" IP or external IP. Normally this is the IP of your ISP's router which acts as a mediator between you and the internet hence binding to that IP fails. You can of course bind to any IP shown when you fire off the "ipconfig" command.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This seems to be a problem with content type of your servlet response. You need to set the content type to text/xml instead of text/html for the browser to render your response in a "tree" format.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Do you get any errors when starting the container? Also, you need to place the class file in a location which matches your package structure. Your test.Hello.class file should be placed in the 'test' folder in the classes directory.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Err.. sorry, but it's not impossible. Binding to the IP assigned by your network as well as the face IP assigned by your ISP works, *always*. The problem has got something to do with the IP that was being used or local settings/firewall settings enforced by your ISP/OS.

Anyways, good thing it worked out well for you. Good luck. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

As an experiment, ask your friend to use his IP address when starting the ServerSocket; does it still work?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I am looking for a coding project where I can learn proper
> software engineering technique.

Effort comes first, guidance next. Just think of something cool you've always wanted to implement and start off with whatever you have. Give it your best shot. It need not be pretty, it need not be awesome, it just needs to work the way you want it to be. The good thing about bad code is that it manifests itself. As your code grows, you might start realizing that things look a bit awkward and there surely must be a better way of doing things. *Then* start looking for projects which are similar to yours.

A better idea would be to try to mimic a small idea for which a good open source solution already exists. Comparing your code with the reference implementation after you are done would give you a new perspective on how things *could* have been done. Diving straight into any significant piece of open source code would only bore/detract you IMO. Good luck. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

As of Java 6, @Override annotation also works with interface methods implemented by classes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm personally a big fan of the way StackOverflow works. The voting system, the volunteers, the moderators etc. fit in so naturally. For a forum system wherein everything is dictated by the community, it is working out surprisingly well. Of course, there might be problems with the approach used by them, but they aren't glaringly apparent. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> How could i post the entire stack trace,

By copy pasting the entire error trace you see in your console. Anyways, have you tried out the suggestions from my previous post? If it still doesn't work, there is nothing I can do from here since this might very well be a firewall/OS configuration issue/any-other-thing.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It works at my place so it obviously has got something to do with the IP address you are using. Also, try a higher port value, like 8080, to make sure the problem isn't with lower ports being blocked. Also, like I said, post the *entire* stack trace unmodified and not just the first line.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Good design hides the implementation complexity, it doesn't do away with the complexity. When you say you need different representations (csv, xml, json etc.), the class creating the representation *needs* to know about the structure of the data to be converted, be it plain XML or a Java object. You say there won't be any Java object along the way. So how do you propose to retrieve data from a database/web-service? How will the resulting data look?

Post a sample code which shows "how" you'd like to see the code or a code sample for a fictional use case like getting a list of all employees using a web-service/database/socket connection. Also make sure you consider the entire flow instead of just posting your connection classes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use getByAddress instead of getByName since you are passing an IP address and not a host name.

byte[] ipBytes = new byte[] { 192, 192, 192, 192 };
InetAddress ip = InetAddress.getByAddress(ipBytes);
ServerSocket server = new ServerSocket(9090, -1, ip);
while(true) {
  Socket client = server.accept();
  // do stuff
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

"Crashes the server" isn't a very good description. Post the relevant code along with complete stack trace. Also, you don't pass in your WAN IP but *your* IP (assigned by your ISP or your network).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> That code wouldn't print anything, you can use Strings and equals

That code will always print "Hello" since both s and the literal "Hello" would refer to the same interned string.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The problem isn't with port but with the host. If you don't pass in a host, it defaults to 0.0.0.0 or 127.0.0.1 (not very sure here); which again gives rise to the scenario I explained in my previous post. Refer the three arg constructor of ServerSocket class for more details.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Are you by any chance spawing the server process by passing in the host as "localhost" or "127.0.0.1"? If yes, then AFAIK you need to replace the same with the IP address assigned by your network in case your friend is in the same network or the IP address assigned by your ISP in case he isn't.

Edit: Don't bump posts, at least not within 24 of posting your post. It'll just make you look demanding/impatient and will detract those trying to help you out.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So what exactly is EJB? I know the definition, but I can't get what exactly is! Is it the framework?

EJB (Enterpries Java Beans) is a specification drafted for creating "re-usable" business components, in the same way as "Servlet Specification" is used for creating "web components". Think of it as something which enables you develop and package your critical business functionality. The underlying mechanism uses a binary protocol (RMI/IIOP though I'm not sure) as opposed to the verbose and textual HTTP protocol.

A lot of smart people have debated over the uses/mis-uses of EJB; even I could have written down a couple of things but in the end it would just confuse you if you have just started with Java. I'd recommend staying away from EJB's unless you are pretty comfortable with other "more" useful things like the core language, servlet specification etc. :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If you post (as long as you're not the original poster) within a thread that is subsequently marked as 'solved' all posters in that thread get credit towards the 'solved' status

Also, it doesn't apply if you post *after* a thread has been marked as solved, for obvious reasons... :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, that's correct.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, I meant i1 since it is the variable which is initialized. Removing or adding the `final` quantifier to i1 changes the way the compiler treats the presented source code. If i1 is made final, the uninitialized state of i2 is acceptable since it is anyways going to get initialized in teh IF block. If not, the user is presented with a compile time error.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If i1 is not declared `final`, the compiler has no way of knowing in advance that the value of i1 won't change; hence it complains if you don't provide an ELSE clause. When i1 is declared as `final`, the compiler knows for sure that i1 will *always* be 9 and never change hence it stops complaining.

Even if you know for sure that i1 never changes before the IF check, the compiler is not *that* smart.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

the error is a compile time error.The error is:
VARIABLE MIGHT NOT HAVE BEEN INITIALISED

But after declaring the variable 'i as final' the code runs just fine. Y??

Because when you declare a variable as `final`, the compiler ensures that re-assignment to that variables never happens. Using static program analysis, the compiler can infer that the value of i1 will *always* be 9 in the given scope and can in turn infer that i2 will always be set to 8. In fact, a smart compiler might reduce the code to something like:

final int i1 = 9;
int i2 = 8;

// OR even this if i1 is never used again in the scope
int i2 = 8;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Which is why, in one of my previous posts I asked for the code of the method he is calling:

Which again is not required since by looking at the error message its pretty clear that it returns a list of strings. :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That still doesn't matter since the line db2Crns=testDB2Connect.getDb2LoggedInCrns(); would screw everything up if the method getDb2LoggedInCrns returns a raw list.

public class Tester {
	
	public static void main(final String[] args) {
		List<Integer> ints = new ArrayList<Integer>();
		ints = getList();
		ints.get(0).intValue();	// KABOOM!!!
	}

	private static List getList() {
		List<String> strings = new ArrayList<String>();
		strings.add("HI");
		return strings;
	}
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

i am getting error on this line

int x=db2Crns.get(i).intValue();---- line no 38

i tried to change below line to
int x=((Integer)db2Crns.get(i)).intValue();
but still same error is coming

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at com.kotak.autoblocknb.transaction.Transaction.main(Transaction.java:38)

db2Crns.get(i) returns a String and you are trying to cast it to an Integer hence the error. Use Integer.parseInt for parsing an integer from a string.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You are trying to print out a variable(i2) which is possibly uninitialized (depends on rutime, i2 won't be initialized if i1 < 3). Either provide an initial value for i2 or write an else statement which takes care of the same.