我正在尝试将用户提供的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;

@Override

protected 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 ssList = new ArrayList<>();

ssList = myDb.countDatabase(Lat,Lng);

int ssize = ssList.size();

TextView tvvv = (TextView) findViewById(R.id.textView8);

for(int i=0;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 ddList = new ArrayList<>();

ddList = myDb.countDatabase1(Lat1,Lng1);

int dsize = ddList.size();

TextView tvvvv = (TextView) findViewById(R.id.textView9);

for(int i=0;i

tvvv.setText(ddList.get(i));

}

for(int i=0;i

String source = ssList.get(i);

for(int j=0;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 countDatabase(Double LAT, Double LNG) {

String sourcename=null;

double earthRadius = 6371.75;

ArrayList 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 countDatabase1(Double LAT, Double LNG) {

String destinationname=null;

ArrayList 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;

}

}

android tv outofmem,java.lang.OutOfMemoryError:尝试抛出OutOfMemoryErr...相关推荐

  1. Android程序运行时出现java.lang.OutOfMemoryError 错误

    写了一个用Paint和Canvas画图的类,画完之后将所画内容保存到手机sd卡上. 1>代码如下: package me.linkcube.taku.ui.share;import java.i ...

  2. 转载 Android解决java.lang.OutOfMemoryError: bitmap size exceeds VM budget

    当图片过大,或图片数量较多时使用BitmapFactory解码图片会出java.lang.OutOfMemoryError: bitmap size exceeds VM budget,要想正常使用则 ...

  3. Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M

    1 问题 glide加载图片出现oom java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2 ...

  4. android 运行或打包出现java.lang.OutOfMemoryError: GC overhead limit exceeded

    今天用android studio 打包apk出现java.lang.OutOfMemoryError: GC overhead limit exceeded,查了一下是JDK6新添的错误类型.是发生 ...

  5. Android Studio编译报错:“ java.lang.OutOfMemoryError: Java heap space”

    前言: 最近换了工作,到了新东家,厂子大了,人也多了,希望在新的环境中不断成长.在上家公司电脑是最好的,新的公司就是一般配置,内存只有8G,因此Android Studio3.5编译报错:java.l ...

  6. Android开发之关于transformDexArchiveWithExternalLibsDexMergerForDebug java.lang.OutOfMemoryError问题的参考解决方案

    报错如下: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > ja ...

  7. java.lang.OutOfMemoryError: Java heap space错误及...

    为什么80%的码农都做不了架构师?>>>    以下是从网上找到的关于堆空间溢出的错误解决办法: java.lang.OutOfMemoryError: Java heap spac ...

  8. java.lang.OutOfMemoryError: Java heap space的解决办法

    如果在启动过程中出现内存溢出问题,抛出类似如下异常信息: java.lang.OutOfMemoryError: Java heap space 可以尝试办法: A.修改Tomcat/bin/cata ...

  9. [JVM-翻译]揭开java.lang.OutOfMemoryError面纱之一

    Java.lang.OutOfMemoryError是什么  Java.lang.OutOfMemory是java.lang.VirtualMachineError的一个子类,当Java虚拟机中断,或 ...

最新文章

  1. Android - Android Studio 解决访问被墙的问题
  2. 探秘推荐引擎之协同过滤算法小综述
  3. 3月6日 输入与输出 数据类型 运算符
  4. elemnt的Table 表格使用注意事项
  5. 前端学习(2919):v-bind属性绑定
  6. 游戏大厅 从基础开始(7)--绕回来细说聊天室(中间偏下)之女仆编年史2
  7. 计算机系数据结构03年试题答案,03年北京文考“数据结构”试题
  8. 如何将Spring Bean注入到JSF Converter
  9. 用python做时间序列预测一:初识概念
  10. 评价法(四):yaahp软件——层次分析法模块使用
  11. qtp11安装及入门
  12. 超级详细的Junit单元测试教程
  13. OC 技术 获取设备的UDID添加到开发者账号(视频)
  14. 彩色二维码生成器,带logo文字和中心文字
  15. 谢文的yiqi有戏没?(续)
  16. excel对不同岗位进行名次排序
  17. (1.4.5)字符串类
  18. 【Python】程序员也可以很会撩:如何一键生成漂亮的生日快乐词云
  19. 游客 计算机英语,游客的英文,游客怎么都用英语!
  20. 【PHP+微信开发】实现微信对账单处理

热门文章

  1. ICH1/ICH2/ICH3/ICH4/ICH5/ICH6/ICH7/ICH8/ICH9的区别和联系
  2. 什么时候使用Redis缓存
  3. 用手机APP来养一盆绿植,这个黑科技智能花盆实在是太炫酷 | 钛空舱
  4. 博客篇-如何使用阿里云搭建网站
  5. java 调用弗雷_JAVASE(九)面向对象特性之 : 继承性、方法重写、关键字super、
  6. 【Python基础】第十六篇 | 面向对象之高级篇
  7. 告别刷量!公众号的正常阅读曲线是什么样的 ​
  8. 【论文学习】基于区块链的档案数据保护和共享方法
  9. TYVJ P1061 [Mobile Service]
  10. python 公众号 关注者位置_微信公众号获取用户地理位置