小编rwo*_*cik的帖子

Android上的同类的类强制转换异常

我在Android上遇到了ClassCastException的奇怪问题.一个类不能被转换为同一个类:

java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.ClassCastException: com.example.model.BadeWrapper cannot be cast to com.example.model.BadgeWrapper

java.lang.ClassCastException: com.example.events.widgets.TouchyWebView cannot be cast to com.example.events.widgets.TouchyWebView

java.lang.ClassCastException: com.example.friends.widgets.FriendsTabView cannot be cast to com.example.friends.widgets.FriendsTabView
Run Code Online (Sandbox Code Playgroud)

当我找到有错误的行时,它所做的就是通过id查找视图或使用参数创建片段,例如:

FriendsTabView friendsTabView;
friendsTabView = (FriendsTabView) view.findViewById(R.id.friends_bottom_tab_panel);
Run Code Online (Sandbox Code Playgroud)

正如我的BugSense所说,这个问题只发生在带有android 5.0.0(三星SM-G900F)的三星Galaxy S5上.我在其他设备上从未遇到过这个问题:

  • 摩托罗拉Moto G第一代(Android 5.0.1)
  • 三星Galaxy S3 Mini(Android 4.1.2)
  • LG G2 Mini(Android 4.4.2)
  • 索尼Xperia L(Android 4.1.2)

有没有人遇到过这个问题?有没有办法解决它?

android classcastexception findviewbyid

19
推荐指数
1
解决办法
3845
查看次数

当从接收者的意图中获得额外收益时,抛出NullPointerException。仅在华为设备上

NullPointerException在我的应用程序中的bugtracker上发现了奇怪的东西。有趣的是,它仅在华为设备(Honor 7和P8 Lite)上发生。

因此,我运行了一些测试代码来检查这些设备是否确实存在问题。

这是我启动AlarmManager的代码:

final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    final Intent intent = new Intent(this, TestReceiver.class);
    intent.putExtra(Constants.contant1, new User("John"));
    intent.setAction(Constants.action1);

    final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 4882, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.cancel(pendingIntent);
    if (Build.VERSION.SDK_INT < 19) {
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pendingIntent);
    } else {
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pendingIntent);
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,我AlarmManager拨打了TestReceiver如下电话:

public class TestReceiver extends BroadcastReceiver {

private static final String TAG = TestReceiver.class.getName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Constants.action1)) {
            User text …
Run Code Online (Sandbox Code Playgroud)

java android nullpointerexception

5
推荐指数
1
解决办法
353
查看次数

设置"requried = false"时仍需要蓝牙LE

我已将我的清单设置为使用蓝牙低能耗功能,我希望它是可选的,但当我尝试更新Google Play商店中的应用时,它说我仍然需要BTLE功能,它会削减我的设备范围.

我添加了android:required="false"param,但它仍然无法正常工作.

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

<uses-feature
        android:name="android.hardware.bluetooth"
        android:required="false"/>

<uses-feature
        android:name="android.hardware.bluetooth_le"
        android:required="false"/>
Run Code Online (Sandbox Code Playgroud)

我的aapt转储徽章:

uses-feature-not-required: name='android.hardware.bluetooth'
uses-feature: name='android.hardware.bluetooth_le'
uses-feature: name='android.hardware.camera'
uses-feature-not-required: name='android.hardware.camera.autofocus'
uses-feature-not-required: name='android.hardware.camera.flash'
uses-feature-not-required: name='android.hardware.nfc'
uses-feature: name='android.hardware.screen.landscape'
uses-feature-not-required: name='android.hardware.touchscreen'
uses-feature-not-required: name='android.hardware.wifi'
uses-feature: name='android.hardware.screen.portrait'
Run Code Online (Sandbox Code Playgroud)

在正常的蓝牙功能上它可以工作,但在BTLE它没有.我正在使用Estimote SDK.

android bluetooth android-manifest android-gradle-plugin

2
推荐指数
1
解决办法
854
查看次数