Friday, October 10, 2014

MongoDB in Windows- error system cannot find the file specified

When you start MongoDB from the command prompt (not from the bin folder), you may get this error saying "error system cannot find the specified". This doesn't give you enough information on what triggers this error. Go to the respective bin folder of MongoDB and start the MongoDB, you will get the below error. The default db path for mongodb is /data/db/, MongoDB checks if /data/db/ is present and if the user has access to it. In your case, there is no such directory and hence the error.

mongod.exe --help for help and startup options
2014-10-10T17:45:58.896+0530 [initandlisten] MongoDB starting : pid=10100 port=27017 dbpath=\data\db\ 64-bit host=EEI3054
2014-10-10T17:45:58.897+0530 [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2014-10-10T17:45:58.897+0530 [initandlisten] db version v2.6.5
2014-10-10T17:45:58.897+0530 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-10-10T17:45:58.897+0530 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2
Pack 1') BOOST_LIB_VERSION=1_49
2014-10-10T17:45:58.898+0530 [initandlisten] allocator: system
2014-10-10T17:45:58.898+0530 [initandlisten] options: {}
2014-10-10T17:45:58.903+0530 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (\data\db\) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating


However you can override the default db path using the --dbpath argument of mongod. Try running the below command. I have provided dbpath of my configuration, you can change it where you want to have it.

mongod.exe --dbpath "c://data/db"

In this case instead of checking for /data/db/ mongoDB check for c://data/db. In your case, you have the specified directory and you have access to it and hence it runs.

Happy Programming...!!!

Saturday, May 10, 2014

Hadoop File System (HDFS)

In this tutorial we will see, some of the common unix shell commands applied on the HDFS. To execute the commands on the HDFS (Hadoop Distributed File System), make sure that the Hadoop is running.

All unix shell commands, will executed against the default home directory in HDFS. What is the default home directory in HDFS? A user’s home directory in HDFS is located at /user/username. For example, my home directory is /user/mramanujam.

Lets start with some commands, make sure that hadoop is running, if not please start hadoop.

$start-dfs.sh
.....
$start-yarn.sh

Once started, let's create the HDFS home directory, it the same unix shell command to create a directory.

$ hadoop fs -mkdir -p /user/mramanujam

Now list the files in your home directory

$ hadoop fs -ls This is will list the files in our HDFS directory.

Lets create a file and move it to the HDFS

$ vi newFile.txt

Now copy the file create from the local directory to the HDFS directory

$ hadoop fs -copyFromLocal newFile.txt newFile.txt

Now list the files in your home directory now

$ hadoop fs -ls It will show Found 1 item and the relevant details.

To get the list of all commands, please visit here

Happy Programming...!!!


Saturday, April 19, 2014

java.lang.IllegalStateException: ArrayAdapter requires the resources ID to be a TextView

Recently i was creating ListActivity for my Android application. After doing the necessary work, when i try to run the application, i was spatted with the error java.lang.IllegalStateException: ArrayAdapter requires the resources ID to be a TextView. What causes this issue?.

When you are passing an layout to the constructor like this new ArrayAdapter(this, R.layout.list_employee, this.employeeList). You need to make sure that your layout file list_employee wasn't wrapped by another layout. Unfortunately, my layout was wrapped with the RelativeLayout , which results in the above exception.

Below is the layout of my activity, which results in the exception

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   android:paddingBottom="@dimen/activity_vertical_margin"  
   android:paddingLeft="@dimen/activity_horizontal_margin"  
   android:paddingRight="@dimen/activity_horizontal_margin"  
   android:paddingTop="@dimen/activity_vertical_margin"  
  >  
   <TextView  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="@string/employee_list_heading" />  
 </RelativeLayout>  

To Resolve the issue, i have just removed the layout element which just wrapped my TextView, and modified my XML as below

 <?xml version="1.0" encoding="utf-8"?>  
 <TextView xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="wrap_content"   
   // other attributes of the TextView  
 />  

Happy Programming...!!!

Sunday, January 26, 2014

Hibernate mapping exception: Could not determine type for columns: [org.hibernate.mapping.Column]

Recently when i was implementing Many to Many with Join columns with Additional column, i was getting the following error when i was building my application. Below is the exception from my application stack.

Invocation of init method failed; nested exception is org.hibernate.MappingException: 
Could not determine type for: com.expense.domain.Medicine, at table: Medicine_Shop, for columns: [org.hibernate.mapping.Column(medicine)]

This is because my application doesn't find all of your annotations, because I was annotating both fields and methods. You have to use only one strategy.
Either annotate in fields else methods, here in my case, i was annotating at field level in all classes, except in one class, where i have annotated at the method level (getter/setter) because of that annotation doesn't have any effect. Below is the sample code, which triggers the above exception, where you can see in the MedicineShop class, i have Annotated @EmbeddedId at the method level instead of the field level, Once i move the annotation to the field level, the issue is resolved.

@Entity
@Table(name="Medicine")
public class Medicine{
 
 @Id
 @GeneratedValue
 private int id;
 @Column(name="Name")
 private String name;
 @Column(name="CompanyName")
 private String companyName;
 @OneToMany(fetch=FetchType.LAZY, mappedBy="pk.medicine", cascade=CascadeType.ALL)
 private Set medicineShop= new HashSet();
}

@Entity
@Table(name="Medicine_Shop")
@AssociationOverrides({
 @AssociationOverride(name="pk.medicine", 
   joinColumns= @JoinColumn(name = "medicine_id")),
 @AssociationOverride(name="pk.shop", 
   joinColumns= @JoinColumn(name = "shop_id"))
})
public class MedicineShop implements Serializable 
{
 
 private MedicineShopId pk = new MedicineShopId ();
 @Column(name="capacity", length=10, nullable=false)
 private int capacity;
 
 @EmbeddedId
 public MedicineShopId getPk() {
  return pk;
 }
 public void setPk(MedicineShopId pk) {
  this.pk = pk;
 }
}


Happy Programming...!!!