我有一个非常简单的代码,但即使经过长时间的谷歌搜索我也无法解决的问题.我希望在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) 在Kotlin中,您可以使用检查对象是否是类的实例(包括继承) is
myObject is String
Run Code Online (Sandbox Code Playgroud)
但是,你怎么能检查,如果两个对象是的确切同一类?我正在寻找Python的模拟
type(obj1) is type(obj2)
Run Code Online (Sandbox Code Playgroud) 我正在尝试一个简单的例子,用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.js
JavaScript文件:
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
.我怎么能等待运行时准备好?
在2018年TensorFlow开发者峰会的tf.data演讲中,Derek Murray提出了一种将tf.data
API与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?
我正在尝试一个简单的例子,用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.js
JavaScript文件:
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 …