当前位置: 首页 > 知识库问答 >
问题:

Android Studio应用程序在没有调试器的情况下启动时会崩溃

段干华皓
2023-03-14

从昨天开始,当我在没有调试器的情况下启动应用程序时,它就会挂起。当我调试应用程序时,一切正常。我不知道我是不是应该把代码贴出来我觉得太多了。我正在使用Google Maps API。

                                                        10-03 09:58:15.311 666-687/? E/ActivityManager: writeStringToFile error:
<?xml version="1.0" encoding="utf-8"?>
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication">
    <activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyAL11W__n26lMvJ9y1Ea1jkvBR19REhE_g" />
</application>
   package com.example.luick.boat_rc;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

import com.example.luick.boat_rc.de.ye.boat_conCONTROL.GPSTracker;

import android.location.Location;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.format.Formatter;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.Toast;

import com.example.luick.boat_rc.de.ye.boat_conCONTROL.CONNECT;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends AppCompatActivity implements SensorEventListener, OnMapReadyCallback {


    public static GoogleMap mMap;
    public static String RASP_IP = "192.168.42.1";
    public static boolean STATUS = false;
    public static SensorManager sensorManager;
    public static boolean KIPP = false;
    public static Switch S_K;
    public static ImageButton B_RELOAD;
    public static String MODE;
    public static ImageButton uf;
    public static ImageButton f;
    public static ImageButton s;
    public static ImageButton ra;
    public static Switch is;
    public static Switch tr;
    public static ImageView wifi_warn;
    private static final String TAG = "MainActivity";
    SupportMapFragment sMapF;
    GPSTracker gps;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sMapF = SupportMapFragment.newInstance();
        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        B_RELOAD = (ImageButton) findViewById(R.id.B_RELOAD);
        //i2.setEnabled(false);
        uf = (ImageButton) findViewById(R.id.uf);
        f = (ImageButton) findViewById(R.id.f);
        s = (ImageButton) findViewById(R.id.s);
        ra = (ImageButton) findViewById(R.id.r);
        s.setImageResource(R.drawable.up);
        f.setImageResource(R.drawable.upg2);
        uf.setImageResource(R.drawable.upg3);
        is = (Switch) findViewById(R.id.S_IS);
        tr = (Switch) findViewById(R.id.S_TR);
        wifi_warn = (ImageView) findViewById(R.id.wifi_warn);
        wifi_warn.setVisibility(View.INVISIBLE);
        Thread si = new Thread(new MainActivity.SEND_IP());
        si.start();
        is.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked) {
                    CONNECT.writer_sens_front.println("ON");
                    CONNECT.writer_sens_front.flush();
                    Toast.makeText(getApplicationContext(), "Inelligent_ON", Toast.LENGTH_SHORT).show();
                } else {
                    CONNECT.writer_sens_front.println("OFF");
                    CONNECT.writer_sens_front.flush();
                    Toast.makeText(getApplicationContext(), "Inelligent_OFF", Toast.LENGTH_SHORT).show();
                }

            }
        });
        tr.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked) {
                    CONNECT.writer_track.println("ON");
                    CONNECT.writer_track.flush();
                    Toast.makeText(getApplicationContext(), "TRACKING....", Toast.LENGTH_SHORT).show();
                } else {
                    CONNECT.writer_track.println("OFF");
                    CONNECT.writer_track.flush();
                    Toast.makeText(getApplicationContext(), "TRACKING_OFF", Toast.LENGTH_SHORT).show();
                }

            }
        });
        ra.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    KIPP = true;
                    ra.setImageResource(R.drawable.ar);

                } else if (event.getAction() == MotionEvent.ACTION_MOVE) {

                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    KIPP = false;
                    ra.setImageResource(R.drawable.dr);
                }

                return true;
            }
        });
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        android.support.v4.app.FragmentManager sFm = getSupportFragmentManager();
        sFm.beginTransaction().add(R.id.map, sMapF).commit();
        sMapF.getMapAsync(this);
        //gps = new GPSTracker(MainActivity.this);
       //Thread CAR_MAP_OBJECT = new Thread(new MainActivity.CAR_MAP_OBJECT());
        //CAR_MAP_OBJECT.start();

        //Thread USER_MAP_OBJECT = new Thread(new MainActivity.USER_MAP_OBJECT());
        //USER_MAP_OBJECT.start();
    }


    public void WIFI() {
        Context context = MainActivity.this;
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        int numberOfLevels = 5;
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
        if (Math.round(level) < 2) {
            wifi_warn.setVisibility(View.VISIBLE);
        } else {
            wifi_warn.setVisibility(View.INVISIBLE);
        }
    }

    public void B_RELOAD(View v) {
        Thread t = new Thread(new CONNECT());
        t.start();
    }

    public void s(View v) {
        MODE = "s";
        s.setImageResource(R.drawable.up);
        f.setImageResource(R.drawable.upg2);
        uf.setImageResource(R.drawable.upg3);
        if (STATUS == true) {
            CONNECT.writer_modi.println("s");
            CONNECT.writer_modi.flush();
            Toast.makeText(getApplicationContext(), "SLOW", Toast.LENGTH_SHORT).show();
        }
    }

    public void f(View v) {
        MODE = "f";
        s.setImageResource(R.drawable.upg);
        f.setImageResource(R.drawable.up2);
        uf.setImageResource(R.drawable.upg3);
        if (STATUS == true) {
            CONNECT.writer_modi.println("f");
            CONNECT.writer_modi.flush();
            Toast.makeText(getApplicationContext(), "FAST", Toast.LENGTH_SHORT).show();
        }
    }

    public void uf(View v) {
        MODE = "uf";
        s.setImageResource(R.drawable.upg);
        f.setImageResource(R.drawable.upg2);
        uf.setImageResource(R.drawable.up3);
        if (STATUS == true) {
            CONNECT.writer_modi.println("uf");
            CONNECT.writer_modi.flush();
            Toast.makeText(getApplicationContext(), "ULTRA_FAST", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onSensorChanged(SensorEvent event) {


        WIFI();
        if (KIPP == true) {
            float output = ((event.values[1] - 1) * (500 - 1)) / (20 - 1) + 1;
            //output= ((input-minInput) * (maxOutput-minOutput)) / (maxInput-minInput) + minOutput;
            float output_eng = ((event.values[2] - 1) * (500 - 1)) / (20 - 1) + 1;
            //output= ((input-minInput) * (maxOutput-minOutput)) / (maxInput-minInput) + minOutput;

            int send = Math.round(output);

            int send_eng = Math.round(output_eng);

            if (STATUS == true) {
                //     if (send < 100 && send > -100) {
                //      CONNECT.writer_dir.println("15");
                //      CONNECT.writer_dir.flush();
                //  } else if (send > 100) {
                //      CONNECT.writer_dir.println("21");
                //      CONNECT.writer_dir.flush();

                //  } else if (send < -100) {
                //      CONNECT.writer_dir.println("10");
                //      CONNECT.writer_dir.flush();

                //Lenken
                if (MODE == "s" || MODE == null) {
                    if (send < 100 && send > -100) {
                        CONNECT.writer_dir.println("middle");
                        CONNECT.writer_dir.flush();
                    } else {
                        if (send > 100) {
                            CONNECT.writer_dir.println("right");
                            CONNECT.writer_dir.flush();
                        } else {
                            if (send < -100) {
                                CONNECT.writer_dir.println("left");
                                CONNECT.writer_dir.flush();
                            }
                        }
                    }
                }
                if (MODE == "f") {
                    if (send < 100 && send > -100) {
                        CONNECT.writer_dir.println("middle");
                        CONNECT.writer_dir.flush();
                    } else {
                        if (send > 100) {
                            CONNECT.writer_dir.println("right");
                            CONNECT.writer_dir.flush();
                        } else {
                            if (send < -100) {
                                CONNECT.writer_dir.println("left");
                                CONNECT.writer_dir.flush();
                            }
                        }
                    }
                }
                if (MODE == "uf") {
                    if (send < 100 && send > -100) {
                        CONNECT.writer_dir.println("middle");
                        CONNECT.writer_dir.flush();
                    } else {
                        if (send > 100) {
                            CONNECT.writer_dir.println("right");
                            CONNECT.writer_dir.flush();
                        } else {
                            if (send < -100) {
                                CONNECT.writer_dir.println("left");
                                CONNECT.writer_dir.flush();
                            }
                        }
                    }
                }
                //Lenken


                //Motor
                if (MODE == "s" || MODE == null) {

                    if (send_eng < 75 && send_eng > -75) {
                        CONNECT.writer_eng.println("0");
                        CONNECT.writer_eng.flush();
                    } else {
                        if (send_eng < -75) {
                            CONNECT.writer_eng.println("B");
                            CONNECT.writer_eng.println("150");
                            CONNECT.writer_eng.flush();
                        } else if (send_eng > 75) {
                            CONNECT.writer_eng.println("F");
                            CONNECT.writer_eng.println("150");
                            CONNECT.writer_eng.flush();

                        }
                    }
                } else if (MODE == "f") {

                    if (send_eng < 75 && send_eng > -75) {
                        CONNECT.writer_eng.println("0");
                        CONNECT.writer_eng.flush();
                    } else {
                        if (send_eng < -75) {
                            CONNECT.writer_eng.println("B");
                            CONNECT.writer_eng.println("150");
                            CONNECT.writer_eng.flush();
                        } else if (send_eng > 75) {
                            CONNECT.writer_eng.println("F");
                            CONNECT.writer_eng.println("180");
                            CONNECT.writer_eng.flush();

                        }
                    }

                } else if (MODE == "uf") {

                    if (send_eng < 75 && send_eng > -75) {
                        CONNECT.writer_eng.println("0");
                        CONNECT.writer_eng.flush();
                    } else {
                        if (send_eng < -75) {
                            CONNECT.writer_eng.println("B");
                            CONNECT.writer_eng.println("0");
                            CONNECT.writer_eng.flush();
                        } else if (send_eng > 75) {
                            CONNECT.writer_eng.println("F");
                            CONNECT.writer_eng.println("199");
                            CONNECT.writer_eng.flush();

                        }
                    }
                }

                //Motor
            }
        } else {
            if (STATUS == true) {
                CONNECT.writer_eng.println("0");
                CONNECT.writer_eng.flush();
                CONNECT.writer_dir.println("middle");
                CONNECT.writer_dir.flush();
            }
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }

    @Override
    protected void onResume() {
        super.onResume();
        // register this class as a listener for the orientation and
        // accelerometer sensors
        sensorManager.registerListener(this,
                sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                SensorManager.SENSOR_DELAY_NORMAL);
    }

    public class SEND_IP implements Runnable {


        @Override
        public void run() {
            while ((true)) {
                if (STATUS == true) {
                    WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
                    String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
                    CONNECT.writer_con.println(ip);
                    CONNECT.writer_con.flush();
                }
            }
        }

    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap=googleMap;
    }
/*
    public class CAR_MAP_OBJECT implements Runnable{

        @Override
        public void run(){
            try {Thread.sleep(10000);} catch (InterruptedException e) {e.printStackTrace();}
            while (true){
                try {Thread.sleep(1000);} catch (InterruptedException e) {}
                MainActivity.mMap.clear();

                MarkerOptions car = new MarkerOptions();
                LatLng car_O = new LatLng(49.466786666666674,10.967413333333311);

                car.position(car_O);

                car.title("CAR");

                MainActivity.mMap.addMarker(car);

                MainActivity.mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(car_O, 16));
                //49.466786666666664
                //Longitude 10.967413333333331
            }
        }

    }*/

  /*  public class USER_MAP_OBJECT implements Runnable{

        @Override
        public void run(){
            try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}
            while (true){
                try {Thread.sleep(1000);} catch (InterruptedException e) {}
                if(gps.canGetLocation()){
                    double latitude = gps.getLatitude();
                    double longitude = gps.getLongitude();
                    Log.v(TAG,"Your Location is - \nLat: " + latitude + "\nLong: " + longitude);
                    //Location location = gps.getLocation();

                    //mMap.clear();

                    //MarkerOptions user = new MarkerOptions();

                    //user.position(new LatLng(location.getLatitude(), location.getLongitude()));

                    //user.title("You");

                    //mMap.addMarker(user);

                    //mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                    //      new LatLng(location.getLatitude(), location.getLongitude()), 16));
                }else{
                    gps.showSettingsAlert();
                }
            }
        }

    }*/
}

共有1个答案

方永贞
2023-03-14

将这些权限添加到manifest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

你可以走了..

 类似资料:
  • 我是Quarkus新手,正在使用Eclipse和Quarkus插件。 无论我是手动使用启动还是使用Eclipse夸克启动配置,应用程序似乎总是在运行测试。 我看到了类似的东西 有一段时间什么都没发生,直到我看到Quarkus标志、我的日志消息等。 也许我还没有仔细阅读文档,但我发现没有配置来关闭它并直接在开发模式下启动应用程序。 有人能帮我吗?

  • 问题是,当我在Google中使用授权运行此代码时,它会立即崩溃: 但是日志中的错误: 2019-06-22 17:55:42.652 29327-23222/?E/AudioSource:在已关闭的AudioSource 2019-06-22 17:55:43.240 2093-2616/?E/TouchFilter:setTouchFilter日志启用参数:0 2019-06-22 17:55:

  • 问题内容: 通常,要将调试器附加到正在运行的jvm,您需要使用以下参数启动jvm: 现在,如果我要调试不是在调试模式下启动的进程,该怎么办? 当生产系统(即在没有调试args的情况下启动)显示“随机”(我用宽松的术语)错误时,就会出现这种情况。因此,我无法使用适当的参数重新启动jvm,因为没人知道如何再次再现该错误。在这种情况下是否不可能附加到JVM? 只是为了澄清,除非将它们以调试方式启动,否则

  • 在过去的一周左右,我一直在绞尽脑汁,真的需要一些帮助。我的apk构建得很好,在linux上运行main.py工作得很好,然而,当在我的galaxy s6上运行apk时,它在打开后不久就崩溃了。我尝试更新buildozer,kivy,确保所有的依赖关系都得到满足,并包含在规范文件中(如下)。以及尝试无数其他解决方案,如更改api、更新所有构建工具等。 有人有什么想法吗?这里有一个到logcat的链接

  • 我开发的应用程序在使用Android Studio进行测试时效果很好。但是在谷歌Play商店发布后遇到了问题。 该应用程序具有多个页面。其中一个页面使用Unity启动AR图像跟踪功能,只需单击一个按钮即可。从Android Studio将应用程序添加到我的手机时完全没有问题,一切正常。但是,当从谷歌Play商店下载时,当单击按钮启动unity时,它会立即崩溃。 我是一个新的Android开发者。任

  • 我复制了gRPC helloworld示例中粘贴的gRPC服务器。 它开始侦听指定端口中的RPC,但当我使用复制粘贴的客户端调用RPC时,它会崩溃,出现“中止(内核转储)”,在客户端收到错误消息“Endpoint read failed”。 我尝试通过在RPC函数实现中包含一些输出语句来调试它,但执行从未达到目的。 没有其他错误消息,是否有一些标志使故障更详细,以便调试?