-1

The app is working in my emulator.I use android studio.But when I export and install in my mobile phone the app doesn't working and closing.I clear the code from my main activity and install again and it opens. When i start the emulation with the android studio i see the logcat as follows:

   07-07 18:47:13.626    1886-1886/com.example.iratus.kvexplorer I/art﹕   Not late-enabling -Xcheck:jni (already on)
   07-07 18:47:14.136    1886-1906/com.example.iratus.kvexplorer I/art﹕ Background sticky concurrent mark sweep GC freed 2826(222KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 17MB/17MB, paused 30.235ms total 65.361ms
   07-07 18:47:14.194    1886-1917/com.example.iratus.kvexplorer D/OpenGLRenderer﹕ Render dirty regions requested: true
   07-07 18:47:14.195    1886-1886/com.example.iratus.kvexplorer D/﹕ HostConnection::get() New Host Connection established 0xa69bf1b0, tid 1886
   07-07 18:47:14.238    1886-1886/com.example.iratus.kvexplorer D/Atlas﹕ Validating map...
   07-07 18:47:14.304    1886-1917/com.example.iratus.kvexplorer D/﹕ HostConnection::get() New Host Connection established 0xa69a8bb0, tid 1917
   07-07 18:47:14.406    1886-1917/com.example.iratus.kvexplorer I/OpenGLRenderer﹕ Initialized EGL, version 1.4
   07-07 18:47:14.477    1886-1917/com.example.iratus.kvexplorer D/OpenGLRenderer﹕ Enabling debug mode 0
   07-07 18:47:14.520    1886-1917/com.example.iratus.kvexplorer W/EGL_emulation﹕ eglSurfaceAttrib not implemented
   07-07 18:47:14.521    1886-1917/com.example.iratus.kvexplorer W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa69a9e60, error=EGL_SUCCESS
   07-07 18:47:18.275    1886-1886/com.example.iratus.kvexplorer D/Database operations﹕ Database Created
   07-07 18:47:18.278    1886-1886/com.example.iratus.kvexplorer W/FileUtils﹕ Failed to chmod(/data/data/com.example.iratus.kvexplorer/databases/kv_db): android.system.ErrnoException: chmod failed: EPERM (Operation not permitted)
   07-07 18:47:18.290    1886-1886/com.example.iratus.kvexplorer I/Choreographer﹕ Skipped 155 frames!  The application may be doing too much work on its main thread.
   07-07 18:47:18.360    1886-1886/com.example.iratus.kvexplorer D/Database operations﹕ Database Created
   07-07 18:47:18.361    1886-1886/com.example.iratus.kvexplorer W/FileUtils﹕ Failed to chmod(/data/data/com.example.iratus.kvexplorer/databases/kv_db): android.system.ErrnoException: chmod failed: EPERM (Operation not permitted)
   07-07 18:47:18.426    1886-1917/com.example.iratus.kvexplorer W/EGL_emulation﹕ eglSurfaceAttrib not implemented
   07-07 18:47:18.426    1886-1917/com.example.iratus.kvexplorer W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa69a9e60, error=EGL_SUCCESS
   07-07 18:47:19.407    1886-1886/com.example.iratus.kvexplorer I/Choreographer﹕ Skipped 58 frames!  The application may be doing too much work on its main thread.

my main activity code is:

public class MainActivity extends ActionBarActivity {

    Context CTX = this;
    TextView tv1;
    Button buttonG;
    public String Fid;
    //SQLiteDatabase db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ArrayList<String> centerString = new ArrayList<>(Arrays.asList("ΒΑΣΙΛΙΚΩΝ", "ΓΑΛΑΡΙΝΟΥ", "ΛΙΒΑΔΙ", "ΜΟΝΟΠΗΓΑΔΟΥ", "ΠΕΡΙΣΤΕΡΑΣ", "ΣΟΥΡΩΤΗΣ", "ΒΥΖΑΝΤΙΟ", "ΘΕΡΜΗΣ", "ΚΑΛΑΜΑΡΙΑΣ", "ΦΟΙΝΙΚΑΣ", "ΑΓ.ΤΡΙΑΔΑΣ", "ΑΓΓΕΛΟΧΩΡΙΟΥ", "ΕΠΑΝΩΜΗΣ", "ΜΕΣΗΜΕΡΙΟΥ", "ΜΗΧΑΝΙΩΝΑΣ", "ΠΕΡΑΙΑΣ", "ΡΥΣΙΟΥ", "ΤΑΓΑΡΑΔΕΣ", "ΤΟΥΜΠΑ ΕΠΑΝΩΜΗΣ", "ΤΡΙΛΟΦΟΥ", "ΕΞΟΧΗ", "ΠΑΝΟΡΑΜΑ", "ΤΟΥΜΠΑΣ", "ΧΑΡΙΛΑΟΥ", "ΧΟΡΤΙΑΤΗΣ", "ΡΟΣΤΑΝ", "ΑΜΠΕΛΟΚΗΠΟΙ ΘΣΝ", "ΕΛΕΥΘΕΡΙΑ", "ΕΥΚΑΡΠΙΑΣ", "ΠΑΥΛΟΥ ΜΕΛΑ", "ΩΡΑΙΟΚΑΣΤΡΟΥ", "ΑΣΠΡΟΒΑΛΤΑΣ", "ΜΑΔΥΤΟΥ", "ΡΕΝΤΙΝΑΣ-ΜΟΔΙ", "ΣΤΑΥΡΟΥ", "ΑΓ ΑΘΑΝΑΣΙΟΣ", "ΑΓΧΙΑΛΟΣ", "ΑΝΑΤΟΛΙΚΟ", "ΒΑΘΥΛΑΚΟΣ", "ΓΕΦΥΡΑ", "ΔΙΑΒΑΤΩΝ", "ΜΕΣΑΙΟ", "Ν.ΜΕΣΗΜΒΡΙΑ", "ΝΕΟΧΩΡΟΥΔΑ", "ΠΡΟΧΩΜΑ", "ΣΙΝΔΟΣ", "ΧΑΛΑΣΤΡΑ", "ΑΠ.ΠΑΥΛΟΥ", "ΕΡΜΟΥ", "ΑΓ.ΒΑΣΙΛΕΙΟΥ", "ΑΝΑΛΗΨΗΣ", "ΑΣΣΗΡΟΥ", "ΒΕΡΤΙΣΚΟΥ", "ΔΟΡΚΑΔΑΣ", "ΔΡΥΜΟΥ", "ΚΑΒΑΛΑΡΙ", "ΚΟΛΧΙΚΟΥ", "ΚΡΙΘΙΑΣ", "ΛΑΓΚΑΔΑ", "ΛΕΥΚΟΧΩΡΙ", "ΛΗΤΗΣ", "ΞΥΛΟΥΠΟΛΗΣ", "ΟΣΣΑΣ", "ΠΕΝΤΕ ΒΡΥΣΕΣ", "ΒΑΣΙΛΟΥΔΙ", "ΖΑΓΚΛΙΒΕΡΙ", "ΚΑΛΑΜΩΤΟΥ", "ΚΟΚΚΑΛΟΥ", "ΛΑΓΚΑΔΙΚΙΩΝ", "Ν.ΑΠΟΛΛΩΝΙΑΣ", "ΠΕΤΡΟΚΕΡΑΣΑ", "ΠΡΟΦΗΤΗ", "ΒΑΡΝΑΣ", "ΚΑΛΟΧΩΡΙ", "ΠΛΑΤ.ΔΗΜΟΚΡΑΤ.", "ΡΕΤΖΙΚΗ-ΠΕΥΚΩΝ", "ΦΙΛΥΡΟΥ", "ΑΡΕΘΟΥΣΑΣ", "ΑΡΕΤΗ", "ΑΣΚΟΥ", "ΚΡΥΟΝΕΡΙΟΥ", "ΛΟΦΙΣΚΟΣ", "ΜΑΥΡΟΥΔΑΣ", "ΣΟΧΟΥ", "ΦΙΛΑΔΕΛΦΕΙΟΥ", "ΑΔΕΝΔΡΟ", "ΑΘΥΡΑ", "ΚΟΥΦΑΛΙΑ", "ΚΥΜΙΝΑ", "ΜΙΜΡΟ ΜΟΝΑΣΤΗΡΙ", "ΧΑΛΚΗΔΟΝΑΣ"));

        final Map<String, Integer> center_kv = new HashMap<>();
        for (int i = 0; i < centerString.size(); i++) {
            center_kv.put(centerString.get(i), i + 1);
        }
        Collections.sort(centerString);
        final Spinner SP = (Spinner) findViewById(R.id.spinner);

        ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>
                (this, android.R.layout.simple_spinner_item, centerString);
        spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        SP.setAdapter(spinnerAdapter);

        final Spinner SP2 = (Spinner) findViewById(R.id.spinner2);

        final    ArrayList<String> selectedKv= new ArrayList<>();
        final ArrayAdapter<String> spinnerAdapter2 = new ArrayAdapter<>
                (this, android.R.layout.simple_spinner_item, selectedKv);

        SP.setOnItemSelectedListener(
                new AdapterView.OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                        selectedKv.clear();

                         DatabaseOperations DOP = new DatabaseOperations(CTX);
                         Cursor CR = DOP.getInformation(DOP);
                         String name_k = SP.getSelectedItem().toString();
                         String idS = center_kv.get(name_k).toString();

                      //  ArrayList<String> selectedKv = new ArrayList<>();
                        CR.moveToFirst();
                        String magic = "";
                        do {
                            if (idS.equals(CR.getString(1))){
                                magic = CR.getString(0);
                                selectedKv.add(magic);}
                            //Log.d("addddddddddddddd", magic.toString());
                        }
                        while (CR.moveToNext());

                        spinnerAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        SP2.setAdapter(spinnerAdapter2);
                        Fid = idS;
                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> parent) {
                        selectedKv.clear();
                        DatabaseOperations DOP = new DatabaseOperations(CTX);
                        Cursor CR = DOP.getInformation(DOP);
                        String name_k = SP.getSelectedItem().toString();
                        String idS = center_kv.get(name_k).toString();

                        CR.moveToFirst();
                        String magic = "";
                        do {
                            if (idS.equals(CR.getString(1))){
                                magic = CR.getString(0);
                                selectedKv.add(magic);}

                        }
                        while (CR.moveToNext());

                        spinnerAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        SP2.setAdapter(spinnerAdapter2);
                    }
                }
        );
        tv1 = (TextView) findViewById(R.id.textView);
        buttonG = (Button) findViewById(R.id.buttonGps);

        View.OnClickListener oclBtnOk = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DatabaseOperations DOP = new DatabaseOperations(CTX);
                Cursor CR = DOP.getInformation(DOP);
                String Selected_kv = SP2.getSelectedItem().toString();
                String id =Fid;

                CR.moveToFirst();
                String FinalCoordinates = "";
                do {
                    if (id.equals(CR.getString(1))){

                        if (Selected_kv.equals(CR.getString(0))){
                            FinalCoordinates = CR.getString(2);}
                        }
                }
                while (CR.moveToNext());
                Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                        Uri.parse("geo:0,0?q="+FinalCoordinates));
                startActivity(intent);
            }
        };
        buttonG.setOnClickListener(oclBtnOk);

        Button buttonInfo = (Button) findViewById(R.id.buttonInfo);
        View.OnClickListener infoListen = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                File file = new File((Environment.getExternalStorageDirectory().getAbsolutePath()+"res/kvinformation/Αγγελοχώρι.pdf"));
                if(file.exists()) {
                Intent target = new Intent(Intent.ACTION_VIEW);
                target.setDataAndType(Uri.fromFile(file),"application/pdf");
                target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

                Intent intent = Intent.createChooser(target, "Open pdf File");
                try {
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    // Instruct the user to install a PDF reader here, or something
                }
                }
                else
                    Toast.makeText(getApplicationContext(), "File path is incorrect." , Toast.LENGTH_LONG).show();

            }
        };
        buttonInfo.setOnClickListener(infoListen);


    }
}

can someone help me?

I add here the logcat when I use usb debugging with my phone and it crashes

      07-07 23:02:50.560  32685-32685/com.example.iratus.kvexplorer D/OpenGLRenderer﹕ Enabling debug mode 0
      07-07 23:02:50.590  32685-32685/com.example.iratus.kvexplorer D/Database operations﹕ Database Created
      07-07 23:02:50.600  32685-32685/com.example.iratus.kvexplorer D/AndroidRuntime﹕ Shutting down VM
      07-07 23:02:50.600  32685-32685/com.example.iratus.kvexplorer W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4101aac8)
      07-07 23:02:50.600  32685-32685/com.example.iratus.kvexplorer E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
        at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
        at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
        at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
        at com.example.iratus.kvexplorer.MainActivity$1.onItemSelected(MainActivity.java:72)
        at android.widget.AdapterView.fireOnSelected(AdapterView.java:899)
        at android.widget.AdapterView.access$200(AdapterView.java:50)
        at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:863)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:5299)
        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:1102)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
        at dalvik.system.NativeStart.main(Native Method)
         07-07 23:02:50.620  32685-32685/com.example.iratus.kvexplorer I/Process﹕ Sending signal. PID: 32685 SIG: 9

Where I have to put the database file?

fadden
  • 51,356
  • 5
  • 116
  • 166
Apollon
  • 311
  • 7
  • 29

2 Answers2

0

This appears to be a permissions issue with FileUtils - on a database table - Check if your app has rights to the storage folder or if it has ownership. As per your logcat, see this line: 07-07 18:47:18.361 1886-1886/com.example.iratus.kvexplorer W/FileUtils﹕ Failed to chmod(/data/data/com.example.iratus.kvexplorer/databases/kv_db): android.system.ErrnoException: chmod failed: EPERM (Operation not permitted)

BenJaminSila
  • 593
  • 5
  • 12
  • for the database I use android device monitor when debugging with the emulator and pull the database.After that I add data with the sqlitestudio2 and I push the database back with the android device monitor from the android studio.Is this the problem? – Apollon Jul 07 '15 at 20:13
  • Here's a useful link which may assist you. Check out this link [How to use ADB in Android Studio to view an SQLite DB][http://stackoverflow.com/questions/18370219/how-to-use-adb-in-android-studio-to-view-an-sqlite-db] – BenJaminSila Jul 08 '15 at 22:09
  • This link is working when I use emulator.When I use my phone to emulate isn't working. – Apollon Jul 09 '15 at 15:20
0

I follow this tutorial to import my db.The tutorial says to make a "_id" column as ID.I use this and the problem solved. http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

Apollon
  • 311
  • 7
  • 29