Monday, November 21, 2011

Android: INSTALL_FAILED_ALREADY_EXISTS

This was a vexing issue with a simple solution. Basically, I attempted to install an APK on a real device and received, "". Since I had never installed it previously, I was perplexed, but I tried renaming the APK, using "adb uninstall", all without success.

Then, this solution simply suggested that you install over the previous installation (as absurd as that sounds). Fortunately, it worked like a charm.

Wednesday, October 12, 2011

Using Pointers to Pointers for Linked Lists

I was reading up on Linked Lists and came across a great description on the meaning of Pointers to Pointers. As pointers and I have a love/hate relationship, I found this post very insightful and easy to understand. In the code I wrote to create and print a Linked List, I found it necessary to use a Pointer to a Pointer because the pointer to the "head" node of a singly linked list needs to be defined (and accessible) by the main() routine.
#include <iostream>
#include <cstdlib>

using namespace std;

typedef struct Node {
    int value;
    struct Node *next;
    struct Node *prev;
} NodeType;

void addNode(struct Node **head, int value);
void printList(char *listName, struct Node *head);

int main() {
    NodeType *head;
    head = (struct Node*)NULL;

    addNode(&head, 1);
    addNode(&head, 10);

    printList("myList", head);

    return 0;
}

void addNode(struct Node **head, int value) {
    NodeType *temp;
    NodeType *cur;

    temp = (NodeType*)malloc(sizeof(NodeType));
    temp->next = NULL;
    temp->prev = NULL;
    if(*head == NULL) {
        *head = temp;
        temp->value = value;
    } else {
        for(cur = *head; cur->next != NULL; cur = cur->next);
        cur->next = temp;
        temp->prev = cur;
        temp->value = value;
    }
}

void printList(char *listName, struct Node *head) {
    NodeType *temp;
    cout << listName << endl;
    for(temp = head; temp != NULL; temp = temp->next) {
        cout << temp->value << endl;
    }
    cout << "End" << endl;
}

Monday, August 15, 2011

Mac OS - Opening a new browser window from within a WebKit WebView

If you Google "createWebViewWithRequest", "WebView open new window", "decidePolicyForNewWindowAction" or check out the Apple Developer Documentation on Opening Multiple Windows using WebKit, there is a lot of chatter on the difficulty of getting such a supposedly simple thing to occur.

The objective is this: You programmatically create a WebView and load standard HTML/JavaScript/CSS into it. You want to click on a link in your WebView which launches a new browser window to any URL of your choosing.

Amazingly, I haven't seen a single post that gave a simple answer to such a simple question...

Here it is in a nutshell:
  • No, you don't need to specify the WebPolicyDelegate as follows:
    @interface MyIAppDelegate : NSObject <NSApplicationDelegate, WebPolicyDelegate> {
    Some delegate are assumed and don't need to be declared. In fact, you get a compiler error if you try
  • Create your WebView in IB, add this line to MyAppDelegate:
    @property (assign) IBOutlet WebView *webView;
    and "connect" the IBAction to IB
  • In applicationDidFinishLaunching:, add this line:
    [webView setPolicyDelegate:self];
  • Add this delegate method:
    - (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener {
        [[NSWorkspace sharedWorkspace] openURL:[request URL]];
    }
  • In the HTML file, make sure your anchor tags contain 'target="_blank"'. For example:
    <a href="http://www.google.com/" target="_blank">click on this link</a>
You should be able to compile, click on a link in your WebView, and have it launch a new browser window to Google.

Tuesday, June 21, 2011

C++ static variables

This blog says it so well, that I'll just link to it. As an extension, if you define your own type, the rule also applies to your typedef. For example,
typedef map ConfigType;
ConfigType HelperUtils::config;

Thursday, June 9, 2011

Log4cpp

It is hard to find documentation for a Log4j-like utility for C++. Here is a good resource. I'll update this post with further comments on the utility (and especially portability) of this library.

Tuesday, May 24, 2011

Eclipse - Widget disposed too early

I'm using Ubuntu 10 (64-bit) and just installed Eclipse for C/C++. The first time I tried to start the application, it threw this error (plus a whole stack dump):
Widget disposed too early
This blog is the first resource that actually worked.

Wednesday, May 18, 2011

Android: updateAppWidget couldn't find any view, using error view

This was a vexing error that, according to all documentation and The Google, should not have been thrown. After a day of change code around, I stumbled on this post. The moral of the story is that you cannot change a button image; you can only change something defined in your layout XML as a <ImageView>