Wednesday, February 20, 2013

Solution: Emulator Failed to allocate memory: 8...


I have started my AVD from eclipse, suddenly I faced an exception:

[2013-02-20 09:18:12 - Emulator] Failed to allocate memory: 8
[2013-02-20 09:18:12 - Emulator]
[2013-02-20 09:18:12 - Emulator] This application has requested the Runtime to terminate it in an unusual way.
[2013-02-20 09:18:12 - Emulator] Please contact the application's support team for more information.

The error occurred due to less amount of physical RAM.

Solution is to edit C:\Users\<user>\.android\avd\<avd-profile-name>.avd\config.ini and change the value 

hw.ramSize=1024
to
hw.ramSize=1024MB

hw.ramSize : Device ram size : The amount of physical RAM on the device, in megabytes. Default value is "96".

Monday, February 18, 2013

Solution: Invalid payload item type onMenuItemSelected

If you're developing for Android 2.3 or lower, users can reveal the options menu panel by pressing the Menu button.
On Android 3.0 and higher, items from the options menu are presented by the action bar as a combination of on-screen action items and overflow options. Beginning with Android 3.0, the Menu button is deprecated.

You have a sample code in 2.3, which is working fine for MENU option.

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sample, menu);
        return true;
    }
   
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.logout:
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }


But there is a following exception when you have run same code in 4.0+ version

java.lang.IllegalArgumentException: Invalid payload item type
at android.util.EventLog.writeEvent(Native Method)
at android.app.Activity.onMenuItemSelected(Activity.java:2565)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:973)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:309)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.AbsListView.performItemClick(AbsListView.java:1099)
at android.widget.ListView.performItemClick(ListView.java:4758)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2556)
at android.widget.AbsListView$1.run(AbsListView.java:3223)
at android.os.Handler.handleCallback(Handler.java:608)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

Solution: 
Override onMenuItemSelected, and use return true or false than super.onMenuItemSelected(featureId, item).

Wednesday, February 6, 2013

Mac: Change root password without old password


If you don’t have access to an administrator already, you need to acquire root access.

If you don’t have admin access, boot the computer into Single-User Mode by holding CMD+S on startup, mount the drive, and type the command:

Wait until you see a bunch of white writing scrolling by on a black screen. You can release the keys, and you are now in Single-User mode. The computer is ready to continue when you see localhost:/ root# or something similar as the very last line on the screen.

Then follow the steps to reset admin password without old password
 /sbin/fsck -fy
        This command is a 'File System Consistency Check' and works very much the same way as Disk Utility's 'Repair Disk' function.
  /sbin/mount -uw /
        The mount command gives us access to the files on the system so we can make changes.
   
 launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist

 and finally:
 passwd
        Then, enter your new root password when prompted twice. After the password has been reset, type:
       
 reboot
        this command restarts the computer.