Wednesday, May 2, 2012

ClassCastException on getCursor() of a CursorAdapter when the ListView has a footer

I have a ListView with a custom adapter that extends CursorAdapter.
that ListView also has a footer view



when a list item is clicked (which is not the footer) in the OnListItemClickListener
I get a ClassCastException on



Cursor c = ((CursorAdapter)l.getAdapter()).getCursor();

E/AndroidRuntime( 8579): FATAL EXCEPTION: main
E/AndroidRuntime( 8579): java.lang.ClassCastException: android.widget.HeaderViewListAdapter
E/AndroidRuntime( 8579): at com.gbenhaim.dealsapp.BrowsePostsActivity.onListItemClick(BrowsePostsActivity.java:277)
E/AndroidRuntime( 8579): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
E/AndroidRuntime( 8579): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime( 8579): at android.widget.ListView.performItemClick(ListView.java:3513)
E/AndroidRuntime( 8579): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
E/AndroidRuntime( 8579): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 8579): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 8579): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 8579): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 8579): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8579): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 8579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 8579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 8579): at dalvik.system.NativeStart.main(Native Method)


the footer view is inflated and added to the listview before setting the adapter.



clicking on the footer works fine and
if I don't add the footer to the listview clicking on a list item works fine



what is the problem and how do i fix it ?





Best Way to Protect Certain File Types in a Directory from Being Served

I have a directory, "d:/resources/xxxxx/file-name.xxx" that stores the file types: .png, .xml, .pdf, which are accessed by a website. A virtual directory is set up in IIS, "resources," which points to this hard drive location, to allow the .png images to be accessed through an http request, but I am referencing the .pdf and .xml files by their hard drive location. These files are part of a workflow process so they must all remain in their current directory structure.



IIS needs to be allowed to serve the .png images, but I do not want it to be allowed to serve the .pdf or .xml files, for security purposes.



I tried setting up an http handler, which would have worked fine, but I can't make the path specific enough. If I set it to "/resources/*", then I need to manually output the allowed file types and that was getting a bit wonky. I can't set it the path to "*.pdf" because other directories should be allowed to have their .pdf files accessed.



I'm just looking for a straight forward way to restrict access if someone tries to go to "www.mysite.com/resources/dir/mypdf.pdf," or ".../myxml.xml," but still allow .png and all other potential file types to be served.



Also, please let me know if I am going about this all the wrong way.





Upside down text in browsers and applications

Check out the answer to this question. How did the inverted text appear as text? In other words, I was expecting it to be an image.





Level of indentation in xmllint

By default xmllint appears to indent by 2 spaces, Is there a way to change the level of indentation on Windows?





Why my html code also display when i send email?

hi dear this is my code to send email
my message code is this



$to = $email;
$subject = "Activation";
$message = "Your activation key is this " .$key.'<br>'.' click here to activate your acount. <a href="activation.php?key='.$key.'">here</a>';
$from = "riaz_qadeer90@yahoo.com";
$headers = "From:" . $from;
if(mail($to,$subject,$message,$headers))
{
echo "Check your email to activate your acount.";
}


The problem is this when i send email the whole message shown in my inbox with code. why it not show "Click" as an anchore.....





XSLT convert mm/dd/yyyy to yyyy-mm-dd

I'm having an issue where I'm getting an XML file, and from the samples that I get the format of date that I'm getting is mm/dd/yyyy and sometimes it is m/d/yyyy. My task is to convert this to another XML where the schema only accepts yyyy-mm-dd. I'm limited to using XSLT 1.0/XPATH 1.0. I appreciate any help.



-Tim





SQL Loader Error: "Variable length field exceeds maximum length."

I have a SQL Loader Control file,



LOAD DATA

INFILE 'test.txt'

INTO TABLE TEST replace

fields terminated "|" optionally enclosed by '"' TRAILING NULLCOLS

(DOCUMENTID INTEGER(10),

CUSTID INTEGER(10),

USERID INTEGER(10),

FILENAME VARCHAR(255),

LABEL VARCHAR(50),

DESCRIPTION VARCHAR(2000),

POSTDATE DATE "YYYY-MM-DD HH24:MI:SS" NULLIF POSTDATE="",

USERFILENAME VARCHAR(50),

STORAGEPATH VARCHAR(255))



and it's giving me an error when I run SQL Loader on it,

Record 1: Rejected - Error on table TEST, column FILENAME.
Variable length field exceeds maximum length.



Here's that row.. the length of that column is way under 255..



1|5001572|2|/Storage/Test/5001572/test.pdf|test.pdf||2005-01-13 11:47:49||



And here's an oddity I noticed within the log file



Column Name | Position | Len | Term | Encl | Datatype

FILENAME | NEXT | 257 | | | VARCHAR



I define the length as 255 in both my table and control file. Yet the log spits it out as 257? I've tried knocking down the length in the control file to 253, so it appears as 255 in the log file, but the same issue.



Any help? This has bugged me for two days now.



Thanks.





how to get a div to randomly move around a page (using jQuery or CSS)

I've been doing some Googling to find an answer to this, but I've had no luck. It could be because I'm a bit of an amateur and I don't know the proper terms to search for, but maybe someone here can steer me in the right direction or help me out.



Anyway, I'm looking for a way to get a div to randomly, smoothly move around a page. There will be a background color, then this image which I want to seemingly randomly, infinitely move around the page. Much like the background of a DVD player's home screen where "DVD" is just floating around.



Starting point of the div doesn't matter, nor does the ending point. It just needs to randomly move around the page for the duration a user is on that page.



I've got decent HTML and CSS skills, very basic JS skills, and some experience implementing jQuery. Ideally, I'd like something which I can implement myself.



Thanks in advance!!!





Synchronization of acces to shared memory

i have shared memory, x writers, y readers, one parent process. Writers have exclusive access, so one writer can write and other readers and writers must wait. Multiple readers can read parallel. Priority is on writers, so for example if 3 readers are reading and one writer want write to that shared memory, then when those 3 readers finish their job, no more readers can read and writer can write. I dont know how to implement it through semaphores, because readers can read parallel, so next code will not work, because then all readers will be waiting in that semaphore.



//reader
if(isWriterActive())
{
sem_wait(semReaderStop);
}

//writer
sem_wait(semReaderStop());
.
.
sem_post(semReaderStop());


I think something like this is not good, because it is not blocking.



//readers doJob
if(isWriterActive())
{
return E_WRITER_ACTIVE;
}

while(doJob()==E_WRITER_ACTIVE);




Numbers in Javascript and effective range

All numbers in Javascript are 64bit (8 bytes) floating point numbers
but why the effective range of JavaScript is 5e-324 (negative) to 1.7976931348623157e+308 (positive)?





MySQL UTF8 varchar column size

MySQL documentation says that since 5.0, varchar lengths refer to character units, not bytes. However, I recently came across an issue where I was getting truncated data warnings when inserting values that should have fit into the varchar column it was designated.



I replicated this issue with a simple table in v5.1



mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`string` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)


I then inserted multiple 10 characters values with differing amounts of UTF8 characters



mysql> insert into test (string) values 
-> ('abcdefghij'),
-> ('ãáéíçãáéíç'),
-> ('ãáéíç67890'),
-> ('éíç4567890'),
-> ('íç34567890');
Query OK, 5 rows affected, 4 warnings (0.06 sec)
Records: 5 Duplicates: 0 Warnings: 4

mysql> show warnings;
+---------+------+---------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------+
| Warning | 1265 | Data truncated for column 'string' at row 2 |
| Warning | 1265 | Data truncated for column 'string' at row 3 |
| Warning | 1265 | Data truncated for column 'string' at row 4 |
| Warning | 1265 | Data truncated for column 'string' at row 5 |
+---------+------+---------------------------------------------+

mysql> select * from test;
+------------+
| string |
+------------+
| abcdefghij |
| ãáéíç |
| ãáéíç |
| éíç4567 |
| íç345678 |
+------------+
5 rows in set (0.00 sec)


I think that this shows that the varchar size is still defined in bytes or at least, is not accurate in character units.



The question is, am I understanding the documentation correctly and is this a bug? Or am I misinterpreting the documentation?





How to insert a Word document file in an exixsting Word document using Java

I've created a Microsoft Word document which has five to six pages using Java code. How do I insert another new word page after the third or fourth page of the existing word document?





Freeing Up Active Ram In MBP - Using Ruby in Terminal

I ran this code to see how long it takes my computer to print a number's factorial.



class Integer

def factorial
x = self.to_i
product = 1 * x

while x >= 2 do
x -= 1
product *= x
end

return product
end
end

require 'benchmark'

b = Benchmark.measure do
puts 200000.factorial
end

puts b


I've only got safari, terminal, text mate, and wonder list open.



I've got the 15" mbp with 4gb of ram running lion.



Here are my ram stats right now.



wired:862MB
Active 2.56GB
Inactive 315MB
Free 286MB



I don't think this is normal.



I printed some massive numbers before I did 200,000. Actually I did 100, 1000, 10,000, 100,000 and then finally 200,000.



Is my ram being used up because of all these numbers I printed?



If so, where can I go to delete them?



EDIT:



Tests



Control



free 270.9
wired 837.9
Active 2.12 GB
Inactive 812.2
used 3.73
Terminal Use 35.2MB
Activity Moniter 30.7MB



Calculating 100,000 factorial AND printing



free 278.6
wired 829.7
Active 2.11 GB
Inactive 817.3
used 3.72
Terminal Use 37.9 MB
Activity Moniter 31.0 MB



Calculating 100,000 factorial WITHOUT printing



free 279.5
wired 829.0
Active 2.12 GB
Inactive 814.5
used 3.72
Terminal Use 38.9 MB
Activity Moniter 31.1 MB





It is possible create a layout and view flipper on the same line?

enter image description hereIt is possible create a screen of the following way?



![Screen][2]



When I change of page, the same layout is displayed on every page



Regards





Download code works in Windows 7 but not XP SP2?

I have wrote a simple piece of code that downloads a file from a url. This code works perfectly in Windows 7, downloading the file at a good speed and maintaining a progress bar showing the download progress. However when I run the same piece of code from Windows XP SP2 it produces a .NET IOException
, it makes no sense to me why it doesnt work. It starts the same, completes the first read correctly and then throws the following exception on the second attempt to read from the stream :



 System.IO.IOException: Unable to read data from the transport connection: An operation on a
socket could not be performed because the system lacked sufficient buffer space or because a
queue was full. --->

System.Net.Sockets.SocketException: An operation on a socket could not be
performed because the system lacked sufficient buffer space or because a queue was full
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)

at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at ServicePackChk.SrvPackChk.DownLoadServicePack(Boolean bWindowsXP)
at ServicePackChk.SrvPackChk.CheckServicePackStatus()
at ServicePackChk.Form1.Form1_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)


CODE :



        Uri uri;

if (bWindowsXP)
uri = new Uri("http://download.microsoft.com/download/d/3/0/d30e32d8-418a-469d-b600-f32ce3edf42d/WindowsXP-KB936929-SP3-x86-ENU.exe");
else
uri = null;

WebRequest req = WebRequest.Create(uri);
WebResponse resp = req.GetResponse();

ProgBarForm pform = new ProgBarForm();

updateEvent += new SrvPackChk.UpdateDownloaded(pform.UpdateProgBar);

Stream stream = resp.GetResponseStream();
ArrayList alBytes = new ArrayList();
int nLen = (int)resp.ContentLength;


pform.DownLoadSize = nLen;

pform.Show();

byte[] byExe = new byte[nLen];

bool bMoreToDownload = true;

FileStream fs = new FileStream(System.IO.Path.GetTempPath() + "XPSP3.exe", FileMode.Create);

MessageBox.Show("Saving File to " + System.IO.Path.GetTempPath() + "XPSP3.exe");

while (bMoreToDownload)
{
Application.DoEvents();

int nRead = 0;

nRead = stream.Read(byExe, 0, nLen);

nDownloaded += nRead;

updateEvent(nDownloaded);

if (nDownloaded == nLen)
{
bMoreToDownload = false;
}

fs.Write(byExe, 0, nRead);
fs.Flush();

Application.DoEvents();
}

stream.Close();

fs.Close();




<asp:TextBox> Vs <input type="text"> Vs Html.TextBox

I am working in asp.net application, adding functionalities like form elements, validation and populating data from DB.



1) I can use ASP: controls but I am wondering is it possible to use HTML.TextBox or



2) If I can use <input type="text" or Html.TextBox what are the pros and cons of using them versus using



Thanks





Is this the right way to use NSAutoreleasePool?

I'm new to Objective-C and I'm not sure if I'm using NSAutoreleasePool the right way.




  1. If I want to use autorelease only one time I use:



    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSString *newText = [NSString stringWithFormat:@"%d", prograssAsInt];
    sliderLabel.text = newText;
    [pool release]; //newText will be released

  2. If I want to use autorelease several times I use:



    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSString *newText = [NSString stringWithFormat:@"%d", prograssAsInt];
    sliderLabel.text = newText;
    [pool drain]; //newText will be released
    newText = [NSString stringWithFormat:@"%d", prograssAsInt];
    sliderLabel.text = newText;
    [pool drain]; //newText will be released
    newText = [NSString stringWithFormat:@"%d", prograssAsInt];
    sliderLabel.text = newText;
    [pool release]; //newText will be released



Is this OK? Are there any memory leaks?





Create Random Serial with PHP

I want to have a random serial created on my website everytime someone visits.



The format of the serial should be XXXXX-XXXXX-XXXXX-XXXXX.



X represents a random number or capital letter.




Unfortunately I have no idea how to do this. Could anybody please help me out?



So for example the random serial output could be: 3WT4A-NB34O-JU87P-B3UHS




Thanks a lot!





SQL hashtags regex to table

I have this table:



p_id        name      skills
1 Sam #IT #communication #administration
2 Alex #French #Trainer


i want an sql query to output this



  ID     p_fid   skill
1 1 IT
2 1 communication
3 1 administration
4 2 French
5 2 Trainer


im using MS Access, but i would use a different RDBMS if Access can't do this and another RDMS can



Thanks a lot





I need to make analog clock that works on Internet Explorer

I have asked the question below, but was unfairly closed without giving me any useful information nor asking me for clarification, I am going to ask it again hoping someone would be kind enough to answer instead of wrongly using their authority:



I need to put analog clocks in a customer's web page. What I need hete is not a complete code, even though if it ever exists I wouldn't mind, but a guidance on how to implement The clocks hands and how to make them move. The calculations of time and clock time zone is something I can do.



One last thing, I need that to work on IE browser 7 and above.