I have created a small application but I would now like to incorporate some type of logging that can be viewed via listbox. The source of the data can be sent from any number of places. I have created a new logging class that will pass in a delegate. I think Im close to a solution but Im receiving a NullReferenceException and I don’t know the proper solution. Here is an example of what Im trying to do:
Class1 where the inbound streaming data is received.
class myClass
{
OtherClass otherClass = new OtherClass();
otherClass.SendSomeText(myString);
}
Logging Class
class OtherClass
{
public delegate void TextToBox(string s);
TextToBox textToBox;
Public OtherClass()
{
}
public OtherClass(TextToBox ttb)
{
textToBox = ttb;
}
public void SendSomeText(string foo)
{
textToBox(foo);
}
}
The Form
public partial class MainForm : Form
{
OtherClass otherClass;
public MainForm()
{
InitializeComponent();
otherClass = new OtherClass(this.TextToBox);
}
public void TextToBox(string pString)
{
listBox1.Items.Add(pString);
}
}
Whenever I receive data in myClass, its throwing an error. Any help you could give would be appreciated.
Hi there,
I'm back again with my ongoing saga of Student-Project Allocation questions. Thanks to Moron (who does not match his namesake) I've got a bit of direction for an evaluation portion of my project.
Going with the idea of the Assignment Problem and Hungarian Algorithm I would like to express my data in the form of a .csv file which would end up looking like this in spreadsheet form. This is based on the structure I saw here.
| | Project 1 | Project 2 | Project 3 |
|----------|-----------|-----------|-----------|
|Student1 | | 2 | 1 |
|----------|-----------|-----------|-----------|
|Student2 | 1 | 2 | 3 |
|----------|-----------|-----------|-----------|
|Student3 | 1 | 3 | 2 |
|----------|-----------|-----------|-----------|
To make it less cryptic: the rows are the Students/Agents and the columns represent Projects/Task. Obviously ONE project can be assigned to ONE student. That, in short, is what my project is about. The fields represent the preference weights the students have placed upon the projects (ranging from 1 to 10). If blank, that student does not want that project and there's no chance of him/her being assigned such.
Anyway, my data is stored within dictionaries. Specifically the students and projects dictionaries such that:
students[student_id] = Student(student_id, student_name, alloc_proj, alloc_proj_rank, preferences)
where preferences is in the form of a dictionary such that
preferences[rank] = {project_id}
and
projects[project_id] = Project(project_id, project_name)
I'm aware that sorted(students.keys()) will give me a sorted list of all the student IDs which will populate the row labels and sorted(projects.keys()) will give me the list I need to populate the column labels. Thus for each student, I'd go into their preferences dictionary and match the applicable projects to ranks. I can do that much.
Where I'm failing is understanding how to create a .csv file. Any help, pointers or good tutorials will be highly appreciated.
I have the following code:
foo :: Int -> [String] -> [(FilePath, Integer)] -> IO Int
foo _ [] _ = return 4
foo _ _ [] = return 5
foo n nameREs pretendentFilesWithSizes = do
result <- (bar n (head nameREs) pretendentFilesWithSizes)
if result == 0
then return 0 -- <========================================== here is the error
else foo n (tail nameREs) pretendentFilesWithSizes
I get an error on the line with the comment above, the error is:
aaa.hs:56:2:
parse error (possibly incorrect indentation)
I'm working with emacs, there's no spaces, and i do not understand what did i do wrong.
Is it possible to put multiple IF statements in Javascript? If so, I'm having a fair amount of trouble with the statement below. I was wondering if you can put another IF statement in between if (data == 'valid') AND else? I want to add another if data =='concept') between the two.
if (data == 'valid') {
$("#file").slideUp(function () {
$("#file").before('<div class="approvedMessage">WIN WIN WIN!</div>');
setTimeout(ApprovedProof, 5000);
});
function ApprovedProof() {
$("#file").slideDown();
$('.approvedMessage').fadeOut();
}
}
else {
$("#file").slideUp(function () {
$("#file").before('<div class="deniedMessage">NO NO NO!</div>');
setTimeout(DeniedProof, 5000);
});
function DeniedProof() {
$("#file").slideDown();
$('.deniedMessage').fadeOut();
}
}
Hi people, I'm trying to validate an age field in a form but I'm having some problem. First I tried to make sure that the field will not be send empty. I don't know JavaScript so I searched some scripts and adapted them to this:
function isInteger (s)
{
var i;
if (isEmpty(s))
if (isInteger.arguments.length == 1)
return 0;
else
return (isInteger.arguments[1] == true);
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (!isDigit(c))
return false;
}
return true;
}
function isEmpty(s)
{
return ((s == null) || (s.length == 0))
}
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if ((validate_required(age,"Age must be filled out!")==false) ||
isInteger(age,"Age must be and int number")==false))
{email.focus();return false;}
}
}
//html part
<form action="doador.php" onsubmit="return validate_form(this)" method="post">
It's working fine for empty fields, but if I type any letters or characters in age field, it'll be sent and saved a 0 in my database. Can anyone help me?
Sorry for any mistake in English, and thanks in anvance for your help.
Hi all:
Basically what I mean is like this:
List<String[]> routes = (List<String[]>)application.getAttribute("routes");
For the above code, it tries to get an attribute named "routes" from the JSP implicit object - application. But as everyone knows, after this line of code, routes may very well contains a null - which means this application hasn't got an attribute named "routes".
Is this "casting on null" good programming practice in Java or not?
Basically I try to avoid exceptions such as java.io.InvalidCastException
I reckon things like this are more as "heritage" of Java 1.4 when generic types were not introduced to this language. So I guess everything stored in application attributes as Objects (Similar to traditional ArrayList). And when you do "downcast", there might be invalid casts.
What would you do in this case?
Update:
Just found that although in the implicit object application I did store a List of String arrays, when I do this :
List<double[]> routes = (List<double[]>)application.getAttribute("routes");
It doesn't produce any error... And I felt not comfortable already...
And even with this code:
out.print(routes.get(0));
It does print out something strange :
[Ljava.lang.String;@18b352f
Am I printing a "pointer to String"? I can finally get an exception like this:
out.print(routes.get(0)[1]);
with error :
java.lang.ClassCastException: [Ljava.lang.String;
Because it was me to add the application attribute, I know which type should it be cast to. I feel this is not "good enough", what if I forget the exact type?
I know there are still some cases where this sort of thing would happen, such as in JSP/Servlet when you do casting on session attributes. Is there a better way to do this?
Before you say:"OMG, why you don't use Servlets???", I should justify my reason as this: - because my uni sucks, its server can only work with Servlets generated by JSP, and I don't really want to learn how to fix issues like that. look at my previous question on this
, and this is uni homework, so I've got no other choice, forget all about war, WEB-INF,etc, but "code everything directly into JSP" - because the professors do that too. :)
"8,5,,1,4,7,,,,7,,1,9,3,6,,,8,6,3,9,,2,5,4,,,,,3,2,,,7,4,1,1,,4,,6,9,,5,,,,5,,,1,,6,3,,,6,5,,,,7,4,,1,7,6,,,,8,,5,,,7,1,,3,9,"
I'm doing a programming challenge where i need to parse this sequence into my sudoku script.
Need to get the above sequence into 8,5,0,1,4,7,0,0,0,7,0,1,9,3,6,0,0,8.........
I tried re but without success, help is appreciated, thanks.
The directoryReader gets you dirs in current dir in File[]-format.
Code
DirectoryReader data = new DirectoryReader();
File[] dirs = data.getDirsInDir(".");
File[] dirsMore = data.getDirsInDir("..");
// How can I append dirsMore to dirs-file[]?
Hi there
I am trying to build a parser and save the results as an xml file but i have problems.. For instance i get a TypeError: expected string or buffer when i try to run the code..
Would you experts please have a look at my code ?
import urllib2, re
from xml.dom.minidom import Document
from BeautifulSoup import BeautifulSoup as bs
osc = open('OSCTEST.html','r')
oscread = osc.read()
soup=bs(oscread)
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
countries = doc.createElement('countries')
root.appendChild(countries)
findtags1 = re.compile ('<h1 class="title metadata_title content_perceived_text(.*?)</h1>', re.DOTALL | re.IGNORECASE).findall(soup)
findtags2 = re.compile ('<span class="content_text">(.*?)</span>', re.DOTALL | re.IGNORECASE).findall(soup)
for header in findtags1:
title_elem = doc.createElement('title')
countries.appendChild(title_elem)
header_elem = doc.createTextNode(header)
title_elem.appendChild(header_elem)
for item in findtags2:
art_elem = doc.createElement('artikel')
countries.appendChild(art_elem)
s = item.replace('<P>','')
t = s.replace('</P>','')
text_elem = doc.createTextNode(t)
art_elem.appendChild(text_elem)
print doc.toprettyxml()
Just started learning Java and I am confused about this whole independent platform thingy.
Doesn't independent means that Java code should be able to run on any machine and would need no special software to be installed (JVM in this case has to be present in the machine)?
Like, for example, we need to have Turbo C Compiler in order to compile C/C++ source code and then execute it.. The machine has to have the C compiler.
guess I am confused..Somebody please explain in simple language or may be direct me to a tutorial that explain things in simple language ? that would be great
I am just not getting the concept.
I am adapting the Coverflow technique to work with a div. Following is the html:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
body,html {
margin: 0;
padding: 0;
background: #000;
height: 100%;
color: #eee;
font-family: Arial;
font-size: 10px;
}
div.magnifyme {
height: 80px;
padding: 80px;
position: absolute;
top: 0px;
left: 0px;
width: 8000px;
}
div.wrapper {
margin: 0px;
height: 470px;
/*border: 2px solid #999;*/
overflow: hidden;
padding-left: 40px;
right: 1px;
width: 824px;
position: relative;
}
div.container {position: relative; width: 854px; height: 480px; background: #000; margin: auto;}
div.nav {position: absolute; top: 10px; width: 20%; height: 10%; right: 1px; }
div.magnifyme div {
position: absolute;
width: 300px;
height: 280px;
float: left;
margin: 5px;
position: relative;
border: 2px solid #999;
background: #500;
}
</style>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="ui.coverflow.js"></script>
<script type="text/javascript">
$(function() {
$("div.magnifyme").coverflow();
$("#add").click(function() {
location.reload();
$(".magnifyme").append("<div id=\"div5\">hello world</div>");
$("div.magnifyme").coverflow();
});
});
</script>
</head>
<body>
<div class="container">
<div class="wrapper">
<div class="magnifyme">
<div id="div0">This is div 0</div>
<div id="div1">This is div 1</div>
<div id="div2">This is div 2</div>
<div id="div3">This is div 3</div>
<div id="div4">This is div 4</div>
</div>
</div>
<div class="nav">
<button type="button" id="add">Add to Deck</button>
</div>
</div>
</body>
</html>
The coverflow function (included as a js file in the head section) is here. When I click the button, I was expecting it to add a DIV to the already present deck. For some reason, it doesn't show the newly added DIV. I tried calling the coverflow() function after I added the new element but that didn't work either. Is there any way I can make this work?
n00b question. I am a C guy and I'm trying to understand some C++ code. I have the following function declaration:
int foo(const string &myname) {
cout << "called foo for: " << myname << endl;
return 0;
}
How does the function signature differ from the equivalent C:
int foo(const char *myname)
Is there a difference between using string *myname vs string &myname? What is the difference between & in C++ and * in C to indicate pointers?
Similarly:
const string &GetMethodName() { ... }
What is the & doing here? Is there some website that explains how & is used differently in C vs C++?
Suppose that I have the following code:
private void UpdateDB(QuoteDataSet dataSet, Strint tableName)
{
using(SQLiteConnection conn = new SQLiteConnection(_connectionString))
{
conn.Open();
using (SQLiteTransaction transaction = conn.BeginTransaction())
{
using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM " + tableName, conn))
{
using (SQLiteDataAdapter sqliteAdapter = new SQLiteDataAdapter())
{
sqliteAdapter.Update(dataSet, tableName);
}
}
transaction.Commit();
}
}
}
The C# documentation states that with a using statement the object within the scope will be disposed and I've seen several places where it's suggested that we don't need to use try/finally clause.
I usually surround my connections with a try/finally, and I always close the connection in the finally clause. Given the above code, is it reasonable to assume that the connection will be closed if there is an exception?
I've read several other questions about material in order to learn RoR. But my question is can I start learning RoR without Ruby?
It's clear that the other way around is better, but I would rather try this way if it makes sense (somehow). Or learn both in parallel...
Hi All
I am learning Java through BlueJ
I would like to add a removeLot method to the Auction Class in BlueJ Chpt 4. This involves also returning the lot with the given number or null if there is no such lot.
If you enter , say 5 lots and then use the remove method, this codes removes whichever lot you specify. However if you enter a new lot after using the removeLot method - an internal error message comes up regarding lotnumbering .
Any ideas?
Thanks
Elaine
public Lot removeLot(int number) {
if((number >= 1) ) {
}
Lot lot = getLot (number);
if(lot !=null) {
lots.remove(lot);
}
return lot;
}
I get the following error from the SQL Script I am trying to run:
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near ','.
This is the SQL script:
IF NOT EXISTS (SELECT *
FROM dbo.sysobjects
WHERE id = OBJECT_ID(N'[dbo].HDDB_DataSource]')
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[HDDB_DataSource](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](255) NOT NULL,
[Type] [nvarchar](50) NOT NULL,
[XmlFileName] [nvarchar](255) NULL,
[ConnectionString] [nvarchar](255) NULL),
CONSTRAINT [PK_DataSource] PRIMARY KEY CLUSTERED
(
[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
I am using SQL Server 2005 if that helps.
Jeff
My keyboard only has normal quotes, not the smart ones.
I have obversed that I need normal ones in cgi development and the backward ones in AWK/SED.
Is there any rule when I should use smart quotes, normal ones and backward ones?
Obviously, I need to edit my keyboard layout to get the smart quotes.
I want to create a simple menu function which can call it example get_menu()
Here is my current code.
<?php
$select = 'SELECT * FROM pages';
$query = $db->rq($select);
while ($page = $db->fetch($query)) {
$id = $page['id'];
$title = $page['title'];
?>
<a href="page.php?id<?php echo $id; ?>" title="<?php echo $title; ?>"><?php echo $title; ?></a>
<?php } ?>
How to do that in?
function get_menu() {
}
Let me know.
I've been having some difficulty in understanding the source of a problem.
Below is a listing of the model classes. Essentially the goal is to have the ability to add sentences to the end of the story, or to add stories to an existing sentence_block. Right now, I'm only attempting to allow users to add sentences, and automatically create a new sentence_block for the new sentence.
class Story < ActiveRecord::Base
has_many :sentence_blocks, :dependent => :destroy
has_many :sentences, :through => :sentence_blocks
accepts_nested_attributes_for :sentence_blocks
end
class SentenceBlock < ActiveRecord::Base
belongs_to :story
has_many :sentences, :dependent => :destroy
end
class Sentence < ActiveRecord::Base
belongs_to :sentence_block
def story
@sentence_block = SentenceBlock.find(self.sentence_block_id)
Story.find(@sentence_block.story_id)
end
end
The problem is occurring when using the show method of the Story. The Story method is as follows, and the associated show method for a sentence is also included.
Sentence.show
def show
@sentence = Sentence.find(params[:id])
respond_to do |format|
format.html {redirect_to(@sentence.story)}
format.xml { render :xml => @sentence }
end
end
Story.show
def show
@story = Story.find(params[:id])
@sentence_block = @story.sentence_blocks.build
@new_sentence = @sentence_block.sentences.build(params[:sentence])
respond_to do |format|
if @new_sentence.content != nil and @new_sentence.sentence_block_id != nil and @sentence_block.save and @new_sentence.save
flash[:notice] = 'Sentence was successfully added.'
format.html # new.html.erb
format.xml { render :xml => @story }
else
@sentence_block.destroy
format.html
format.xml { render :xml => @story }
end
end
end
I'm getting a "couldn't find Sentence_block without and id" error. So I'm assuming that for some reason the sentence_block isn't getting saved to the database. Can anyone help me with my understanding of the behavior and why I'm getting the error? I'm trying to ensure that every time the view depicts show for a story, an unnecessary sentence_block and sentence isn't created, unless someone submits the form, I'm not really sure how to accomplish this. Any help would be appreciated.
Help make Stack Overflow become the definitive place to come to for examples of the classic "Hello World!" program. Feel free to use any language you like and keep to one example per answer please.
i want to implement ajax hover menu and i have a grid gridview1 like this
<asp:GridView ID="GridView1" OnRowCommand="ScheduleGridView_RowCommand" runat="server"
AutoGenerateColumns="False" Height="60px" Style="text-align: center" Width="869px"
EnableViewState="False">
<Columns>
<asp:BoundField HeaderText="Topic" DataField="Topic" />
<asp:BoundField DataField="Moderator" HeaderText="Moderator" />
<asp:BoundField DataField="Expert" HeaderText="Expert" />
<asp:BoundField DataField="StartTime" HeaderText="Start">
<HeaderStyle Width="175px" />
</asp:BoundField>
<asp:BoundField DataField="EndTime" HeaderText="End">
<HeaderStyle Width="175px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Join" ShowHeader="False">
<ItemTemplate>
<asp:Button ID="JoinBT" runat="server"
CommandName="Join" Text="Join" Width="52px" />
</ItemTemplate>
<HeaderStyle Height="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
so i registered <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
and added
I added this way in code of gridview columns
But i am getting fixed Edit/delete link in a new column rather than Hover menu,,Can any one tell me the solution to get hover menu