Posts Tagged ‘troubleshoot’

Ruby on Rails lockfile_parser.rb undefined method NoMethodError error

Posted in ruby on October 5th, 2010 by Aditya – 2 Comments

In short, I have been playing with both Ruby and Rails3 and Git for the first time. Everything looks OK until I decided to restart rails server. Afterward, all rails related command (rails s, rails console and such) stopped working. Here’s the output from the command line. I put my ruby (which is 1.9.2. in c:\Ruby192)

read more »

How to know which application is using which port on Mac

Posted in howto on August 4th, 2010 by Aditya – Be the first to comment

Mac:  lsof -i -P | grep -i “listen”

Note down the pid in order to kill it through activity monitor.

Developed Android App gives Java NullPointer Error

Posted in post on August 2nd, 2010 by Aditya – Be the first to comment

Sometime when I import or export Android application using eclipse, some cryptic null pointer error pops up. The error console will only prompt some kind of ‘Local Internal Error’ or something along that line despite there is no error in the application code. The full error trace can be seen below.

java.lang.NullPointerException at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launch(Unknown Source) at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.doLaunch(Unknown Source) at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(Unknown Source) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703) at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:866) at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1069) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

My best hypothesis, the problem lies with the running ADV which contains corrupted app references. So what I recommend is to delete the ADV instance – yes delete and not stop – before making different ADV instance. It works… kinda

Get One Random SQL Row From A Very Huge Table

Posted in java on August 1st, 2010 by Aditya – Be the first to comment

I have a very huge SQL table (5m entries and keep increasing) and want to select one row of entry at random. Typical method of using one SQL statement is apparently so slow. The typical method is by using the below statement by the way.

SELECT <column_name/*> FROM <table_name> ORDER BY RAND() LIMIT 1

while the above statement works fine on smaller table – generally 10000 records and below (depending on your processor speed), when its confronted with huge table, the statement just could not make it. Just to give you some imagination, I start using one of those statement and while waiting for the result, I can go to vending machine, grab a coke and come back, finish half a bottle of coke before stopping the process out of frustration.

After much tweaking and such, I realized that some statement are more size-conscious than the other. The trick is that using several statements which are less size-conscious to gather much needed parameter to assist statement that are more size conscious by increasing its … specifity (TODO: rephrase this paragraph)

I implement these principles using Java and the result can be seen below

public synchronized PhotoBean getRandomPhoto() throws DAOException {
        Connection con = null;
        try {
            con = getConnection();

            PreparedStatement pstmt1 = con
                    .prepareStatement("SELECT max(`id`) AS max_id FROM photos;");

            ResultSet rs1 = pstmt1.executeQuery();

            //this to to null-proof the logic
            int max_id = 22101985;
            int randomId = 22; // put some real ID just to make sure

            while (rs1.next()) {
                max_id = rs1.getInt("max_id");
            }

            Random randomGenerator = new Random();
            randomId = randomGenerator.nextInt(max_id);

            PreparedStatement pstmt2 = con
                    .prepareStatement("SELECT * FROM photos WHERE `id` >= ? ORDER BY `id` ASC LIMIT 1");

            pstmt2.setInt(1, randomId);

            ResultSet rs = pstmt2.executeQuery();
            PhotoBean tmpPhoto = new PhotoBean();
            while (rs.next()) {
                tmpPhoto.setPhotoId(rs.getString("photo_id"));
                //... more
            }

            //ps: you can use just one pstmt and it will be no problem as its executed separately but i am just too lazy
            pstmt1.close();
            pstmt2.close();
            releaseConnection(con);

            return tmpPhoto;

        } catch (Exception e) {
            //... more

    }

Screen Sharing with Mac OS X and Windows 7 – or possibly any other Windows

Posted in post on June 30th, 2010 by Aditya – 3 Comments

Today, I discovered how easy it is to share my school’s Mac OS X (10.5.x) screen with another non-Mac OS computer. I know it is not a sophisticated or such but I’m posting it here as I know this might not be obvious to most Windows user or even Mac user who often live in their own world.

My first attempt to do this screen sharing thing is by following this super complex tutorial. http://howto.diveintomark.org/remote-mac/

The tutorial by Mark Pilgrim comes with videos and links and nice background music and such – making it looks highly reliable for beginner like me. It sounds like a very secure procedure, with explanation about SSH, man-in-the-middle and many more. However, this tutorial miss one crucial aspect regarding setting up fixed domain, tcp-forwarding and those ip related stuff that might confuse 99% of world population. Not to mention his tutorial only shows configuration for home internet with a particular ISP.  The mac that I use for example was located behind CMU’s firewall and some other obstruction, making his tutorial to be only for geeks.

I could not set up the screen sharing capability through his tutorial. :(

*swearing phase*

For some reason all the VNC client that I use, RealVNC, TightVNC, UltraVNC does not seems to work properly. The clients fails with message like: ”Server did not offer supported security type” (tightVNC), ”No matching security types” (realVNC), ”Incompatible Version” (UltraVNC).

Then I google this error message only to found out this very long tutorial on how to tweak Mac to accept screen sharing. The tutorial can be found in this forum:

http://forums.macrumors.com/showthread.php?t=380251

In short, the tutorial asks me to perform some kind of surgery to the mac machine which obviously I was not so keen of doing so.

*swearing phase*

Then Justin, one of my research mentor pointed out that for mac, there should be no additional set up other than setting up screen sharing. He suspects its a mac-windows uneasy relationship thing.

After few googling I stumble upon one of the forum post somewhere – I forgot from where but it basically said I need to set the password for screen sharing so that those windows based client can actually connect to the mac.

IT WORKS… wtf

Here is how.

Go to (top-left-apple)-> system preferences->sharing->tick screen sharing together with the users that can be allowed to screen share.

Go to system preferences and then Sharing

Click Computer Setting to set up the password for allowing screen share.

Remove duplicate entries from a mySQL database table

Posted in post on June 18th, 2010 by Aditya – Be the first to comment

This is a quick and painless way to remove duplicate rows from a MySQL database table. It requires no programming or PHP coding whatsoever. Without further ado…

STEP 1

CREATE TABLE new_table as
SELECT * FROM old_table WHERE 1 GROUP BY [column to remove duplicates by];

STEP 2

DROP TABLE old_table;

STEP 3

RENAME TABLE new_table TO old_table;

STEP 4
DO NOT FORGET TO RESET THE PRIMARY KEY AND FOREIGN KEY AGAIN

from

http://www.justin-cook.com/wp/2006/12/12/remove-duplicate-entries-rows-a-mysql-database-table/

Tomcat 6 need more than 45 seconds

Posted in post on June 5th, 2010 by Aditya – 1 Comment

If you have read my previous post, I was still struggling with Struts + Hibernate.
In any case, for some reason Tomcat gives this weird error message.

Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.

Pretty self explanatory except for the fact that the error never mention about where I need to open the config files.

I am looking into several files inside my eclipse without avail until one blog outline his quick and dirty method.

Solution: I’m not sure where the server editor is located, but changing the start-timeout=”45″ in workspace\.metadata\.plugins\org.eclipse.wst.server.core\server.xml would help, make sure restart eclipse after the change.

Neat

Got the solution from http://acodapella.blogspot.com/2009/12/server-tomcat-v60-server-at-localhost.html

Using Hibernate 3.5 from 3.3 tutorial

Posted in post on June 5th, 2010 by Aditya – Be the first to comment

You never believe what much configuration does it take to make Struts-Hibernate-Spring configuration run. I am currently following a very long tutorial outlined here http://www.scribd.com/doc/25244173/Java-Struts-Spring-Hibernate-Tutorial I got the tutorial from apache.org site – and pretty much a very promising one.

In short, the tutorial shows how to create web-app using hibernate and struts. The tutorial uses hibernate 3.3 core and annotation component. It is said that ‘If by the time you read this 3.5 has been released then you won’t need annotations as it is going to be’. I am using Hibernate 3.5 and noticing by page 56, the code does not works due to missing element and such.

Apparently, after much googling and code skimming, I have concluded that Hibernate 3.5 still required javax.persistence.jar

Solution: download Javax.persistence.jar and add it to lib.

Download the jar from here
Javax.persistence.jar

Continue with the tutorial

UPDATE:
No need to download the above files. Apparently that javax.persistence,jar do not have important class such as javax.persistence.Cacheable

I am looking for a newer version of javax.persistence.jar now
Let me know if you have

struts.xml needs parameter to be in sequence

Posted in post on May 30th, 2010 by Aditya – 1 Comment

For some reason, I do whatever tutorial on Struts exception handling http://struts.apache.org/2.1.8.1/docs/exception-handling.html and yet the Struts giving me that obscure error message at package nodes.

It is said

The content of element type “package” must match “(result-types?,interceptors?,default-interceptor-ref?,default-
action-ref?,default-class-ref?,global-results?,global-exception-mappings?,action*)”.

I have no idea what is it until I see the tutorial mentions that I need to add two important nodes which I gladly copy pasted.

   <global-exception-mappings>
	<exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" result="securityerror" />
	 <exception-mapping exception="java.lang.Exception" result="error" />
   </global-exception-mappings>

  <global-results>
        <result name="securityerror">/securityerror.jsp</result>
  	<result name="error">/error.jsp</result>
   </global-results>

It took me 15 minutes to figure out that the tutorial gives me the wrong sequence of nodes. I need to do global-result before global-exception-mappings. Making the correct sequence to be:

  <global-results>
        <result name="securityerror">/securityerror.jsp</result>
  	<result name="error">/error.jsp</result>
   </global-results>

   <global-exception-mappings>
	<exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" result="securityerror" />
	 <exception-mapping exception="java.lang.Exception" result="error" />
   </global-exception-mappings>

and based on the above mentioned error notification and seeing the tutorial sample file, I could piece up the final struts.xml. In case you are lazy bum who do not want to download that extra 3.5 mb zip files and (assuming you follow the tutorial faithfully), the final struts.xml at the end of the day should be

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

	<constant name="struts.devMode" value="true" />
	<constant name="struts.custom.i18n.resources" value="global" />

	<package name="basicstruts2" extends="struts-default">

		<!--
			setup the default-stack exception mapping interceptor so that any
			exceptions not caught by this application will be logged and then
			handled by the global exception mapping
		-->

		<!--
			You can configure the Struts 2 framework to log any uncaught
			exceptions. To enable logging of the exceptions being handled by the
			Struts 2 framework you must specify some parameter values in
			struts.xml. If you examine the ExceptionMappingInterceptor class API
			there are three parameter values you can set to enable logging
			(logEnabled), the log level to use (logLevel), and the log category
			(logCategory) to specify in the log message. To set these parameter
			values for all actions that use a specific stack of interceptors in a
			package include the following in struts.xml just after the opening
			package node.
		-->
		<interceptors>
			<interceptor-stack name="appDefault">
				<interceptor-ref name="defaultStack">
					<param name="exception.logEnabled">true</param>
					<param name="exception.logLevel">ERROR</param>
				</interceptor-ref>
			</interceptor-stack>
		</interceptors>

		<default-interceptor-ref name="appDefault" />

		<!--
			To enable global exception handling you need to add two nodes to
			struts.xml: global-exception-mapping and global-results. For example
			examine struts.xml from the Exception Handling code download
			(http://code.google.com/p/struts2-examples/downloads/list).
		-->

		<global-results>
			<result name="error">/error.jsp</result>
			<result name="securityerror">/securityerror.jsp</result>
		</global-results>

		<global-exception-mappings>
			<exception-mapping
				exception="org.apache.struts.register.exceptions.SecurityBreachException"
				result="securityerror" />
			<exception-mapping exception="java.lang.Exception"
				result="error" />
		</global-exception-mappings>

		<action name="causesecurityexception" class="org.apache.struts.register.action.Register"
			method="throwSecurityException">
			<result>/register.jsp</result>
		</action>

		<action name="causeexception" class="org.apache.struts.register.action.Register"
			method="throwException">
			<result>/register.jsp</result>
		</action>

		<action name="causenullpointerexception" class="org.apache.struts.register.action.Register"
			method="throwNullPointerException">
			<result>/register.jsp</result>
		</action>

		<!--
			If you need to handle an exception in a specific way for a certain
			action you can use the exception-mapping node within the action node.
		-->

		<action name="actionspecificexception" class="org.apache.struts.register.action.Register"
			method="throwSecurityException">
			<exception-mapping
				exception="org.apache.struts.register.exceptions.SecurityBreachException"
				result="login" />
			<result>/register.jsp</result>
			<result name="login">/login.jsp</result>
		</action>

		<action name="index">
			<result>/index.jsp</result>
		</action>

		<action name="hello"
			class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
			<result name="success">/HelloWorld.jsp</result>
		</action>

		<action name="register" class="org.apache.struts.register.action.Register"
			method="execute">
			<result name="success">/thankyou.jsp</result>
			<result name="input">/register.jsp</result>
		</action>

		<action name="registerInput" class="org.apache.struts.register.action.Register"
			method="input">
			<result name="input">/register.jsp</result>
		</action>
	</package>

</struts>

Struts on Eclipse could not get refreshed

Posted in post on May 30th, 2010 by Aditya – Be the first to comment

Often when I am doing coding on java, most changes I have made seldom appear instantly. To make it faster, the following steps (in order / combination) might be working.

  1. Right click on the project –> “Build Project”
  2. Stop tomcat, clean the server
  3. Restart