Nov
23
2013

Android | UNEXPECTED TOP-LEVEL EXCEPTION:java.nio.BufferOverflowException

While buidling android applicaiton found this issue with latest android sdk of revision 22.3 and build tool revision 19.0.0.

 Here below is the stacktrace:

01
-dex:
02
       [dx] 
03
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
04
       [dx] java.nio.BufferOverflowException
05
       [dx]  at java.nio.Buffer.nextPutIndex(Buffer.java:501)
06
       [dx]  at java.nio.HeapByteBuffer.putShort(HeapByteBuffer.java:296)
07
       [dx]  at com.android.dex.Dex$Section.writeShort(Dex.java:818)
08
       [dx]  at com.android.dex.Dex$Section.writeTypeList(Dex.java:870)
09
       [dx]  at com.android.dx.merge.DexMerger$3.write(DexMerger.java:437)
10
       [dx]  at com.android.dx.merge.DexMerger$3.write(DexMerger.java:423)
11
       [dx]  at com.android.dx.merge.DexMerger$IdMerger.mergeUnsorted(DexMerger.java:317)
12
       [dx]  at com.android.dx.merge.DexMerger.mergeTypeLists(DexMerger.java:423)
13
       [dx]  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:163)
14
       [dx]  at com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
15
       [dx]  at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
16
       [dx]  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
17
       [dx]  at com.android.dx.command.dexer.Main.run(Main.java:230)
18
       [dx]  at com.android.dx.command.dexer.Main.main(Main.java:199)
19
       [dx]  at com.android.dx.command.Main.main(Main.java:103)

 
Solution:
Deleting android sdk build tool 19.0.0 is solution for this for now.
It sounds illogical but this solution will work.
 
Here below are the link for android google group where this is submitted as defect.
https://code.google.com/p/android/issues/detail?id=61710
 
Stackoverflow question link for the same is as below:
http://stackoverflow.com/questions/19727915/android-dex-gives-a-bufferoverflowexception

 Your Suggestions Always Welcome.

Jun
10
2013

How To Get Default Location For Code Signing Keys BlackBerry10

By default, code signing keys for blackberry10 are stored in a default location in your system. The default locations of code signing keys vary based on operating system on your computer.

Below is detail about the default location as per different operating system

Windows XP : %HOMEPATH%\Local Settings\Application Data\Research In Motion

Windows Vista and Windows 7 : %HOMEPATH%\AppData\Local\Research In Motion

Mac OS : ~/Library/Research In Motion

HOMEPATH for different operating system is as below:

Windows xp : C:\Documents and Settings\user

Windows Vista and Windows 7 : C:\Users\user

Here below is the java program to get default location of code signing keys

01
/**
02
 * Driver class
03
 * @author Sanjay Jain
04
 *
05
 */
06
 
07
public class Driver {
08
 public static void main(String[] args) {
09
 try {
10
 String rimDir = getDefaultRIMDirLocation();
11
 System.out.println("Research In Motion Default Directory is:");
12
 System.out.println(rimDir);
13
 } catch (Exception e) {
14
 e.printStackTrace();
15
 }
16
 }
17
 
18
 private static String getDefaultRIMDirLocation() {
19
 String osName = System.getProperty(Constants.OS_NAME);
20
 String fileSeparator = System.getProperty(Constants.FILE_SEPARATOR);
21
 String osVersion = System.getProperty(Constants.OS_VERSION);
22
 String userHome = System.getProperty(Constants.USER_HOME);
23
 String rimDirectory = Constants.RESEARCH_IN_MOTION;
24
 String dirName = "";
25
 // Check for mac
26
 if (osName.contains(Constants.MAC)) {
27
 dirName = userHome + fileSeparator + Constants.LIBRARY + fileSeparator
28
 + rimDirectory;
29
 } // Check for windows except windows xp
30
 else if (osName.contains(Constants.WINDOWS_VISTA)
31
 || osName.contains(Constants.VISTA)
32
 || osName.contains(Constants.WINDOWS_7)
33
 || osName.contains(Constants.WINDOWS_8)
34
 || osVersion.equals(Constants._6_2)) {
35
 dirName = userHome + fileSeparator + Constants.APP_DATA + fileSeparator
36
 + Constants.LOCAL + fileSeparator + rimDirectory;
37
 }
38
 // For windows xp
39
 else {
40
 dirName = userHome + fileSeparator + Constants.LOCAL_SETTINGS
41
 + fileSeparator + Constants.APPLICATION_DATA + fileSeparator + rimDirectory;
42
 }
43
 
44
 if (dirName.length() == 0) {
45
 dirName = userHome + fileSeparator + rimDirectory;
46
 }
47
 return dirName;
48
 }
49
}

01
/**
02
 * Constants class for holding all constants
03
 * @author Sanjay Jain
04
 *
05
 */
06
public class Constants {
07
 static final String APPLICATION_DATA = "Application Data";
08
 static final String LOCAL_SETTINGS = "Local Settings";
09
 static final String APP_DATA = "AppData";
10
 static final String _6_2 = "6.2";
11
 static final String WINDOWS_8 = "Windows 8";
12
 static final String VISTA = "Vista";
13
 static final String WINDOWS_7 = "Windows 7";
14
 static final String WINDOWS_VISTA = "Windows Vista";
15
 static final String LIBRARY = "Library";
16
 static final String MAC = "Mac";
17
 static final String RESEARCH_IN_MOTION = "Research In Motion";
18
 static final String USER_HOME = "user.home";
19
 static final String OS_VERSION = "os.version";
20
 static final String FILE_SEPARATOR = "file.separator";
21
 static final String OS_NAME = "os.name";
22
 static final String LOCAL = "Local";
23
}
24

For windows 7  and windows vista output will be as below:

Research In Motion Default Directory is:

C:\Users\user\AppData\Local\Research In Motion

For windows xp output will be as below

Research In Motion Default Directory is:

C:\Documents and Settings\user\Local Settings\Application Data\Research In Motion

For Mac OS output will be as below:

Research In Motion Default Directory is:

/Users/user/Library/Research In Motion

Your Suggestions Are Always Welcomed.

Mar
13
2013

Ant | How To Create Executable Jar ?

In this article I am going to describe about how to create executable jar file using ant file.

For this I am using a java project with an ant file.

In my previous post I have detailed how to create ant hello world ant project.

I will use the same project here as well.

To create an executable jar file one need to edit projectBuilder.xml file.

So new projectBuilder.xml will looks like as below:

01
<?xml version="1.0" encoding="UTF-8"?>
02
<project name="AntProject" default="makejar" basedir=".">
03
<target name="makejar" description="Create a jar for the HW project">
04
<jar jarfile="HelloWorld.jar" includes="*.class" basedir="bin">
05
 <manifest>
06
 <attribute name="Main-Class" value="Main" />
07
 </manifest>
08
</jar>
09
</target>
10
</project>

Now run this ant file right click and run as Ant build.

Here I added a manifest tag with Main-class in jar tag.

This will set Main-Class in MANIFEST.MF

One can see the Manidest.MF by double click on HelloWorld.jar–>META-INF–>Manifest.MF As below:

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.8.3

Created-By: 1.6.0_18-b07 (Sun Microsystems Inc.)

Main-Class: Main

One can also execute HelloWorld.jar on the command line as below.

coffeewithcode

Mar
13
2013

Ant | Hello World Ant Project

Apache Ant is an open source, cross-platform based build tool that is used to describe a build  process and its dependencies and implemented in XML scripts using Java classes that ensures its extensible to any development environment (based on Java) and its  integrity with other build tools.

This article is about how to start with ant tool. In this article I am going to create a Java Project and will create a jar file  of  java project using ant file.

In my previous post I have written about Eclipse | Hello World Java Project. I am  going to use same project and here also.

So my project structure will be as below:

 

 

 

 

 

 

Now to introduce ant file create a xml file using File–> New wizard and  name it projectBuilder.xml and place below code in xml file.

1
<project name="AntProject" default="makejar" basedir=".">
2
 <target name ="makejar" description="Create a jar for the ant project">
3
   <jar jarfile="HelloWorld.jar" includes="*.class" basedir="bin"/>
4
 </target>
5
</project>

  
Now right click on projectbuilder.xml select run as ant file. As the execution stops refresh the ant project.
A jar file named HelloWorld.jar will be in root project folder.

Mar
11
2013

Eclipse | Hello World Java Project

This article is abut how to start with eclipse hello world java project.

Prerequisite: Java must be installed.

In eclipse click on File -> New Project -> Java Project (as below)

1

It will open new java project wizard. (as below)

Enter a valid a project name in project name text box. Click next (or one can directly click on finish also)

2

Click on finish on next wizard page. (as below)

3

Now create a new java class in src package. 

4

On click of class will open a page for new class entry. Enter valid class name in name text box.

Also check main method check box as below. It will create a main method in class itself.

5

Now a add sys out statement in main method. (as below)

1
public class Main {
2
 public static void main(String[] args) {
3
 System.out.println("Hello World !!!");
4
 }
5
}

Noe one can run this as java application. (as below)

6

It will first compile and then run TestProject application.

On console it will print result. ‘Hello World !!!’

Mar
8
2013

How To Open New Tab For HTML Hyperlink ?

HTML Hyperlink

In HTML, hyperlink can be used by using <a> tag. Hyperlink is a group of word which can be clicked and get executed by opening clicked link.

Syntax of HTML hyperlink is as below: 

1
<a href="http://www.coffeewithcode.com/">Visit coffeewithcode</a>

Here ‘Visit coffeewithcode’ text can be clicked together and for this clickable text destination is http://www.coffeewithcode.com which is described in href attribute of <a> tag. So on click of Visit coffeewithcode it will open http://www coffeewithcode.com in same tab / browser.

In case if once required to open hyperlink in new tab / browser window then also it is possible.

For this one need to add new attribute target and value for this attribute is “_blank”.

So new syntax will be as below:

1
<a href="http://www.coffeewithcode.com/" target="_blank">Visit coffeewithcode</a>

Now on click on ‘Visit coffeewithcode’ will open http://www coffeewithcode.com in new tab / windows.

 

 

 

 

Sep
30
2012

How to install Oracle libraries for PHP5 on Ubuntu Server

An easy way to Connect Apache server (PHP) with Oracle database.

Execute following command in terminal to complete installation of oracle OCI8 extension in php.ini.

1) Get Oracle repository from this link.

     http://oss.oracle.com/debian unstable main non-free

2) Make sure to add the proper GPG key for the repository.

      sudo wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | sudo apt-key add -

3) Get all the packages for PHP5, Oracle, and Apache2 server.

       sudo apt-get update

       sudo apt-get install build-essential

       sudo apt-get install php5-dev

       sudo apt-get install php5

       sudo apt-get install php-pear

       sudo apt-get install oracle-xe-client

       sudo apt-get install apache2

       sudo apt-get install libapache2-mod-php5

4) Install Oracle OCI8 library.

       pecl install oci8

5) This will ask for your home directory. At the time of installing the Oracle client was installed in following path :

     /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/

6) When the installation is complete you will need to add the extension information to both instance of php.ini.

     echo “extension=oci8.so” >> /etc/php5/cli/php.ini

     echo “extension=oci8.so” >> /etc/php5/apache2/php.ini

7) Restart Apache2 server.

    /etc/init.d/apache2 restart

Now make a simple test to find oracle connectivity with php.

Make test.php and paste following  code.

01
<?php
02
//oracle connection variables
03
$ora_user = 'USER_NAME'; //username
04
$ora_pass = 'PASSWORD'; //password
05
$ora_host = 'SERVER_IP_OF_ORACLE"'; //host name or server ip address
06
$ora_db = ‘DATABASE_NAME'; //database name
07
 
08
$conn = oci_connect($ora_user,$ora_pass,'//'.$ora_host.'/'.$ora_db);
09
 
10
// error handling
11
if (!ora_conn){ // if variable $conn fails to connect
12
// do the following if it fails
13
$ora_conn_erno = oci_error(); // insert oci_error() function into variable
14
echo ($ora_conn_erno['message']."\n"); // print the $ora_conn_erno variable/oci_error() function selecting only the message (human readable)
15
oci_close($conn); // close the connection just in case php doesn't close it
16
} else {
17
// if it doesn't fail it will proceed with the rest of the script
18
echo "Connection Successful\n"; //echo message if connection does not error
19
oci_close($conn); // close the connection
20
}
21
?>

Jul
19
2012

Php code for twitter interaction

Let’s take a look how php code interacts with twitter.

1.) How to get number of  twitter followers.

 PHP |  copy code |? 
1
fnction get_followers($twitter_id){
2
    $xml=file_get_contents('http://twitter.com/users/show.xml?screen_name='.$twitter_id);
3
    if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
4
        $tw['count'] = $match[1];
5
    }
6
 
7
    return $tw['count'];
8
}

Now call this function with this code

 PHP |  copy code |? 
1
$followers = get_followers(‘vimalm4u’);
2
echo “You have”.$followers.”followers!;

2.) Get number of retweets for a specific page.

       Function will get the number of  retweets of the url passed as a parameter

 PHP |  copy code |? 
01
function rtweetCount($url) {
02
   $content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
03
   $element = new SimpleXmlElement($content);
04
   $retweets = $element->story->url_count;
05
   if($retweets){
06
       return $retweets;
07
   } else {
08
       return 0;
09
   }
10
}
11
 
12
echo rtweetCount('http://www.coffeewithcode.com');

3) Shorten urls for Twitter

      As we know, we can’t tweets messages which are longer than 140 characters. To avoid this problem, you have to use an url shortener.

 

 PHP |  copy code |? 
1
function getTinyUrl($url) {
2
   return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
3
}

Jun
29
2012

How To Call A Java Script From Java Code?

This post is to describe how to call a java script from java code.

Below is  java file.In which there is a main method.In this main method a script engine instance is taken.This script engine is already with jdk.For this one need not to add any other jar file.

01
import java.io.FileNotFoundException;
02
import java.io.FileReader;
03
 
04
import javax.script.ScriptEngine;
05
import javax.script.ScriptEngineManager;
06
import javax.script.ScriptException;
07
 
08
public class Driver {
09
 
10
/**
11
* @param args
12
* @throws FileNotFoundException
13
*/
14
public static void main(String[] args) throws FileNotFoundException {
15
try {
16
/**
17
* To call a anonymous function from java script file
18
*/
19
ScriptEngine engine = new ScriptEngineManager()
20
.getEngineByName("javascript");
21
FileReader fr = new FileReader("src/js/MySpec.js");
22
engine.eval(fr);
23
 
24
} catch (ScriptException scrEx) {
25
scrEx.printStackTrace();
26
}
27
}
28
}

Below is the java script file with an anonymous fuction.This function is to print on the console.

1
// java script anonumous function
2
(function() {
3
 print('Hello world');
4
})();
5

Below is the folder structure of the project.

Folder Structure

Folder Structure

Your Suggestions Are Always Welcomed.

Jun
20
2012

Hibernate plugin in eclipse

In previous post I describe about how to hibernate plugin the eclipse.In this post I am detailing about how that plugin will be helpful in development.

While creating any new hibernate related file this plugin will help you by configuring the parameter which are necessary to create that file.

Below are the suggestion by hibernate plugin in the new wizards.

Hibernate plugin in eclipse

Hibernate plugin in eclipse

On click of any of four link it will start a new wizard.New wizard will ask for the required input parameter to build respective file.By using this wizard one need not to create specific file manually and do entries.

While working with hibernate mapping file hibernate plugin also help with suggestions of bean properties.

There may many other features of hibernate plugin which are helpful at the time of development.As I came across I will share them on this blog.

Above are the benefits at the time of the development.Hibernate plugins also provide a complete hibernate tutorial inside the eclipse with examples.

To see the hibernate tutorial inside the eclipse go to

  • Help
  • Help Contents

It will open a new windows.This contains the guide to develop hibernate application with examples.

Here below is the screenshot of newly opened window:

Hibernate plugin in eclipse

Hibernate plugin in eclipse

Your Suggestions Are Always Welcomed.

Pages:12345678»