|
-
Jan 15th, 2009, 01:38 PM
#1
Thread Starter
Hyperactive Member
Strange Error
hi,
I am creating a simple application which will fetch google search results URL in list box. I am using URI function.
Code:
Dim results As Uri()
results = c.GetResults("asd")
For Each result As Uri In results
ListBox1.Items.Add(result)
Next
Here i am getting a null reference Error. i tried to use the keyword New but still same error. i can sort it out. plz help. i have another class and its object is c. I don have any error in coding. just runtime error.
-
Jan 15th, 2009, 01:58 PM
#2
Re: Strange Error
What is c? Where is the null reference thrown (i.e. which line)? Does Uri actually contain multiple items?
I've never used a Uri object before but it seems odd that it can both old one and multiple pieces of data. For instance, you usually do a For Each on a String inside of a List(Of String).
What does GetResults return?
-
Jan 15th, 2009, 02:00 PM
#3
Re: Strange Error
Shouldn't your declaration be:
Code:
Dim results() As Uri
-
Jan 15th, 2009, 02:03 PM
#4
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Kasracer
What is c? Where is the null reference thrown (i.e. which line)? Does Uri actually contain multiple items?
I've never used a Uri object before but it seems odd that it can both old one and multiple pieces of data. For instance, you usually do a For Each on a String inside of a List(Of String).
What does GetResults return?
GetResults Return a List of URLs retrived from webpage.
c is a object or another class which has Getresults. Null Reference is thrown
Code:
results = c.GetResults("asd") 'Here
-
Jan 15th, 2009, 02:05 PM
#5
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Pradeep1210
Shouldn't your declaration be:
Code:
Dim results() As Uri
Is there any declaration mistake? i tried declaring both globally and locally.
-
Jan 15th, 2009, 02:09 PM
#6
Re: Strange Error
 Originally Posted by yogesh12
Yeah i have Declared it as Global Variable.
No... I meant the position of brackets.
Dim results() As Uri
Dim results As Uri()
These two declarations mean two different things.
-
Jan 15th, 2009, 02:11 PM
#7
Re: Strange Error
 Originally Posted by yogesh12
GetResults Return a List of URLs retrived from webpage.
c is a object or another class which has Getresults. Null Reference is thrown
Code:
results = c.GetResults("asd") 'Here
So it looks like we have two issues then. First off, results needs to be declared as a List(Of Uri). Or an array (bah!).
Secondly, if you're getting that error on that line, it sounds like c is null. Where is your declaration of c?
-
Jan 15th, 2009, 02:19 PM
#8
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Pradeep1210
No... I meant the position of brackets.
Dim results() As Uri
Dim results As Uri()
These two declarations mean two different things.
I got Error. Array cannot be Declared as New
-
Jan 15th, 2009, 02:23 PM
#9
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Kasracer
So it looks like we have two issues then. First off, results needs to be declared as a List(Of Uri). Or an array (bah!).
Secondly, if you're getting that error on that line, it sounds like c is null. Where is your declaration of c?
Code:
Uri[] results = Googler.GetResults(txtSearchstring.Text);
foreach (Uri result in results) {
lstResults.Items.Add(result);
This is c# Code i converted it. Result is an Array of URI. (List of URLS).
-
Jan 15th, 2009, 02:34 PM
#10
Addicted Member
Re: Strange Error
You may not have any red squigglies (otherwise you wouldn't even be able to compile it), but there is something your code is not handling.
And where is your try/catch?
Your code should look more like this:
vb Code:
Dim results() As Uri
Try
results = c.GetResults("asd")
If Not results = Nothing Then
For Each result As Uri In results
ListBox1.Items.Add(result)
Next
End If
Catch ex as Exception
'this is only for testing, never show the user app error messages
Messagebox.Show(ex.ToString)
End Try
When you step through the code, it should skip from the If to the End If, based on the error you are getting. Any other exceptions will be caught.
For future reference, don't show exception messages to the user. Most won't understand anything on the messages. You should handle the error, preferrably by writing it to a log, and show a message notifying the user there has been an error (how specific you want to be depends on the detail of your error handling).
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
Jan 15th, 2009, 02:39 PM
#11
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Blakk_Majik
You may not have any red squigglies (otherwise you wouldn't even be able to compile it), but there is something your code is not handling.
And where is your try/catch?
Your code should look more like this:
vb Code:
Dim results() As Uri
Try
results = c.GetResults("asd")
If Not results = Nothing Then
For Each result As Uri In results
ListBox1.Items.Add(result)
Next
End If
Catch ex as Exception
'this is only for testing, never show the user app error messages
Messagebox.Show(ex.ToString)
End Try
When you step through the code, it should skip from the If to the End If, based on the error you are getting. Any other exceptions will be caught.
For future reference, don't show exception messages to the user. Most won't understand anything on the messages. You should handle the error, preferrably by writing it to a log, and show a message notifying the user there has been an error (how specific you want to be depends on the detail of your error handling).
Mate Code is not correct.
-
Jan 15th, 2009, 02:44 PM
#12
Re: Strange Error
What is the return type of GetResults?
Declare the results variable of that type.
-
Jan 15th, 2009, 02:46 PM
#13
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Pradeep1210
What is the return type of GetResults?
Declare the results variable of that type.
Code:
Public Function GetResults(ByVal query As String) As Uri()
tell me if i am wrong.
-
Jan 15th, 2009, 02:50 PM
#14
Re: Strange Error
Put a breakpoint on the line that throws the exception. Highlight c and press Shift+F9, is it Nothing? If it is, then you have a problem there. Whether or not c is the issue can be dispensed with by this simple check. The declaration of results shouldn't impact it.
The second test is to highligh the entire c.GetResults() portion, and use Shift+F9. If c is not nothing, and you get the same exception when you look at the whole thing, then that would be interesting, but do the tests first.
My usual boring signature: Nothing
 
-
Jan 15th, 2009, 02:56 PM
#15
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Shaggy Hiker
Put a breakpoint on the line that throws the exception. Highlight c and press Shift+F9, is it Nothing? If it is, then you have a problem there. Whether or not c is the issue can be dispensed with by this simple check. The declaration of results shouldn't impact it.
The second test is to highligh the entire c.GetResults() portion, and use Shift+F9. If c is not nothing, and you get the same exception when you look at the whole thing, then that would be interesting, but do the tests first.
Great Man. I am really a stupid. i din used "New" Keyword while declaring object... Thanks Man. I also want to know how to protect my software online? via online activation or something like that..
-
Jan 15th, 2009, 03:17 PM
#16
Re: Strange Error
That should be the subject of a new thread, as you will get better eyes on the topic with a subject that is more appropriate to the current question. No cost to starting new threads for new topics. Though this thread should be marked resolved.
I might also add that you shouldn't go into that new question with much optimism. There have been a handful of threads kicking around lately on that subject, and nobody has said "this will work." It has always been more of, "this is how easy it would be to defeat that technique." With such a response to every technique I have seen, you end up asking yourself just what it is you really NEED to protect. You'll get advice, just maybe not a definitive, affirmative, answer.
My usual boring signature: Nothing
 
-
Jan 15th, 2009, 03:22 PM
#17
Thread Starter
Hyperactive Member
Re: Strange Error
 Originally Posted by Shaggy Hiker
That should be the subject of a new thread, as you will get better eyes on the topic with a subject that is more appropriate to the current question. No cost to starting new threads for new topics. Though this thread should be marked resolved.
I might also add that you shouldn't go into that new question with much optimism. There have been a handful of threads kicking around lately on that subject, and nobody has said "this will work." It has always been more of, "this is how easy it would be to defeat that technique." With such a response to every technique I have seen, you end up asking yourself just what it is you really NEED to protect. You'll get advice, just maybe not a definitive, affirmative, answer.
Thanks Man..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|