Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!

Mark Vedder

Ranch Hand
+ Follow
since Dec 17, 2003
Mark likes ...
IntelliJ IDE Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mark Vedder

Here are some useful troubleshooting tips that might help you understand what is going wrong (and better understand the point Wouter and Jesper make). These are useful things you can use in this situation, and in the future when your code is not doing what you are expecting. Try to do one, or both, of the following:

1. Change your loop as follows:

This will let you know where you are in the loop as things are printed out. It will shed some light onto what is happening. How many times are you looping? Is this the nubmer of times you are expecting.

2. Try changing the output so you place each array value in a single quote.

This way you can see for sure what the value of b[i] is. Is it what you are expecting?


These tips should help you see the issue.

Also carefully reread Jesper's post from Dec 4 @ 2:44PM. It explains what the problem is. Attention to detail is a critical skill to develop as a programmer.

>
8 years ago
The DailyRollingFileAppender is not designed to have the date in the "current" log's name. It is designed such that the current log is named something like MyLog.log, and then as it rolls, the archived logs are named Mylog_2010-11-15.log.

From the javadoc of DailyRollingFileAppender:

For example, if the File option is set to /foo/bar.log and the DatePattern set to '.'yyyy-MM-dd, on 2001-02-16 at midnight, the logging file /foo/bar.log will be copied to /foo/bar.log.2001-02-16 and logging for 2001-02-17 will continue in /foo/bar.log until it rolls over the next day.



As a side note, the RollingFileAppender in LogBack (a newer Logging Framework, written by the same people that first developed log4j, intended to be a successor to log4j) is more sophisticated and can be configured such that the "current" log name has the date in it. It can also be set to only keep x number of rolled logs (for example 60 days), deleting any older logs. This is a shortcoming of the DailyRollingFileAppender in Log4j as it cannot be configured to clean up old logs. You can use the Simple Logging Facade for Java (SLF4J) API to make it so LogBack handles all the Log4J logging for a project/application that uses log4j. It's as simple as replacing the log4j.jar file in your classpath with the log4j-over-sl4fj.jar from the SLF4J API and putting the logback jar in the classpath. Then replace your log4j configuration file with a logback configuration file. See the SLF4J Bridging legacy APIs page for details. Logback brings a number of advantages to the table over log4j. See the Reasons to prefer logback over log4j page for more information. (I use to be a log4j fanatic until I discovered SLF4J and Logback. Now that is the logging framework I evangelize, as you can probably tell.)
I was not aware that you were using Front Man (or any other framework). I am not familiar with Front Man beyond knowing it is a Web App front Controller. As such, my previous comments may not apply since Front Man may provide functionality to do what you are attempting to accomplish.

Also, can you indicate what your goal is. My initial understanding of your question was that you wanted it so that if someone navigated to a single resource, namely www.mysite.com and only www.mysite.com, that they would be redirected (not forwarded) to www.mysite.com/command/index. The suggestion I made would only work for people navigating to www.mysite.com. If they navigated to www.mysite.com/page1.html they would not be redirected to www.mysite.com/command/index nor to www.mysite.com/command/index/page1.html. Also, I suggested a redirect, not a forward (see below). However, it now looks like you may be attempting to put access control in place so that if an a non authenticated user (i.e. some one that is not logged in) navigates to any resource in your web application, they are redirected to a log in page. Or are you trying to make it so that any request is sent through a Controller?


Redirect vs Forward
As I mentioned in my initial post, it is important to understand the difference between a forward and a redirect. Let's say I have a very basic page called somePage.html that is nested in the directory docs/info. In other words, you navigate to www.mysite.com/docs/info/somePage.html to view that page. That page contains a relative link to anotherPage.html such that the anchor tag contains the attribute href="anotherPage.html". Therefore, if I navigate to www.mysite.com/docs/info/somePage.html and click on the link, I go to www.mysite.com/docs/info/anotherPage.html.

If I have a redirect configured to handle requests to "/" and redirect those requests to /docs/info/somePage.html, when I go to www.mysite.com the web server sends a redirect back to the client (i.e. the browser) to the page /docs/info/somePage.html. The browser URL shown in the browser address bar changes from www.mysite.com to www.mysite.com/docs/info/somePage.html and the browser submits a new request to the web server for www.mysite.com/docs/info/somePage.html. As a result, when the browser displayes the page, the relative link on the page resolves to www.mysite.com/docs/info/anotherPage.html.

By contrast, if instead I have a forward configured to handle requests to "/", when a user goes to www.mysite.com, the web server internally gets the content from /docs/info/somePage.html and returns it to the client. The client is unaware of this. As such, the URL in the address bar does not change. So the URL still reads www.mysite.com. Moreover, the relative link on the page resolves to www.mysite.com/anotherPage.html. This is most likely an incorrect resolution of the URL. There are times (mostly in the case of servlet mappings rather than html pages) that this may be desirable.

So the use case for a forward and a redirect are different. They each have there uses depending on the goal.


Can you please clarify what your goal is. I will likely need to bow out of the discussion since I am not familiar with Front Man and I do not want to give you incorrect information on how to accomplish your goal if Front Man potentially provides functionality to accomplish your goal. Someone else familiar with the framework can jump in to help. But I think they too will need some clarification of your goal in order to better assist you. (Also, this thread may need to be moved by a bartender to the Other Application Frameworks forum if that is the case).
8 years ago

John Schretz wrote:Im trying to figure out how this mapping relates to the url on the browser.
I guess maybe im not grasping the entire mapping concept correctly. In the past I would map all my servlets individually begining with the root /



Sorry... I forgot to comment on this. A servlet mapping is different than the welcome list. As I mentioned in my first reply, since the welcome list applies to all partial URL's (i.e. "directories") and is appended to the partial URL, a leading slash does not make sense. However, with servlet mapping, they are absolute mappings from the root of the web application and therefore require a leading slash. That's why there is a difference. See section 12.2 of the servlet specification for information on the what patterns are allowed in a URL mapping for a servlet.
8 years ago

John Schretz wrote:
How come one works and the other doesnt?


Per section 10.10 of the Servlet Specification:

Servlet 3.0 Specification wrote:
If a Web container receives a valid partial request, the Web container must examine the welcome file list defined in the deployment descriptor. The welcome file list is an ordered list of partial URLs with no trailing or leading /. The Web server must append each welcome file in the order specified in the deployment descriptor to the partial request and check whether a static resource in the WAR is mapped to that request URI. If no match is found, the Web server MUST again append each welcome file in the order specified in the deployment descriptor to the partial request and check if a servlet is mapped to that request URI. The Web container must send the request to the first resource in the WAR that matches. The container may send the request to the welcome resource with a forward, a redirect, or a container specific mechanism that is indistinguishable from a direct request. (Emphasis added)



The reason for this is that the welcome file list applies to ALL paths within a web app. It is the default file to load when going to a "directory". So a leading slash does not make sense. By default, the web server will look for index.html. So if I navigate to example.com/stuff, the web server will look for the page /stuff/index.html (that is example.com/stuf/index.html). If I navigate to example.com/more/things, the web server will look for the page /more/things/index.html. I can use the welcome-file-list to override, or added to, the list of files I want the web server to look for when a partial URL is provided.

John Schretz wrote:
So how would I then If I were to go to www.mysite.com
Have the url display as www.mysite.com/command/index and my home page display automatically?



Map a redirect Servlet (or JSP) to the root context. Have that redirect servlet redirect the client to /command/index. Be sure you understand Forward versus redirect.
8 years ago
Take a look at Chapter 6 of the Advanced Data Visualization Developer Guide from Adobe. It has a nice chart listing the additional capabilities of the AdvancedDataGrid.
9 years ago

Bryan Peach wrote:ok forget about the tyoe casting i got that figureed out... but now when i go to compile i get a null pointer exception in the main method somewhere... does anyone know how to remedy that?



Can you post the entire exception you are getting, along with your new code. I can then teach you how to read an exception stack trace so you can answer your question yourself. A much more valuable outcome.
9 years ago
Your getAverage method is declared to return an int. However, the math you perform results in a double, which is a floating point number. You want to assign that calculation to avgocc, which is a double. So that's fine. However, you cannot use avgocc as the return value since it is a double and your method is declared to return an int. So you either need to cast it to an int (option 1) and lose precision (2 vs 2.4) before you return it, or your method needs to be declared to return a double rather than an int (option 2).



Since your avgocc variable is a double, and since it makes more sense that an average be a floating number (unless your requirements say otherwise) I think option two is the better one.

You have some other issues looming. I'll comment on them in a another post.
9 years ago
Is there a classmate that attend the class you missed that might be able to provide you with notes? Or at least can give you a better general idea of what your teacher discussed?

Can't you contact the teacher? Most teacher's today do provide their e-mail addresses. (Or is this not a college class?)

If we at least had a good starting point to know what concepts or topics where discussed, we might be able to help better. If you have only been programming for two weeks, then I would agree that the CardLayout is a bit advanced for where you are likely at in your studies. At the same time, I cannot see a teacher discussing the topic that it sounds like you are describing in the second or third week of a course. And the topic/example you mentioned in your original post sounds like a classic example for discussing the CardLayout class. So we all may misunderstanding the problem/topic you are asking for guidance on.

What have you learned so far? That might also help us determine a starting point to help you.
9 years ago
Dog(String, Double, String, int) is the signature of the constructor. It is saying the constructor takes those types. Your actual constructor, in your original post, was:

See how the types line up in the signature I posted?

When you call the constructor, you need to pass in actual values:
9 years ago

Bryan Peach wrote:I have to create this Dog class and then two Sub-classes called WorkingDog and PetDog... How do i link them? just by having them in the same package?



No, sinply putting them in the same package will not result in them being subclasses. Think about it logically... how would the compiler know that PetDog is a subclass of Dog and not the other way around? There is nothing telling the compiler of such a relationship. The keyword extends is used to create a subclass:




Bryan Peach wrote:
And the idea is if its a working dog i have to get certain information, but if its a pret dog i need different information... where would i make the distinction to branch off into either of the two subclasses and how do i make the distinction?



Anything that is common to all Dogs goes in the Dog class. Since a PetDog extends Dog, it knows everything a Dog knows (there's a bit more detail involved in this, but for know, you can work off that statement.) Anything specific only to a pet dog goes in the PetDog class. And anything specific to a working dog class goes into the WorkingDog class.


Bryan Peach wrote:
hahaha ok stupid me... i got the errors figured out. Now this is the last thing... I promise... in my driver is it saying that: cannot find symbol constructor Dog()... Whats that all about?



In your Dog class, you only have a constructor Dog(String, Double, String, int) but in your DogDriver class you are trying to call the no-arg (i.e. no argument) constructor Dog(). So you either need to call the correct constructor in your DogDriver class (the one that takes all the information needed to construct a dog) or you need to add a no argument constructor to the Dog class. I think, based on what I am seeing in your code, you want to do the first thing.
9 years ago

Bryan Peach wrote:yeah i got that figured out and working now... but now at my date constructor it is saying that its an invalid method declaration.... but its not even a method declaration... do you see whats wrong with it? Constructors really boggle my mind



A constructor is for constructing, or creating a new instance of, a particular class. The constructor exists within the same class and is named the same thing as the class. So your Dog class has Dog constructors, and can only have Dog constructors. Anything else in the class is a method. You cannot have a Date constructor in your Dog class. And there is no reason you ever should. What does a Dog know about creating a Date? A Dog can only know how to create himself. A Cat only knows how to create, or construct, a Cat, not a Dog. So a Cat cannot have a Dog constructor. And a Date only knows how to create a Date.

Now if a Dog needs to use a Date, the Dog class calls the Dog class' constructor. The Dog class goes not declare a Date constructor, it calls the Date constructor that resides in the Date class. That call can occur in a number of places, such as in the Dog's constructor itself, or in a method within the Dog class. Unfortunately, creating dates is a little more complex that if you want to create a Date other than today, you create a date trough a Calendar.

Do you really need a Date, with a day, month, and year? or do you just need the age (an int)? I ask since I see your Dog constructor is taking an int, which can be used to represent the Dog's age, but not a date.
9 years ago
I'm not familiar with JBuilder. But it sounds like your problem is more with how to use that IDE than it is with how to code java. That is one reason I, along with many others, am a proponent of not using an IDE when first learning to program. You spend more time learning the tool than programming. Or you can't tell what are problems with the tool and what are problems with your code.

That being said, I'll see what I can do to help. Maybe someone else that knows JBuilder can jump in as well.

Have you tried compiling your code using the command line to see what happens?

What do yo mean by "when i try to move DogDriver into the Dog file"? I'm not understanding why you are trying to "move" DogDriver into the Dog file. By move, do you mean dragging the DogDriver file into the Dog file? The two classes should be in separate files. While you could put them in the same file under certain circumstances, doing such is a little beyond where you are I believe in your programming experience.

<edit>
Sorry, I was tying my reply to your first reply when yo posted your second. I'll answer that one now.
9 years ago

Bryan Peach wrote:Please help. I have to create a class Dog and then implement a driver for that class. I have done both and am now trying to test both but when i go to compile the driver I get this message :cannot find symbol class Dog. I am not sure how to delcare another class, or how to import the class Dog or whatever it is i have to do. Please Help. here is the code...



Since Dog and DogDriver are both part of the Pet package, you do need an import statement for Dog in the DogDriver class. Based on what I am seeing in the sample code you posted, you should not be getting the particular error -- cannot find symbol class Dog -- that you are getting. There are some other issues looming, but lets get you past this one first.

Are both your Dog.java and DogDriver.java files saved in a directory named Dog?

If not, they both need to be in that directory. If that is okay, can you post the command that you are using to compile along with the directory you in when you try to compile.
9 years ago
I haven't used TreeSelectionEvents much, so I cannot answer your question directly. But something that may help you is the following... and it may help you solve other problems in the future... If you go to the TreeSelectionEvent class, or any class or interface, in the JavaDoc API, at the top is a series of links with a light blue background: "Overview, Package, Class, Use, Tree, Deprecated, Index, Help". Click on the "Use" link. It will show you a list of all other (known) classes and methods that use that class. It will give you a list of methods that use that class as an argument, methods that return that class, public fields that have that class as a type, etc. In the case of the TreeSelectionEvent, there is a rather limited number methods that use it. From that you can probably find what you are looking for.

I hope that helps.
9 years ago