簡體   English   中英

不幸的是,該應用已停止

[英]unfortunately ,app has stopped

當我使用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

任何幫助,將不勝感激。

您正在收到SecurityException : Neither user 10051 nor current process has android.permission.WAKE_LOCK

如果您的Target API為23或更高版本,請確保添加運行時權限以及Android Manifest中的權限。

從Android 6.0(API級別23)開始,用戶在應用程序運行時(而不是在安裝應用程序時)授予應用程序權限。

有關更多信息,請參見此處

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

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

並在運行時請求權限。 有關更多信息,請參見此處

嘗試使用與原始設備相同的API級別創建一個新的genymotion虛擬設備,並在該設備上運行您的應用程序。 如果可以,請刪除原始圖片,因為其圖像可能已損壞。 您將不會丟失任何東西,也不值得花費時間嘗試對其進行修復。我要在您的錯誤日志中指出的行在這里:

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

這些的解決方案是:

此問題已在此處報告, 版本214182:appcompat-v7 24.0.0與柵格化矢量不兼容。

開發人員之一提到:

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'
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM