Friday 2 September 2016

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of options to view.

Today I am going to explain one of the famous Database viewer introduced by the Facebook.
Facebook people have released one SQLite Database viewer called Stetho. By using this Developers can access the SQLite database from the Chrome desktop browser.

Add this line to your build.gradle file:

compile 'com.facebook.stetho:stetho:1.4.2'
 
 And add this line to your Activity/Application Class onCreate() method: 
 
public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    Stetho.initializeWithDefaults(this);
  }
}
Once application Runs in your Emulator/Real Device you can see the database from the Chrome.

Open it from Chrome :

chrome://inspect/#devices 

you can see the below screen:

Step 2:








Source Information from:
https://github.com/facebook/stetho

Thursday 11 February 2016

AlertDialog List Items with onClick and onItemLongClick


                // TODO Auto-generated method stub
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(
                        ListAlertDailog.this);
                alertBuilder.setIcon(R.drawable.ic_launcher);
                alertBuilder.setTitle("Select Mobile OS:-");
                final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                        ListAlertDailog.this,
                        android.R.layout.select_dialog_item);
                arrayAdapter.add("Android");
                arrayAdapter.add("IOS");
                arrayAdapter.add("Windows");
                arrayAdapter.add("Bada");
                arrayAdapter.add("BlackBerry OS");
                arrayAdapter.add("Symbian OS");

                alertBuilder.setNegativeButton("Cancle",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.dismiss();
                            }
                        });

                alertBuilder.setAdapter(arrayAdapter,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                String strOS = arrayAdapter.getItem(which);
                                Toast.makeText(getApplicationContext(),
                                        "On click selected " + strOS, Toast.LENGTH_SHORT)
                                        .show();
                                dialog.dismiss();
                            }
                        });

                final AlertDialog alertDialog = alertBuilder.create();
                alertDialog.setOnShowListener(new OnShowListener() {

                    @Override
                    public void onShow(DialogInterface dialog) {
                        // TODO Auto-generated method stub
                        ListView listView = alertDialog.getListView();
                        listView.setOnItemLongClickListener(new OnItemLongClickListener() {

                            @Override
                            public boolean onItemLongClick(
                                    AdapterView<?> parent, View view,
                                    int position, long id) {
                                // TODO Auto-generated method stub
                                String strOS = arrayAdapter.getItem(position);
                                Toast.makeText(getApplicationContext(),
                                        "Long Press " + strOS,
                                        Toast.LENGTH_SHORT).show();
                                alertDialog.dismiss();
                                return true;
                            }
                        });
                    }
                });

                alertDialog.show();
           

Monday 4 January 2016

How to compare dates in android or Java (String format dates compare in java)



  Here is the example to compare 2 string format dates :
 
 
 String dateOneStr = "12/02/2016";
        String dateTwoStr = "13/02/2016";
        Date date1,date2;
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
    try {
     date1 = df.parse(dateOneStr);
     date2 = df.parse(dateTwoStr);
       
        if(date1.after(date2)){
               System.out.println("Date1 is after Date2");
           }

           if(date1.before(date2)){
               System.out.println("Date1 is before Date2");
           }

           if(date1.equals(date2)){
               System.out.println("Date1 is equal Date2");
           }
       
    } catch (ParseException e) {
        e.printStackTrace();
    }

Tuesday 4 August 2015

How To Fix Eclipse Error - Java was started but returned exit code 13

Some times after installing sdk or new plugins to eclipse we will face the issue like

Java was started but returned exit code 13 message with dialog and we can't able to open eclipse

Resolve this issue by followed by below points:

1)open eclipse folder where your using eclipse

2)check for "eclipse.ini" file in the same folder

example path:

D:\Surya Android\eclipse-java-indigo-SR1-win32\eclipse here is eclipse is root folder

and check for eclipse.ini file

Right click and chose edit option

and now you can see the file like the below format:

-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
128M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
128m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.7
-Xms512m
-Xmx512m









at the end of the line just paste below 2 lines of text
-vm
C:/Program Files/Java/jdk1.7.0_75/bin/javaw.exe

And now save the file and restart the eclipse now eclipse will work fine.

Wednesday 4 February 2015

Could not create the Java Virtual Machine.

I am using Eclipse IDE for development from so many years. recently i installed on plugin from the market place in eclipse. And i restarted eclipse,  at that time i can't able to open eclipse in my system.
i am facing below issue.

Error : Could not create the Java Virtual Machine.
Error: A fatal exception has occurred.Program will exit.





To resolve above issue i followed below point.

I just opened "eclipse.ini"file in eclipse folder.

And i  removed the -vm P:\Programs\jdk1.6\bin lines.

And i changed the required java version from

1.5 to 1.6 set  -Dosgi.requiredJavaVersion=1.6.







Wednesday 28 January 2015

Import a large sql dump file to a MySQL database using command line

Steps to import large amount of data (dump ) file to mysql using command line. 


  1. Open a command prompt (or shell) with administrative privileges
  1. Connect to a MySQL instance using command line
If you are using online/hosted sql like (AWS)

$PATH_TO_MYSQL\mysql.exe -h 198.166.1.9 --port=3306 -u root -p

If you are in localhost you do not need host and port

$PATH_TO_MYSQL\mysql.exe -u root -p
  1. Check your network buffer length value.
            SHOW VARIABLES LIKE 'net_buffer_length';
  1. If the value is less than 1000000 .Set network buffer length to a large byte number. The default value may throw errors for such large data files
set global net_buffer_length=1000000;
  1. Set maximum allowed packet size to a large byte number. The default value may throw errors for such large data files.
set global max_allowed_packet=1000000000;
  1. Disable foreign key checking to avoid delays, errors and unwanted behavior
SET foreign_key_checks = 0;
SET UNIQUE_CHECKS = 0;
SET AUTOCOMMIT = 0;
  1. Import your sql dump file
source C:\db_dumpfolder\filename.sql

Here “C:\db_dumpfolder\filename.sql” is a fully qualified path of your sql file.

  1. Once total sql file execution completed. Don’t forget to enable foreign key checks when procedure is complete!
      SET foreign_key_checks = 1;
      SET UNIQUE_CHECKS = 1;
      SET AUTOCOMMIT = 1;



If you want to edit large amount of sql file(if you are unable to open large .sql file) use below Notepad.

http://www.editpadlite.com/


This Source from the:

https://cmanios.wordpress.com/2013/03/19/import-a-large-sql-dump-file-to-a-mysql-database-from-command-line/

  
         

Wednesday 22 October 2014

How to show Android Activity as a dialog in Android

we can apply a dialog theme to an activity so that it is displayed as a floating dialog.

To apply a dialog theme to an activity, just modify the <Activity> element in the AndroidManifest.xml file by adding the android:theme attribute(android:theme="@android:style/Theme.Dialog") to the Activity.


 In Manifest file just add one simple attribute to show activity as a dialog.

 <activity
android:label="@string/app_name"
android:name=".Activity"
android:theme="@android:style/Theme.Dialog"  />

Then here we got one doubt how to close this activity dialog? 

solution is just call finish( ) method to close the activity dialog.









Saturday 16 August 2014

Exception occurred while reading or writing file {0}The Axis2 facets cannot be installed since the Axis2 runtime location has not been set. Go to the Web Services preference page and set the Axis2 runtime location under Axis2 Preferences

This is the exception am getting when am trying to create a web service.


Exception occurred while reading or writing file {0}The Axis2 facets cannot be installed since the Axis2 runtime location has not been set.   Go to the Web Services preference page and set the Axis2 runtime


How to Resolve this Issue ?

Create Dummy dynamic web project with axis2 feature and leave it. Next try your old project .













Tuesday 5 August 2014

how to change port no of jboss manually

Here the procedure to change the port number of jboss (or) check the current port number of jboss server

These are the steps to change port number of jboss manually.

Steps:

 1) Go to below path

     jboss-6.0.0.Final\server\default\deploy\jbossweb.sar\  

  2) Fnd out server.xml in jbossweb.sar folder

  3) Open server.xml

  4) Check this below tag in xml file and change port attribute in xml .

    <Connector protocol="HTTP/1.1" port="8243" address="${jboss.bind.address}" 
           redirectPort="${jboss.web.https.port}" />

 5) Restart your JBoss server.

  Now check from your browser

   http://localhost:8243/







Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...