Monday, November 30, 2009

java.lang.OutOfMemoryError: PermGen space on java Tomcat server, linux


I got this error last day when try to open an jsp page,

server is Tomcat5.5 and os is linux

I found this link http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/ it was very helpful to fix the issue

1. I just added the following code to my catalina.sh file

JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256m"


2.
You can create jsp page with the following code to evalute your memory details


# <%@ page import="java.lang.management.*, java.util.*" %><%

# response.setContentType("text/html");

# Iterator iter = ManagementFactory.getMemoryPoolMXBeans().iterator();

# while(iter.hasNext()){

# MemoryPoolMXBean item = (MemoryPoolMXBean) iter.next();

# MemoryUsage mu = item.getUsage();

# long used = mu.getUsed();

# long committed = mu.getCommitted();

# long max = mu.getMax();

# %>

# MEMORY TYPE: <%=item.getName()%>

# Used: <%=used%>

# Committed: <%= committed%>

# Max: <%=max%>

# <%}%>



The output look like

localhost
MEMORY TYPE: Code Cache
Used: 4 mb
Committed: 4 mb
Max: 48 mb
------------------------------------
MEMORY TYPE: PS Eden Space
Used: 25 mb
Committed: 33 mb
Max: 54 mb
------------------------------------
MEMORY TYPE: PS Survivor Space
Used: 0 mb
Committed: 1 mb
Max: 1 mb
------------------------------------
MEMORY TYPE: PS Old Gen
Used: 10 mb
Committed: 227 mb
Max: 455 mb
------------------------------------
MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 64 mb
------------------------------------


After add this code JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256m"
I got PS Perm Gen size as

MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 256 mb

Sunday, November 29, 2009

Code Sign Error: a valid provisioning profile could not be found

We have to sign our application before run with device, To do this, first we join the Program
http://developer.apple.com/iphone/program/
The minimum amount is $99

This is a very helpful link to do the process after create an account
http://www.24100.net/2009/02/iphone-sdk-mobile-provisioning-0xe800003a-0xe8000001/

Also the apple documentation is available at iPhone Developer Program Portal

Tip: creating App ID using wildcard char (*) will not be supported for Push Notification

Monday, November 16, 2009

substring in objective c

NSRange firstRange = [fullString rangeOfString:@"lookFor"];

//log the firstRange.location and firstRange.length and see whats that..

NSString *newStr = [[fullString substringFromIndex:startposition] substringToIndex:endposition];

want to see more.. click here

The number of sections contained in the table view after the update must be equal to the number of sections contained in the table view before the

'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section

This error throws when commitEditingStyle , Usually this exception is appearing when build with >= 3.0 level

When we remove data from sections, and if the section is empty , we have to remove the section also

following is the sample code:
This error throws when commitEditingStyle , Usually this exception is appearing when build with >= 3.0 level

When we remove data from sections, and if the section is empty , we have to remove the section also

following is the sample code:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// modelForSection is a custom model object that holds items for this section.
[modelForSection removeItem:[self itemForRowAtIndexPath:indexPath]];

[tableView beginUpdates];

// Either delete some rows within a section (leaving at least one) or the entire section.
if ([modelForSection.items count] > 0)
{
// Section is not yet empty, so delete only the current row.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
else
{
// Section is now completely empty, so delete the entire section.
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationFade];
}

[tableView endUpdates];
}
}
courtesy://http://stackoverflow.com/questions/1061071/uitableview-deleting-sections-with-animation


this is the error message I got
'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'

In my case the above solutions didn't work.. :(
I got this error when build the existing source with sdk 3.0 and above..My previous build level was 2.0. Now I want to shift to 3.0 ..

Solved by the following way

The error message describes that, the no.of rows should be same, after delete one row..
It means if you have only one row, and you delete that row, then the remaining row count should be zero

I have used a display like "No Contacts" when my list is empty, to implement this I added an array with size 3 and show that (No Contacts) when ever list is empty

so this is the corrected code in commitEditing style implementation

[arrayData removeObjectAtIndex:indexPath.row];
[tableView beginUpdates];
//this flag is used to check in numberOfRowsinSection(),
//the code would be
// if [arrayData count] == 0 && this flag is true, reset flag and return 0;

// if [arrayData count] == 0 && this flag is false return the array with size 3 to display "No //Contacts"
self.isRowDeleted = YES;
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

//this is used to
display "No Contacts"
if ([arrayData count] == 0 ){
[tableView reloadData];
}

compare iphone 3g and iphone 3gs

iPhone 3GSpeed is really improved the performance. It has 256 mb ram , the earlier iPhone 3g has 128 mb ram

see the differences in http://www.apple.com/iphone/compare-iphones/

setHidesAccessoryWhenEditing is deprecated

we can use for >=3.0:
cell.editingAccessoryType
or
cell.editingAccessoryView

the documentation describes all... :)

Sunday, November 15, 2009

setTextColor is deprecated

If we compile our old source with >= 3.x versions, we will get this warning..

old code for version :
cell.textColor = [UIColor redColor];

the new code will be
[cell.textLabel setTextColor:[UIColor redColor]];

setFont is deprecated

If we compile our old source with >= 3.x versions, we will get this warning..

1.UITableviewCell

old code for version :
cell.font = [UIFont boldSystemFontOfSize: 16];

the new code will be
[cell.textLabel setFont:[UIFont boldSystemFontOfSize: 16]];

2.UIButton

[cell.aButton.titleLabel setFont:[UIFont boldSystemFontOfSize:16]];

setImage is deprecated

If we compile our old source with >= 3.x versions, we will get this warning..

old code for version :
cell.image = [UIImage imageNamed:@"image1.png"];

the new code will be
[cell.imageView setImage:[UIImage imageNamed:@"image1.png"]];



setText is deprecated

If we compile our old source with >= 3.x versions, we will get this warning..

old code for version <3 cell.text = @"cell text";

the new code will be
[cell.textLabel setText:@"cell text"];

Thursday, November 12, 2009

Convert wmv(or any) video to m4v format on MAC OS to load in iPhone or iPod

Hi all, a free software called "HandBrake" can do this ... just google it and download

free screen capture(image or video) software for Mac OS

For image capture we can use the builtin command+shift+4 functionality, But to do some additional things(like add text, mark some area etc..) with this captured image we can use a free software "Jing" And also we can record video using this Jing

just search "Jing for Mac" in google and download ...enjoy :)

How to take screen shot in Mac OS

As I am new to Mac OS, I know hot get screen shot in windows machine..we can use "print screen" button or use "Alt"+"Prnt Scrn" button to get active window scrren, and we can paste into MSPaint application and can save..

But in Mac, this is very simple
use "command"+"shift"+"4" buttons, and drag a rectangle using mouse , the selected area would be saved into desktop as a picture#.png file

Monday, November 9, 2009

Thursday, November 5, 2009

APNS with java

I have tested push notification with pushmebaby sample program.. its worked fine.

To send notification from java, I found this
1. download apns.jar from the above link
2.
add apns.jar, commons-lang-2.0.jar files into your build path
the following is the sample program
try{
PayLoad simplePayLoad = new PayLoad();
simplePayLoad.addAlert("My alert message");
simplePayLoad.addBadge(1);
simplePayLoad.addSound("default");
PushNotificationManager.getInstance().addDevice("jijo's iPhone","give device token get from didRegisterForRemoteNotificationsWithDeviceToken delegate");
Device client = PushNotificationManager.getInstance().getDevice("jijo's iPhone");
PushNotificationManager.getInstance().initializeConnection("gateway.sandbox.push.apple.com", 2195, "C:/temp/APNSCertificates.p12", "paawordgivenwhenexport from keychain by click 'export 2 item' menu item", SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
PushNotificationManager.getInstance().sendNotification(client, simplePayLoad);

}catch(Exception e){

e.printStackTrace();
}
I have also posted the same code as comments on that site


How to create APNSCertificates.p12 file from login keychain

After enable the push on your application from apple site, and install on your machine, you can see the same in keychain.













select the installed push ceritificate and key, right click and select the menu item "Export 2 items"












and give a name ( say: APNSCertificates.p12) .

APNS : no valid 'aps-environment' entitlement string found for application

It is common to get this error if we are going to implement APNS on our currently running application..

My application runs fine on device, To implement APNS I configure the App Id on iPhone Developer Program also look at how to tab, and also go through this guide

implement APNS on client source
to implement this , there are lot of good tutorial on internet
http://www.z2live.com/push_notifications
http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/
http://ameyashetti.wordpress.com/2009/07/31/apple-push-notification-service-tutorial/

after do all these We have to create a new provisioning profile(or remove the old one and create with same name) and download it and install both xcode and iphone

remove old profile from xcode and iphone and install new profiles

Dont forget to change the "code signing identity" in settings and "Bundle Identifier" in .plist file if you are create new profile

this will solved the above mentioned error