该应用程序正在我的模拟器中工作。我使用android studio.But当我导出并安装在我的手机中时,应用程序无法正常工作和关闭。我清除了我的主要活动中的代码并再次安装并打开。 当我用android studio开始模拟时,我看到logcat如下:
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.
我的主要活动代码是:
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);
}
}
有人可以帮助我吗?
当我在手机上使用usb调试时,我在这里添加了logcat,它崩溃了
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
我必须把数据库文件放在哪里?
答案 0 :(得分:0)
这似乎是FileUtils的权限问题 - 在数据库表上 - 检查您的应用是否拥有存储文件夹的权限,或者它是否拥有所有权。根据您的logcat,请参阅以下行: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)
答案 1 :(得分:0)
我按照本教程导入我的数据库。教程说要做一个&#34; _id&#34;列作为ID.I使用此,问题解决了。 http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/