stop unexpectedly my app when peress botton in emulator/android -
my code compiles , run on emulator when button pressed stops , shows message "the application stopped on unexpectedly"
. i've searched lot , read related posts didn't help. me? got following message: "fatal exception:main"message main xml file
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.example.testing.mainactivity" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <button android:id="@+id/btnshowlocation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_marginbottom="93dp" android:paddingleft="20dp" android:paddingright="20dp" /> </relativelayout>
and activity is
package com.example.testing; import java.util.arrays; import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.toast; public class mainactivity extends activity { double latituden; double longtituden; double [][] matrix_a = {{33.977517,51.456953}, {33.980738,51.426285}, {33.989817,51.433273}, {33.994729,51.437565}, {33.995928,51.447210}, {33.992708,51.446357}, {33.984604,51.436315}, {33.974430,51.433501}, {33.983399,51.445335}, {33.978474,51.466491} };{ (int i=0;i<matrix_a.length;i++) { latituden=i; (int j=0;j<matrix_a.length;j++){ longtituden=j; }}}; button btnshowlocation; // gpstracker class gpstracker gps; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toast.maketext(getapplicationcontext(), "welcome app" , toast.length_long).show(); btnshowlocation = (button) findviewbyid(r.id.btnshowlocation); // show location button click event btnshowlocation.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { // create class object gps = new gpstracker(mainactivity.this); // check if gps enabled if(gps.cangetlocation()){ double latitude = gps.getlatitude(); double longitude = gps.getlongitude(); // \n new line toast.maketext(getapplicationcontext(), "your location - \nlat: " + latitude + "\nlong: " + longitude, toast.length_long).show(); }else{ // can't location // gps or network not enabled // ask user enable gps/network in settings gps.showsettingsalert(); } (int i=0;i<matrix_a.length;i++) { (int j=0;j<matrix_a.length;j++){ distclass distclass= new distclass(); double[] distance = distclass.calculate(gps.getlatitude(),gps.getlongitude(),latituden,longtituden); arrays.sort(distance); double min = distance[0]; system.out.println(min); toast.maketext(getapplicationcontext(), "min distance location - \nmin: " + min, toast.length_long).show(); } }; }});}}
there multiple reasons why might crash , details provided can think of several like:
have declared activity in
androidmanifest.xml
. activities in application have declared there, inside<application></application>
tag<application android:label="@string/app_name" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main"/> <category android:name="android.intent.category.launcher"/> </intent-filter> </activity> </application>
what gpstracker? imported somewhere? crash might related class.
check logcat. crash should visible there. logcat feature can accessed android studio. more on that, check this
Comments
Post a Comment