java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rishabh.casino/com.example.rishabh.casino.Game}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference
Run Code Online (Sandbox Code Playgroud) 我刚刚将Android Studio更新为2.2,现在我的Kotlin项目无法构建.gradle synch工作正常,但在尝试构建时,我立即显示错误,内容如下:
Error:Execution failed for task ':app:compileDebugKotlin'.
> Could not initialize class com.intellij.ide.highlighter.JavaFileType
Run Code Online (Sandbox Code Playgroud)
我已经检查过我的Kotlin插件是最新的.这个错误听起来像是与IDE有关并突出显示Java代码?任何帮助,将不胜感激.
我目前有一个大约2000万行的MySQL表,我需要修剪它.我想删除其updateTime(插入时间戳)超过一个月的每一行
前.我没有亲自对表的顺序进行任何更改,因此数据应该按插入顺序排列,并且UNIQUE在两个字段上有一个键,id并且updateTime.我如何在短时间内完成这项工作?
我写了这样的代码:
-(IBAction)startCapture
{
//session object
captureSession = [[AVCaptureSession alloc]init];
captureSession.sessionPreset = AVCaptureSessionPresetMedium;
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
previewLayer.frame = CGRectMake(0, 10, 320, 200); ////self.view.frame; //
[self.view.layer addSublayer:previewLayer];
NSError *error = nil;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//input object
AVCaptureDeviceInput *inputDevice = [[AVCaptureDeviceInput alloc]initWithDevice:device error:&error];
[captureSession addInput:inputDevice];
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];
[captureSession addOutput:stillImageOutput];
[captureSession startRunning];
}
-(IBAction) captureNow
{
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections)
{ …Run Code Online (Sandbox Code Playgroud) 当我在我的应用程序中打开溢出菜单时,我看到菜单背景颜色的实心矩形显示在菜单本身的整个进入/退出动画中.这是一个动画显示这个(减速到75%的速度):

这个无关的彩色矩形的存在破坏了漂亮的进/出动画!如何在保留所有其他Toolbar样式的同时将其删除?
研究
我已经阅读了Toolbar关于SO的样式的一堆答案,以及Chris Banes关于这个主题的自己的帖子.似乎在过去的几年里,每个基础上的style/ theme标签的使用View都发生了变化,这使得很难在任何地方找到确定的信息.
我使用支持库的22.1.0到23.2.0(包括)版本重现了这一点.
应用文件
styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="ToolbarStyle" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">@color/colorPrimary</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:style="@style/ToolbarStyle" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
运行时视图分析
正如@Commonsware 建议的那样,我在运行时查看了视图层次结构.在结果中编辑:
菜单折叠(存在溢出按钮,没有神秘的额外矩形):
菜单已展开(溢出菜单视图单独显示Window):
Window当比较两个菜单(稳定)状态时,主应用程序视图层次结构(如原始显示)保持不变.因此我的猜测是,在菜单动画期间,额外的矩形会临时添加到主应用程序的窗口中,并在完成后立即删除.我不确定为什么会这样做 - 也许这是一个显示和隐藏溢出菜单的旧(现在未使用)方法的宿醉?如果我的推论是正确的,那么如果我们能够确定如何防止这种短暂的行为,那么这个问题就可以得到解决......
我正在使用Eclipse.在我的Android代码中,我使用了ProGuard.但是在导出APK时,我遇到了以下警告:
Proguard returned with error code 1. See console
Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: …Run Code Online (Sandbox Code Playgroud) 我编写了一个默认Snackbar.make方法的包装器,以将自定义样式应用于我的Snackbar实例.我的自定义包装器的方法签名如下:
public static Snackbar makeCustom(
@NonNull View view,
@StringRes int resId,
@Snackbar.Duration int duration)
Run Code Online (Sandbox Code Playgroud)
其中Snackbar.Duration注释中定义android.support.design.widget.Snackbar.java如下:
/**
* @hide
*/
@IntDef({LENGTH_INDEFINITE, LENGTH_SHORT, LENGTH_LONG})
@IntRange(from = 1)
@Retention(RetentionPolicy.SOURCE)
public @interface Duration {}
Run Code Online (Sandbox Code Playgroud)
当我makeCustom使用以下参数调用时:
makeCustom(
activity.findViewById(android.R.id.content),
messageResId,
Snackbar.LENGTH_SHORT);
Run Code Online (Sandbox Code Playgroud)
我在IDE(Android Studio)中看到以下错误:
如果我直接调用Snackbar.make,我看到没有这样的错误,它具有以下签名:
public static Snackbar make(
@NonNull View view,
@StringRes int resId,
@Duration int duration) {
Run Code Online (Sandbox Code Playgroud)
看来,当我在自己的方法签名中使用时,Android Studio无法识别满足以下任一约束的值
@IntDef({LENGTH_INDEFINITE, LENGTH_SHORT, LENGTH_LONG})
@IntRange(from = 1)
Run Code Online (Sandbox Code Playgroud)
应该被认为是有效,而不是期待的是值满足两者的上述约束同时(这是不可能的,因为 …
我试图了解如何CIAdditionCompositing工作。
作为测试的一部分,我创建了一个方形的中灰色图像:


和一个方形的黑色图像:


当我使用CIAdditionCompositing补丁组合这两个正方形图像时,我希望看到一个灰色正方形,其颜色与原始中灰色正方形完全匹配(因为黑色图像的所有颜色分量都具有值 0)。然而,最终的结果实际上比原始的灰度图像更亮:


我不明白这个结果是如何产生的。我对CIAdditionCompositing工作原理有什么误解?
在阅读 Android Architecture Components的官方指南时,在解释带有 Retrofit 请求的存储库层的部分中,有一段代码我似乎无法完全理解:
public class UserRepository {
private Webservice webservice;
// ...
public LiveData<User> getUser(int userId) {
// This is not an optimal implementation, we'll fix it below
final MutableLiveData<User> data = new MutableLiveData<>();
webservice.getUser(userId).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
// error case is left out for brevity
data.setValue(response.body());
}
});
return data;
}
}
Run Code Online (Sandbox Code Playgroud)
在这个阶段,我们正在初始化我们的LiveData对象:
final MutableLiveData<User> data = new MutableLiveData<>();
Run Code Online (Sandbox Code Playgroud)
然后在改造异步调用中,我们设置该变量的值。
由于这是一个异步调用,该方法不会只返回初始化的数据但从不返回设置的值吗?
android user-guide retrofit2 android-architecture-components
我正在构建一个针对5.0+的Android应用,它使用BLE连接到多个外围设备.这些外围设备中的每一个都具有许多(~10)特性.理想情况下,我想订阅这些特征中每一个特征的变化通知.
但是,我从阅读中理解的是,Android的蓝牙实施对可以激活的同时通知的数量实施了硬性限制.此问题确定了在Android蓝牙实施中定义限制的位置,并且还记录了限制随时间的变化:
最大并发活动通知(
BTA_GATTC_NOTIF_REG_MAX):
- Android 4.3上的4
- Android 4.4上的7
- Android 5.0+上的15
Dave Smith在此视频中确认了这些数字,并建议:
在5.0+设备上进行测试,但是,我发现,我似乎能够成功订阅更超过15个通知.到目前为止,我已经观察到:
这些通知订阅通过两项措施取得成功:
GATT_SUCCESS;这是好消息.一方面,更多"真实"通知==>减少手动轮询==>更好的用户体验.另一方面,无法创建导致"真实"通知设置失败的条件意味着我无法轻松编写或测试手动回退代码,一旦将此应用程序发布给真实用户,肯定会(?)需要这些代码.
android ×6
ios ×2
android-architecture-components ×1
annotations ×1
camera ×1
cifilter ×1
compositing ×1
core-image ×1
database ×1
iphone ×1
kotlin ×1
mysql ×1
porter-duff ×1
pruning ×1
retrofit2 ×1
user-guide ×1