不幸的是,应用已停止

时间:2016-07-16 16:21:38

标签: java android android-studio

当我使用genymotion运行我的应用程序时出现一条消息“不幸的是应用程序已经停止”,当我在手机上使用它时,它工作正常,所以我的应用程序在某些设备上运行而不能在另一台设备上工作这是代码我的主要活动

public class Speedo extends Activity {
private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        if (msg != null) {
            if (msg.what == MessageHandler.MSG_NOT_CONNECTED) {
                textBluetoothStatus.setText("Not connected");
            } else if (msg.what == MessageHandler.MSG_CONNECTING) {
                textBluetoothStatus.setText("Connecting...");
            } else if (msg.what == MessageHandler.MSG_CONNECTED) {
                textBluetoothStatus.setText("Connected");
                mDeviceConnector.sendAsciiMessage("TEST");
            } else if (msg.what == MessageHandler.MSG_CONNECTION_FAILED) {
                textBluetoothStatus.setText("Connection failed");
            } else if (msg.what == MessageHandler.MSG_CONNECTION_LOST) {
                textBluetoothStatus.setText("Connection lost");
            } else if (msg.what == MessageHandler.MSG_LINE_READ) {
                Log.i("msg", msg.toString());
                cmd = msg.obj.toString();
                cmd = cmd.trim();
                textBluetooth.setText(cmd);
                }
        }
    }
};
    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
try {
                        Scanner in = new Scanner(((TextView) findViewById(R.id.bluetooth)).getText() + "").useDelimiter("[^0-9]+");
                       int bluetoothSpeed = in.nextInt();

                        GPSspeed = Integer.parseInt(edittext.getText() + "");
                        textSpeed.setText(GPSspeed + " km/h");
                        speedometer.setSpeed(GPSspeed);

                        if (bluetoothSpeed < GPSspeed && (bluetoothSpeed != lastBluetoothSpeed || GPSspeed != lastGPSspeed || lastBluetoothTime + 120 <= System.currentTimeMillis() / 1000L)) {
                          lastBluetoothSpeed = bluetoothSpeed;
                            lastGPSspeed = Integer.parseInt(edittext.getText() + "");
                            lastBluetoothTime = System.currentTimeMillis() / 1000L;
                            if(!player.isPlaying()) {
                               player.start();
                                sendsms ();
                            }
                            wakeLock.acquire();
                            handler.postDelayed(runnable, 120000);
                        }
                    }
                    catch (NumberFormatException e) {
                        Snackbar.make(findViewById(android.R.id.content), "Number format error", Snackbar.LENGTH_LONG).show();
                    }
                    catch (NoSuchElementException e) {
                        Snackbar.make(findViewById(android.R.id.content), "Bluetooth format error", Snackbar.LENGTH_LONG).show();
                    }
                }
            });

            alert.show();
        }
    });
 private class MyLocationListener implements LocationListener {
    Integer counter = 0;

    public void onLocationChanged(Location loc) {
        Log.i("GPS", "updated");
 GPSspeed = speed.intValue();
            textSpeed.setText(GPSspeed + " km/h");
            speedometer.setSpeed(GPSspeed);
            try {
                Scanner in = new Scanner(cmd).useDelimiter("[^0-9]+");
                bluetoothSpeed = in.nextInt();
                if (GPSspeed > bluetoothSpeed  && (bluetoothSpeed !=               lastBluetoothSpeed || GPSspeed != lastGPSspeed )) {
                    lastBluetoothSpeed = bluetoothSpeed;
                    lastGPSspeed = GPSspeed;
                    lastBluetoothTime = System.currentTimeMillis() / 1000L;
                    sendsms ();
                    //mDeviceConnector.sendAsciiMessage("1");
                    if(!player.isPlaying()) {
                        player.start();

                    }
                   // handler.postDelayed(runnable, 120000);
                    // wakeLock.acquire();
                }

                else if(bluetoothSpeed != lastBluetoothSpeed){
                    lastBluetoothSpeed = bluetoothSpeed;
                    sendsms ();
                }
                else if (lastBluetoothSpeed != -1 && GPSspeed     >lastBluetoothSpeed && GPSspeed != lastGPSspeed ) {
                    lastBluetoothTime = System.currentTimeMillis() / 1000L;
                    sendsms ();
                  //  mDeviceConnector.sendAsciiMessage("1");

                    if(!player.isPlaying()) {
                        player.start();

                    }
//       handler.postDelayed(runnable, 120000);
//                      wakeLock.acquire();
                }
                else {
                  //  mDeviceConnector.sendAsciiMessage("0");
                }
            } catch (Exception e) {
                e.printStackTrace();                                               Log.e(getResources().getString(R.string.app_name),"your_error_exception",e);
            }
           mDeviceConnector.sendAsciiMessage(GPSspeed + "");


        } else {
            textSpeed.setText("0 km/h");
         }
     }

这是代码错误

  07-16 13:20:54.952 831-831/? E/AndroidRuntime: FATAL EXCEPTION: main
                                           java.lang.RuntimeException:   Unable to start receiver com.jakewharton.smsbarrage.transaction.EventReceiver: java.lang.SecurityException: Neither user 10051 nor current process has android.permission.WAKE_LOCK.
                                               at android.app.ActivityThread.handleReceiver(ActivityThread.java:2236)
                                               at android.app.ActivityThread.access$1500(ActivityThread.java:130)
                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
                                               at android.os.Handler.dispatchMessage(Handler.java:99)
                                               at android.os.Looper.loop(Looper.java:137)
                                               at android.app.ActivityThread.main(ActivityThread.java:4745)
                                               at java.lang.reflect.Method.invokeNative(Native Method)
                                               at java.lang.reflect.Method.invoke(Method.java:511)
                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                               at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                               at dalvik.system.NativeStart.main(Native Method)
                                            Caused by: java.lang.SecurityException: Neither user 10051 nor current process has android.permission.WAKE_LOCK.
                                               at android.os.Parcel.readException(Parcel.java:1425)
                                               at android.os.Parcel.readException(Parcel.java:1379)
                                               at android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:288)
                                               at android.os.PowerManager$WakeLock.acquireLocked(PowerManager.java:309)
                                               at android.os.PowerManager$WakeLock.acquire(PowerManager.java:288)
                                               at com.jakewharton.smsbarrage.transaction.EventReceiver.beginStartingService(EventReceiver.java:42)
                                               at com.jakewharton.smsbarrage.transaction.EventReceiver.onReceive(EventReceiver.java:31)
                                               at android.app.ActivityThread.handleReceiver(ActivityThread.java:2229)
                                               at android.app.ActivityThread.access$1500(ActivityThread.java:130) 
                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271) 
                                               at android.os.Handler.dispatchMessage(Handler.java:99) 
                                               at android.os.Looper.loop(Looper.java:137) 
                                               at android.app.ActivityThread.main(ActivityThread.java:4745) 
                                               at java.lang.reflect.Method.invokeNative(Native Method) 
                                               at java.lang.reflect.Method.invoke(Method.java:511) 
                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                                               at dalvik.system.NativeStart.main(Native Method) 
07-16 13:21:02.008 123-205/? E/SocketStream: readFully was waiting for 687488 bytes, got 10220 
07-16 13:21:02.008 123-205/? E/SocketStream: readFully was waiting for 677268 bytes, got 16192 
07-16 13:21:02.008 123-205/? E/SocketStream: readFully was waiting for 661076 bytes, got 4248 
07-16 13:21:19.996 436-919/? E/BinaryDictionaryGetter: Could not find a dictionary pack
07-16 13:21:19.996 436-919/? E/ActivityThread: Failed to find provider info  for com.android.inputmethod.latin.dictionarypack
07-16 13:21:22.848 123-205/? E/SocketStream: readFully was waiting for 687488 bytes, got 16192 
07-16 13:21:22.860 123-205/? E/SocketStream: readFully was waiting for 671296 bytes, got 16192 
07-16 13:21:29.916 436-985/? E/ActivityThread: Failed to find provider info for com.android.inputmethod.latin.dictionarypack
07-16 13:21:29.956 436-985/? E/BinaryDictionaryGetter: Could not find a dictionary pack
07-16 13:21:32.412 123-205/? E/SocketStream: readFully was waiting for 687488 bytes, got 16192 
07-16 13:21:32.424 123-205/? E/SocketStream: readFully was waiting for 671296 bytes, got 16192 
07-16 13:39:36.892 1121-1121/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             java.lang.RuntimeException:   Unable to start activity ComponentInfo{com.example.toshiba.GpsBluetooth/com.example.toshiba.GpsBluetooth.Speedo}: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.Toolbar
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:130)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.Toolbar
                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:613)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
                                                 at android.app.Activity.setContentView(Activity.java:1867)
                                                 at com.example.toshiba.GpsBluetooth.Speedo.onCreate(Speedo.java:134)
                                                 at android.app.Activity.performCreate(Activity.java:5008)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                 at android.os.Looper.loop(Looper.java:137) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:4745) 
                                                 at java.lang.reflect.Method.invokeNative(Native Method) 
                                                 at java.lang.reflect.Method.invoke(Method.java:511) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                                                 at dalvik.system.NativeStart.main(Native Method) 
                                              Caused by: java.lang.reflect.InvocationTargetException
                                                 at java.lang.reflect.Constructor.constructNative(Native Method)
                                                 at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:587)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                                                 at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) 
                                                 at android.app.Activity.setContentView(Activity.java:1867) 
                                                 at com.example.toshiba.GpsBluetooth.Speedo.onCreate(Speedo.java:134) 
                                                 at android.app.Activity.performCreate(Activity.java:5008) 
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                 at android.os.Looper.loop(Looper.java:137) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:4745) 
                                                 at java.lang.reflect.Method.invokeNative(Native Method) 
                                                 at java.lang.reflect.Method.invoke(Method.java:511) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                                                 at dalvik.system.NativeStart.main(Native Method) 
                                              Caused by: java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.
                                                 at  android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:692)
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
                                                 at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:67)
                                                 at android.support.v7.widget.Toolbar.<init>(Toolbar.java:298)
                                                 at android.support.v7.widget.Toolbar.<init>(Toolbar.java:229)
                                                 at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                 at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                                                 at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) 
                                                 at android.app.Activity.setContentView(Activity.java:1867) 
                                                 at com.example.toshiba.GpsBluetooth.Speedo.onCreate(Speedo.java:134) 
                                                 at android.app.Activity.performCreatat android.app ctivityOnCreate(Instrumentation.java:1079) 
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                 at android.os.Looper.loop(Looper.java:137) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:4745) 
                                                 at java.lang.reflect.Method.invokeNative(Native Method) 
                                                 at java.lang.reflect.Method.invoke(Method.java:511) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                                                 at dalvik.system.NativeStart.main(Native Method) 
07-16 13:39:37.160 123-205/? E/SocketStream: readFully was waiting for 687488 bytes, got 16192 
07-16 13:39:37.160 123-205/? E/SocketStream: readFully was waiting for 671296 bytes, got 16192   
07-16 13:57:28.840 123-205/? E/SocketStream: readFully was waiting for 23616 bytes, got 16192 
07-16 13:57:29.184 1196-1196/? E/AndroidRuntime: FATAL EXCEPTION: main

任何帮助都将不胜感激。

3 个答案:

答案 0 :(得分:0)

你得到的是SecurityException : Neither user 10051 nor current process has android.permission.WAKE_LOCK

如果您的Target API为23或更高,请确保添加运行时权限以及Android Manifest中的运行时权限。

  

从Android 6.0(API级别23)开始,用户在应用运行时向应用授予权限,而不是在安装应用时授予权限。

有关详细信息,请参阅here

答案 1 :(得分:0)

确保您的AndroidManifest.xml文件中包含以下行:

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

并在运行时请求权限。有关详细信息,请参阅here

答案 2 :(得分:0)

尝试使用与原始版本相同的API级别创建genymotion的新虚拟设备,然后在该版本上运行您的应用。如果没关系,只需删除原始图像,因为其图像可能已损坏。你不会丢失任何东西,并且不值得花时间去尝试修复它。我想在你的错误logcat中指出这一行: -

This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.

解决这些问题的方法是: -

此问题已在此处报告Issue 214182: appcompat-v7 24.0.0 is incompatible with rasterized vectors.

其中一位开发者提到:

What version of the Gradle plugin are you using?

As of v2.0 of the Gradle plugin, library resources are never rasterized so this should never happen.

此解决方法是按照此官方链接更新您的Gradle。适用于Gradle发行说明的Android插件。

buildscript {
  ...
  dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0'
  }
}