我的.java:
package com.androID.geolocalisation3;import androID.location.Location;import androID.location.LocationListener;import androID.location.LocationManager;import androID.location.LocationProvIDer;import androID.os.Bundle;import androID.vIEw.KeyEvent;import androID.vIEw.Menu;import androID.Widget.Toast;import com.Google.androID.maps.GeoPoint;import com.Google.androID.maps.MapActivity;import com.Google.androID.maps.MapController;import com.Google.androID.maps.MapVIEw;public class Geo3MainActivity extends MapActivity implements LocationListener { private MapVIEw mapVIEw; private MapController mc; private LocationManager lm; private double latitude=122; private double longitude=37; private double altitude=0; private float accuracy=0; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_geo3_main); mapVIEw = (MapVIEw) this.findVIEwByID(R.ID.mapVIEw); mapVIEw.setBuiltInZoomControls(true); mc = mapVIEw.getController(); mc.setZoom(17); } @OverrIDe protected voID onResume() { super.onResume(); lm = (LocationManager) this.getSystemService(LOCATION_SERVICE); if (lm.isProvIDerEnabled(LocationManager.GPS_PROVIDER)) lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,10000,this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,this); } @OverrIDe protected voID onPause() { super.onPause(); lm.removeUpdates(this); } @OverrIDe protected boolean isRoutedisplayed() { return false; } @OverrIDe public boolean onKeyDown(int keyCode,KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_VolUME_UP) { mapVIEw.setSatellite(true); return true; } else if (keyCode == KeyEvent.KEYCODE_VolUME_DOWN) { mapVIEw.setSatellite(false); return true; } return super.onKeyDown(keyCode,event); } @OverrIDe public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_geo3_main,menu); return true; } @OverrIDe public voID onLocationChanged(Location location) { //altitude = location.getAltitude(); ///accuracy = location.getAccuracy(); String msg = String.format( getResources().getString(R.string.new_location),latitude,longitude,altitude,accuracy); Toast.makeText(this,msg,Toast.LENGTH_LONG).show(); GeoPoint p = new GeoPoint((int) (latitude * 1E6),(int) (longitude * 1E6)); mc.animateto(p); mc.setCenter(p); } @OverrIDe public voID onProvIDerDisabled(String provIDer) { String msg = String.format( getResources().getString(R.string.provIDer_Disabled),provIDer); Toast.makeText(this,Toast.LENGTH_SHORT).show(); } @OverrIDe public voID onProvIDerEnabled(String provIDer) { String msg = String.format( getResources().getString(R.string.provIDer_enabled),Toast.LENGTH_SHORT).show(); } @OverrIDe public voID onStatusChanged(String provIDer,int status,Bundle extras) { String newStatus = ""; switch (status) { case LocationProvIDer.OUT_OF_SERVICE: newStatus = "OUT_OF_SERVICE"; break; case LocationProvIDer.TEMPORARILY_UNAVAILABLE: newStatus = "TEMPORARILY_UNAVAILABLE"; break; case LocationProvIDer.AVAILABLE: newStatus = "AVAILABLE"; break; } String msg = String.format( getResources().getString(R.string.provIDer_Disabled),provIDer,newStatus); Toast.makeText(this,Toast.LENGTH_SHORT).show(); }}
我的日志错误:
07-28 00:00:01.054: E/StrictMode(621): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoIDing resource leaks.07-28 00:00:01.054: E/StrictMode(621): java.lang.Throwable: Explicit termination method 'close' not called07-28 00:00:01.054: E/StrictMode(621): at dalvik.system.CloseGuard.open(CloseGuard.java:184)07-28 00:00:01.054: E/StrictMode(621): at androID.database.CursorWindow.<init>(CursorWindow.java:137)07-28 00:00:01.054: E/StrictMode(621): at androID.database.CursorWindow.<init>(CursorWindow.java:41)07-28 00:00:01.054: E/StrictMode(621): at androID.database.CursorWindow.createFromParcel(CursorWindow.java:681)07-28 00:00:01.054: E/StrictMode(621): at androID.database.CursorWindow.createFromParcel(CursorWindow.java:679)07-28 00:00:01.054: E/StrictMode(621): at androID.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)07-28 00:00:01.054: E/StrictMode(621): at androID.database.BulkCursorDescriptor.createFromParcel(BulkCursorDescriptor.java:34)07-28 00:00:01.054: E/StrictMode(621): at androID.database.BulkCursorDescriptor.createFromParcel(BulkCursorDescriptor.java:30)07-28 00:00:01.054: E/StrictMode(621): at androID.content.ContentProvIDerProxy.query(ContentProvIDerNative.java:369)07-28 00:00:01.054: E/StrictMode(621): at androID.content.ContentResolver.query(ContentResolver.java:370)07-28 00:00:01.054: E/StrictMode(621): at androID.content.CursorLoader.loadInBackground(CursorLoader.java:6507-28 00:00:01.054: E/StrictMode(621): at androID.content.CursorLoader.loadInBackground(CursorLoader.java:43)07-28 00:00:01.054: E/StrictMode(621): at androID.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:301)07-28 00:00:01.054: E/StrictMode(621): at androID.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:68)07-28 00:00:01.054: E/StrictMode(621): at androID.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:56)07-28 00:00:01.054: E/StrictMode(621): at androID.os.AsyncTask.call(AsyncTask.java:287)07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.FutureTask.run(FutureTask.java:137)07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)07-28 00:00:01.054: E/StrictMode(621): at java.lang.Thread.run(Thread.java:856)07-28 00:00:01.144: E/StrictMode(621): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoIDing resource leaks.07-28 00:00:01.144: E/StrictMode(621): java.lang.Throwable: Explicit termination method 'close' not called07-28 00:00:01.144: E/StrictMode(621): at dalvik.system.CloseGuard.open(CloseGuard.java:184)07-28 00:00:01.144: E/StrictMode(621): at androID.content.ContentResolver$CursorWrapperInner.<init>(ContentResolver.java:1835)07-28 00:00:01.144: E/StrictMode(621): at androID.content.ContentResolver.query(ContentResolver.java:392)07-28 00:00:01.144: E/StrictMode(621): at androID.content.CursorLoader.loadInBackground(CursorLoader.java:65)07-28 00:00:01.144: E/StrictMode(621): at androID.content.CursorLoader.loadInBackground(CursorLoader.java:43)07-28 00:00:01.144: E/StrictMode(621): at androID.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:301)07-28 00:00:01.144: E/StrictMode(621): at androID.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:68)07-28 00:00:01.144: E/StrictMode(621): at androID.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:56)07-28 00:00:01.144: E/StrictMode(621): at androID.os.AsyncTask.call(AsyncTask.java:287)07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.FutureTask.run(FutureTask.java:137)07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)07-28 00:00:01.144: E/StrictMode(621): at java.lang.Thread.run(Thread.java:856)07-28 00:00:45.364: E/PowerManagerService(157): Excessive delay setting brightness: 144ms,mask=207-28 00:00:45.544: E/PowerManagerService(157): Excessive delay setting brightness: 139ms,mask=207-28 00:00:45.764: E/PowerManagerService(157): Excessive delay setting brightness: 211ms,mask=207-28 00:00:45.994: E/PowerManagerService(157): Excessive delay setting brightness: 224ms,mask=207-28 00:05:21.293: E/ThrottleService(157): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.fileNotFoundException: /proc/net/xt_qtaguID/iface_stat_all: open Failed: ENOENT (No such file or directory)解决方法 不知何故,日志消息的格式丢失了,使得它们很难阅读.
日志消息的第一行给出了线索:
07-28 00:00:01.054: E/StrictMode(621): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoIDing resource leaks.07-28 00:00:01.054: E/StrictMode(621): java.lang.Throwable: Explicit termination method 'close' not called
某些对象(如文件或游标)需要显式关闭.简单地删除对它们的引用是不够的.未能关闭对象会导致资源泄漏,系统会通过查杀应用程序来检测并做出反应.
不幸的是,堆栈跟踪仅显示检测到泄漏的位置,而不是最初导致泄漏的位置.
您的代码中是否有部分内容与数据库无关?日志消息表明Cursor对象存在问题.
假设您正在使用数据库,请查看数据库访问代码并确保关闭打开的每个游标和数据库.确保数据库处理函数中的所有“返回”语句在返回之前关闭相关对象.确保捕获所有可能的异常并关闭光标对象,然后让异常进入堆栈.我为此自由地使用finally {}块.
我的数据库代码通常如下所示:
protected DbRec findByID(String IDent) { DbRec rval; Cursor cursor = null; try { if( (cursor = findCursorByID(IDent)) == null ) return null; rval = newRecord(); rval.fillFromCursor(cursor); } catch (Exception e) { Log.w(TAG,"Failed to read database record: " + e); rval = null; } finally { if( cursor != null ) cursor.close(); } return rval;}
ETA:我冒昧地粘贴你评论中的日志消息:
E/AndroIDRuntime(808): java.lang.RuntimeException: Unable to resume activity {com.androID.geolocalisation3/com.androID.geolocalisation3.Geo3MainActivity}: java.lang.IllegalArgumentException: requested provIDer network doesn't exisitE/AndroIDRuntime(808): at androID.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)E/AndroIDRuntime(808): at androID.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)E/AndroIDRuntime(808): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)E/AndroIDRuntime(808): at androID.app.ActivityThread.access0(ActivityThread.java:130)E/AndroIDRuntime(808): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)E/AndroIDRuntime(808): at androID.os.Handler.dispatchMessage(Handler.java:99)E/AndroIDRuntime(808): at androID.os.Looper.loop(Looper.java:137)E/AndroIDRuntime(808): at androID.app.ActivityThread.main(ActivityThread.java:4745)E/AndroIDRuntime(808): at java.lang.reflect.Method.invokeNative(Native Method)E/AndroIDRuntime(808): at java.lang.reflect.Method.invoke(Method.java:511)E/AndroIDRuntime(808): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)E/AndroIDRuntime(808): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:553)E/AndroIDRuntime(808): at dalvik.system.NativeStart.main(Native Method)E/AndroIDRuntime(808): Caused by: java.lang.IllegalArgumentException: requested provIDer network doesn't exisitE/AndroIDRuntime(808): at androID.os.Parcel.readException(Parcel.java:1429)E/AndroIDRuntime(808): at androID.os.Parcel.readException(Parcel.java:1379)E/AndroIDRuntime(808): at androID.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)E/AndroIDRuntime(808): at androID.location.LocationManager._requestLocationUpdates(LocationManager.java:660)E/AndroIDRuntime(808): at androID.location.LocationManager.requestLocationUpdates(LocationManager.java:482)E/AndroIDRuntime(808): at com.androID.geolocalisation3.Geo3MainActivity.onResume(Geo3MainActivity.java:49)E/AndroIDRuntime(808): at androID.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)E/AndroIDRuntime(808): at androID.app.Activity.performResume(Activity.java:5082)E/AndroIDRuntime(808): at androID.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)E/AndroIDRuntime(808): ... 12 more
这是一个与以前不同的错误.它看起来像位置提供程序的名称(例如,“gps”在onSaveInstanceState()中保存错误,导致应用程序重新启动时发生崩溃.
总结以上是内存溢出为你收集整理的为什么Android模拟器显示“遗憾的是my_app_name已停止”?全部内容,希望文章能够帮你解决为什么Android模拟器显示“遗憾的是my_app_name已停止”?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)