小编Kil*_*ner的帖子

ActionBar操作项未显示

我有一个非常简单的代码,但即使经过长时间的谷歌搜索我也无法解决的问题.我希望在ActionBar中有一些Action Item,但每当我运行App时,我看到的只是一个带有App徽标和标题的ActionBar,但没有Action Item.

如果你可以帮助我,那将是很棒的,可能我只是错过了最明显的事情;)

这是我的ActionBarActivity中的方法:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
}
Run Code Online (Sandbox Code Playgroud)

这是ActionBar的相关.xml文件(名为main_activity_actions.xml):

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/action_search"
      android:icon="@drawable/ic_action_search"
      android:title="@string/action_search"
      android:showAsAction="always"  />
<item android:id="@+id/action_compose"
      android:icon="@drawable/ic_action_compose"
      android:title="@string/action_compose" 
      android:showAsAction="always"/>
</menu>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-actionbar

24
推荐指数
2
解决办法
2万
查看次数

如何检查两个对象在Kotlin中是否具有相同的类?

在Kotlin中,您可以使用检查对象是否是类的实例(包括继承) is

myObject is String
Run Code Online (Sandbox Code Playgroud)

但是,你怎么能检查,如果两个对象是的确切同一类?我正在寻找Python的模拟

type(obj1) is type(obj2)
Run Code Online (Sandbox Code Playgroud)

kotlin

15
推荐指数
1
解决办法
4210
查看次数

"断言失败:您需要等待运行时准备好"在JavaScript中调用C函数时出错

我正在尝试一个简单的例子,用JavaScript调用编译为.wasm的C函数.

这是counter.c文件:

#include <emscripten.h>

int counter = 100;

EMSCRIPTEN_KEEPALIVE
int count() {  
    counter += 1;
    return counter;
}
Run Code Online (Sandbox Code Playgroud)

我用它编译了它emcc counter.c -s WASM=1 -o counter.js.

我的main.jsJavaScript文件:

const count = Module.cwrap('count ', 'number');
console.log(count());
Run Code Online (Sandbox Code Playgroud)

我的index.html文件只加载正文中的两个.js文件,没有别的:

<script type="text/javascript" src="counter.js"></script>
<script type="text/javascript" src="main.js"></script>
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Uncaught abort("Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)") at Error

当我试着打电话count()的时候main.js.我怎么能等待运行时准备好?

javascript emscripten webassembly

9
推荐指数
1
解决办法
1969
查看次数

如何在急切执行模式下使用tf.data数据集?

在2018年TensorFlow开发者峰会的tf.data演讲中,Derek Murray提出了一种将tf.dataAPI与TensorFlow的急切执行模式相结合的方法(10:54).我尝试了那里显示的代码的简化版本:

import tensorflow as tf
tf.enable_eager_execution()

dataset = tf.data.Dataset.from_tensor_slices(tf.random_uniform([50, 10]))
dataset = dataset.batch(5)
for batch in dataset:
    print(batch)
Run Code Online (Sandbox Code Playgroud)

造成

TypeError: 'BatchDataset' object is not iterable
Run Code Online (Sandbox Code Playgroud)

我也尝试使用dataset.make_one_shot_iterator()dataset.make_initializable_iterator()迭代数据集,但它们导致了

RuntimeError: dataset.make_one_shot_iterator is not supported when eager execution is enabled.
Run Code Online (Sandbox Code Playgroud)

RuntimeError: dataset.make_initializable_iterator is not supported when eager execution is enabled.
Run Code Online (Sandbox Code Playgroud)

TensorFlow版本:1.7.0,Python版本:3.6

如何在tf.data急切的执行中使用API?

python tensorflow

9
推荐指数
2
解决办法
7574
查看次数

如何加载存储在子目录中的.wasm文件?

我正在尝试一个简单的例子,用JavaScript调用编译为.wasm的C函数.

这是counter.c文件:

#include <emscripten.h>

int counter = 100;

EMSCRIPTEN_KEEPALIVE
int count() {  
    counter += 1;
    return counter;
}
Run Code Online (Sandbox Code Playgroud)

我用它编译了它emcc counter.c -s WASM=1 -o counter.js.

我的main.jsJavaScript文件:

Module['onRuntimeInitialized'] = onRuntimeInitialized;
const count = Module.cwrap('count ', 'number');

function onRuntimeInitialized() {
    console.log(count());
}
Run Code Online (Sandbox Code Playgroud)

我的index.html文件只加载正文中的两个.js文件,没有别的:

<script type="text/javascript" src="counter.js"></script>
<script type="text/javascript" src="main.js"></script>
Run Code Online (Sandbox Code Playgroud)

它工作正常/打印101到控制台,但当我将counter.c文件移动到一个wasm子目录,用emscripten重新编译并更新script标签src="wasm/counter.js",counter.js脚本尝试counter.wasm从根目录而不是wasm子目录加载,我得到错误:

counter.js:190 failed to asynchronously prepare wasm: failed to load …

javascript emscripten webassembly

6
推荐指数
2
解决办法
1756
查看次数