java.lang.OutOfMemoryError:尝试抛出OutOfMemoryError时抛出了OutOfMemoryError;没有可用的堆栈跟踪

java.lang.OutOfMemoryError:尝试抛出OutOfMemoryError时抛出了OutOfMemoryError;没有可用的堆栈跟踪,第1张

概述我正在尝试将用户提供的latlong值与数据库中的latlong值进行比较.如果它们彼此的半径在15km之内,则应更改textview.但是我面临以下错误,我的数据库包含值来源lat=19.218418源长=73.08661Deslat=18.9766017deslong=72.8326658.用户提供的值是源纬度=19.2213935源纬

我正在尝试将用户提供的lat long值与数据库中的lat long值进行比较.如果它们彼此的半径在15 km之内,则应更改textvIEw.
但是我面临以下错误,

我的数据库包含值来源lat = 19.218418源长= 73.08661
Des lat = 18.9766017 des long = 72.8326658.用户提供的值是
源纬度= 19.2213935源纬度= 73.081532目标纬度= 18.9632933经度纬度= 72.8324848.

E/AndroIDRuntime: FATAL EXCEPTION: main              Process: com.example.hitesh.nearby, PID: 2156              java.lang.IllegalStateException: Could not execute method for androID:onClick                  at androID.vIEw.VIEw$DeclaredOnClickListener.onClick(VIEw.java:5347)                  at androID.vIEw.VIEw.performClick(VIEw.java:6267)                  at androID.vIEw.VIEw$PerformClick.run(VIEw.java:24763)                  at androID.os.Handler.handleCallback(Handler.java:789)                  at androID.os.Handler.dispatchMessage(Handler.java:98)                  at androID.os.Looper.loop(Looper.java:164)                  at androID.app.ActivityThread.main(ActivityThread.java:6548)                  at java.lang.reflect.Method.invoke(Native Method)                  at com.androID.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)                  at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:767)               Caused by: java.lang.reflect.InvocationTargetException                  at java.lang.reflect.Method.invoke(Native Method)                  at androID.vIEw.VIEw$DeclaredOnClickListener.onClick(VIEw.java:5342)                  at androID.vIEw.VIEw.performClick(VIEw.java:6267)                   at androID.vIEw.VIEw$PerformClick.run(VIEw.java:24763)                   at androID.os.Handler.handleCallback(Handler.java:789)                   at androID.os.Handler.dispatchMessage(Handler.java:98)                   at androID.os.Looper.loop(Looper.java:164)                   at androID.app.ActivityThread.main(ActivityThread.java:6548)                   at java.lang.reflect.Method.invoke(Native Method)                   at com.androID.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)                   at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:767)                Caused by: java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available

Result.java

public class result extends Activity {DatabaseHelper myDb;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    myDb = new DatabaseHelper(this);    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.layout_result);    String url = getIntent().getExtras().getString("username");    String url1 = getIntent().getExtras().getString("username1");    TextVIEw tv= (TextVIEw)findVIEwByID(R.ID.textVIEw2);    TextVIEw tv1= (TextVIEw)findVIEwByID(R.ID.textVIEw5);    String[] separated = url.split("_");    String srclat = separated[0];        Double dsrclat= Double.parseDouble(srclat);    String srclng = separated[1];        Double dsrclng= Double.parseDouble(srclng);    String[] separated1 = url.split("_");    String deslat = separated1[0];         Double ddeslat= Double.parseDouble(deslat);    String deslng = separated1[1];         Double ddeslng= Double.parseDouble(deslng);    tv.setText(url);    tv1.setText(url1);}public voID Database(VIEw vIEw){    Intent intent = new Intent(result.this, Feeder.class);    startActivity(intent);}public voID NearestValue(VIEw vIEw){    TextVIEw tv= (TextVIEw)findVIEwByID(R.ID.textVIEw2);    String s1 = tv.getText().toString();    String[] separated = s1.split("_");    String deslat = separated[0];    Double Lat= Double.parseDouble(deslat);    String deslng = separated[1];    Double Lng= Double.parseDouble(deslng);    ArrayList<String> ssList = new ArrayList<>();    ssList = myDb.countDatabase(Lat,Lng);    int ssize = ssList.size();    TextVIEw tvvv = (TextVIEw) findVIEwByID(R.ID.textVIEw8);    for(int i=0;i<ssize;i++) {        tvvv.setText(ssList.get(i));    }    TextVIEw tv1= (TextVIEw)findVIEwByID(R.ID.textVIEw5);    String s11 = tv1.getText().toString();    String[] separated1 = s11.split("_");    String deslat1 = separated1[0];    Double Lat1= Double.parseDouble(deslat1);    String deslng1 = separated1[1];    Double Lng1= Double.parseDouble(deslng1);    ArrayList<String> ddList = new ArrayList<>();    ddList = myDb.countDatabase1(Lat1,Lng1);    int dsize = ddList.size();    TextVIEw tvvvv = (TextVIEw) findVIEwByID(R.ID.textVIEw9);    for(int i=0;i<dsize;i++) {        tvvv.setText(ddList.get(i));    }        for(int i=0;i<ssize;i++){            String source = ssList.get(i);            for(int j=0;j<dsize;j++) {                String destination = ddList.get(j);                String src = myDb.findBus(source, destination);                    TextVIEw tvv = (TextVIEw) findVIEwByID(R.ID.textVIEw7);                    tvv.setText(src);            }        }    }}

DatabaseHelper

    public class DatabaseHelper extends sqliteOpenHelper {    public static final String DATABASE_name = "Nearby.db";    public static final String table_name = "halt_details";    public static final String Col_2 = "snme";    public static final String Col_3 = "slati";    public static final String Col_4 = "slong";    public static final String Col_5 = "dnme";    public static final String Col_6 = "dlati";    public static final String Col_7 = "dlong";    public static final String Col_8 = "buses";    public DatabaseHelper(Context context) {        super(context, DATABASE_name, null, 1);    }    @OverrIDe    public voID onCreate(sqliteDatabase db) {        db.execsql("CREATE table " + table_name + "(ID INTEGER PRIMARY KEY autoINCREMENT NOT NulL, snme VARCHAR, slati DOUBLE, slong DOUBLE, dnme VARCHAR, dlati DOUBLE, dlong DOUBLE, buses VARCHAR)");    }    @OverrIDe    public voID onUpgrade(sqliteDatabase db, int oldVersion, int newVersion) {        db.execsql("DROP table IF EXISTS " + table_name);        onCreate(db);    }    public voID insertData(String sname, Double slat, Double slng, String dname, Double dlat, Double dlng, String bus) {        sqliteDatabase db = this.getWritableDatabase();        ContentValues contentValues = new ContentValues();        contentValues.put("snme",sname);        contentValues.put("slati",slat);        contentValues.put("slong",slng);        contentValues.put("dnme",dname);        contentValues.put("dlati",dlat);        contentValues.put("dlong",dlng);        contentValues.put("buses",bus);        db.insert(table_name,null ,contentValues);    }    public voID clearDatabase() {        sqliteDatabase db = this.getWritableDatabase();        String clearDBquery = "DELETE FROM "+table_name;        db.execsql(clearDBquery);    }    public ArrayList<String> countDatabase(Double LAT, Double LNG) {        String sourcename=null;        double earthRadius = 6371.75;        ArrayList<String> sList = new ArrayList<>();        sqliteDatabase db = this.getWritableDatabase();        Cursor mCount= db.rawquery("SELECT * FROM " + DatabaseHelper.table_name + " WHERE " + DatabaseHelper.Col_3 + " BETWEEN (" +LAT+"- 0.1) AND ("+LAT+" + 0.1) AND " + DatabaseHelper.Col_4 + " BETWEEN (" +LNG+"- 0.1) AND ("+LNG+" + 0.1)", null);        mCount.movetoNext();        while (mCount.movetoFirst()) {            double Latitude = mCount.getDouble(2);            double Longitude = mCount.getDouble(3);            double dLat = Math.toradians(Latitude-LAT);            double dLng = Math.toradians(Longitude-LNG);            double sindLat = Math.sin(dLat / 2);            double sindLng = Math.sin(dLng / 2);            double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toradians(LAT)) * Math.cos(Math.toradians(Latitude));            double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));            double dist = earthRadius * c;            if (dist<15){                sourcename=mCount.getString(1);                sList.add(sourcename);            }        }        mCount.close();       return sList;    }    public ArrayList<String> countDatabase1(Double LAT, Double LNG) {        String destinationname=null;        ArrayList<String> dList = new ArrayList<>();        double earthRadius = 6371.75;        sqliteDatabase db = this.getWritableDatabase();        Cursor mCount= db.rawquery("SELECT * FROM " + DatabaseHelper.table_name + " WHERE " + DatabaseHelper.Col_3 + " BETWEEN (" +LAT+"- 0.1) AND ("+LAT+" + 0.1) AND " + DatabaseHelper.Col_4 + " BETWEEN (" +LNG+"- 0.1) AND ("+LNG+" + 0.1)", null);        mCount.movetoFirst();        while (mCount.movetoNext() ) {            double Latitude = mCount.getDouble(2);            double Longitude = mCount.getDouble(3);            double dLat = Math.toradians(Latitude-LAT);            double dLng = Math.toradians(Longitude-LNG);            double sindLat = Math.sin(dLat / 2);            double sindLng = Math.sin(dLng / 2);            double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toradians(LAT)) * Math.cos(Math.toradians(Latitude));            double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));            double dist = earthRadius * c;            if (dist<15){                destinationname = mCount.getString(4);                dList.add(destinationname);            }        }        mCount.close();        return dList;    }    public String findBus(String sourcename, String desname){        sqliteDatabase db = this.getWritableDatabase();        Cursor mCount= db.rawquery("select count(*) from search_table where name='" + sourcename + "' AND dname='"+desname+"'", null);        mCount.movetoFirst();        String src= mCount.getString(1);        mCount.close();         return src;    }    public Cursor getAllData() {        sqliteDatabase db = this.getWritableDatabase();        Cursor res = db.rawquery("select * from " + table_name, null);        return res;    }}

解决方法:

我建议您在findBus方法和调用它的循环中遇到一些问题.

1.不必要的循环

围绕findBus方法的调用的3个循环似乎无用,因为它们重复设置了TextVIEw,但是只有最后一个可能可见并且因此可用.您可以使用它们的size方法直接转到ArrayList的最后一个元素.

我建议以下内容:

tvvv.setText(ddList.get(ddList.size()-1));TextVIEw tvv = (TextVIEw) findVIEwByID(R.ID.textVIEw7);tvv.setText(myDB.findBus(ssList.get(ssList.size()-1),ddList.get(ddList.size()-1)));

应该替换:-

for(int i=0;i<dsize;i++) {    tvvv.setText(ddList.get(i));}    for(int i=0;i<ssize;i++){        String source = ssList.get(i);        for(int j=0;j<dsize;j++) {            String destination = ddList.get(j);            String src = myDb.findBus(source, destination);                TextVIEw tvv = (TextVIEw) findVIEwByID(R.ID.textVIEw7);                tvv.setText(src);        }    }}

2.无效的偏移

此外,在findBus方法中,当查询仅返回1列时,您尝试访问从查询返回的第二列.即您已编码偏移量1,而只有偏移量0(列数(*))是唯一可用的列.

我建议将findBus方法更改为:-

public String findBus(String sourcename, String desname){    sqliteDatabase db = this.getWritableDatabase();    Cursor mCount= db.rawquery("select count(*) from search_table where name='" + sourcename + "' AND dname='"+desname+"'", null);    mCount.movetoFirst();    String src= mCount.getString(0); //<<<< Changed offset to 0 from 1    mCount.close();    return src;}

如果足够我不知道的话,这可能会减少内存需求.但是,您可能还希望检查有关OOM的右侧的“相关”链接显示(“内存不足”错误,也许是带有(AndorID)的错误).

总结

以上是内存溢出为你收集整理的java.lang.OutOfMemoryError:尝试抛出OutOfMemoryError时抛出了OutOfMemoryError;没有可用的堆栈跟踪全部内容,希望文章能够帮你解决java.lang.OutOfMemoryError:尝试抛出OutOfMemoryError时抛出了OutOfMemoryError;没有可用的堆栈跟踪所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1094246.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存