问:
Android ndk error asm types.h not found
After updating Android Studio to 2.3.3 and updating ndk bundles，my project fails to build. What does the error mean? It should be a bug of the IDE. How to fix the issue or how to go back to prior Android Studio/ndk versions?</p>

```<code>Error:注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: /home/noob/code/greatcompany/ExcellentApk/app/src/main/java/com/greatcompanyx/ExcellentApk/yjzb/CtrlNetTool.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildRelease'.
> Build command failed.
  Error while executing process /home/noob/Android/Sdk/cmake/3.6.3155560/bin/cmake with arguments {--build /home/noob/code/greatcompany/ExcellentApk/app/.externalNativeBuild/cmake/release/armeabi-v7a --target greatcompany-foot}
  [1/1] Re-running CMake...
  -- Configuring done
  使用Android编译设置
  -- Generating done
  -- Build files have been written to: /home/noob/code/greatcompany/ExcellentApk/app/.externalNativeBuild/cmake/release/armeabi-v7a
  [1/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o
  [2/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o
  [3/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o
  [4/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o
  [5/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o
  [6/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_posthandler.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_posthandler.cpp:5:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/utils/json/json.h:50:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdlib.h:36:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/malloc.h:22:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_feature_extractor.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_feature_extractor.cpp:5:
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_feature_extractor.h:18:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdlib.h:36:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/malloc.h:22:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/aec/aec.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/aec/aec.cpp:5:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:39:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ostream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iosfwd:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/postypes.h:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:44:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/wchar.h:32:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_kws.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_kws.cpp:6:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/utils/json/json.h:50:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdlib.h:36:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/malloc.h:22:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/Buffer.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/Buffer.cpp:5:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/Buffer.h:11:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3/Eigen/Core:80:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/complex:45:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/sstream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/istream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iosfwd:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/postypes.h:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:44:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/wchar.h:32:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/beamforming/delaysum.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/beamforming/delaysum.cpp:4:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming/delaysum.h:14:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3/Eigen/Dense:1:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3/Eigen/Core:80:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/complex:45:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/sstream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/istream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iosfwd:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/postypes.h:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:44:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/wchar.h:32:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  ninja: build stopped: subcommand failed.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
</code>```

答:
In Android studio 3.0 and ndk 15, I got this error too.
But I resolved this, but analyse it in chinese.

http://www.jianshu.com/p/27f98165d73d

Method :

```<code>if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
    include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
    include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
else()
    include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
endif()
</code>```

Method 2

SET(CMAKE_CXX_FLAGS "-isystem /home/cc/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi")

Method 3

include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)

Title: Android ndk error asm types.h not found

Body:
After updating Android Studio to 2.3.3 and updating ndk bundles，my project fails to build. What does the error mean? It should be a bug of the IDE. How to fix the issue or how to go back to prior Android Studio/ndk versions?

Error:注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: /home/noob/code/greatcompany/ExcellentApk/app/src/main/java/com/greatcompanyx/ExcellentApk/yjzb/CtrlNetTool.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildRelease'.
> Build command failed.
  Error while executing process /home/noob/Android/Sdk/cmake/3.6.3155560/bin/cmake with arguments {--build /home/noob/code/greatcompany/ExcellentApk/app/.externalNativeBuild/cmake/release/armeabi-v7a --target greatcompany-foot}
  [1/1] Re-running CMake...
  -- Configuring done
  使用Android编译设置
  -- Generating done
  -- Build files have been written to: /home/noob/code/greatcompany/ExcellentApk/app/.externalNativeBuild/cmake/release/armeabi-v7a
  [1/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o
  [2/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o
  [3/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o
  [4/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o
  [5/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o
  [6/17] Building CXX object src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_posthandler.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_posthandler.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_posthandler.cpp:5:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/utils/json/json.h:50:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdlib.h:36:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/malloc.h:22:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_feature_extractor.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_feature_extractor.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_feature_extractor.cpp:5:
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_feature_extractor.h:18:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdlib.h:36:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/malloc.h:22:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/aec/aec.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/aec/aec.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/aec/aec.cpp:5:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:39:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ostream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iosfwd:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/postypes.h:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:44:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/wchar.h:32:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/kws/sentence/Sentence_kws.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_kws.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/kws/sentence/Sentence_kws.cpp:6:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/utils/json/json.h:50:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdlib.h:36:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/malloc.h:22:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/Buffer.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/Buffer.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/Buffer.cpp:5:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/Buffer.h:11:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3/Eigen/Core:80:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/complex:45:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/sstream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/istream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iosfwd:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/postypes.h:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:44:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/wchar.h:32:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  FAILED: /home/noob/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/noob/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/noob/Android/Sdk/ndk-bundle/sysroot  -DANDROID -DNDEBUG -Dgreatcompany_foot_EXPORTS -I../../../../src/main/cpp/greatcompany-foot/src -I../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3 -I../../../../src/main/cpp/greatcompany-foot/src/utils -I../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -O3 -mfpu=neon -mfloat-abi=softfp -march=armv7-a -Wno-parentheses -Os -DNDEBUG  -fPIC   -std=gnu++11 -MD -MT src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o -MF src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o.d -o src/main/cpp/greatcompany-foot/CMakeFiles/greatcompany-foot.dir/src/modules/beamforming/delaysum.cpp.o -c /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/beamforming/delaysum.cpp
  In file included from /home/noob/code/greatcompany/ExcellentApk/app/src/main/cpp/greatcompany-foot/src/modules/beamforming/delaysum.cpp:4:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/modules/beamforming/delaysum.h:14:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3/Eigen/Dense:1:
  In file included from ../../../../src/main/cpp/greatcompany-foot/src/3rdparty/eigen3/Eigen/Core:80:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/complex:45:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/sstream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/istream:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:38:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/iosfwd:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/postypes.h:40:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:44:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/wchar.h:32:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/stdio.h:42:
  In file included from /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/sys/types.h:36:
  /home/noob/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  ninja: build stopped: subcommand failed.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Body:
In Android studio 3.0 and ndk 15, I got this error too.
But I resolved this, but analyse it in chinese.

http://www.jianshu.com/p/27f98165d73d

Method :

if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
    include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
    include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
else()
    include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
endif()

Method 2

SET(CMAKE_CXX_FLAGS "-isystem /home/cc/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi")

Method 3

include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)


来源: stackexchange

问:
Do-while loop not paying attention to the while in java
I'm trying to write a do while loop that will read a file that the user input and read it out and will loop until the user types end. The do part is working, but my while just isn't being activated and I'm struggling to figure out why.

```<code>public static void readingFiles() throws Exception {
    BufferedReader reader = null;
    Scanner input = null;
    boolean fileFound = true;
    do {
        System.out.print("Enter a file name or Type END to exit: ");

        input = new Scanner(System.in);

        if(input.hasNextLine())
                {
                    try {
                        File f = new File(input.nextLine());
                        reader = new BufferedReader(new FileReader(f));
                        String str = null;

                        while((str = reader.readLine()) != null)
                        {
                            System.out.println(str);
                        }

                    }
                    catch (FileNotFoundException e)
                    {
                        System.out.println("File Not Found. Please try again.");
                        fileFound = false;
                        continue;
                    }
                    catch (IOException e)
                    {
                        System.out.println("There was an IOException. Please try again.");
                        continue;
                    }
                    catch (Exception e)
                    {
                        System.out.println("There was an exception. Please try again.");
                        continue;
                    }
                    finally
                    {
                        {
                        if(fileFound)
                            reader.close();
                        }
            }
        }
     } while(!input.nextLine().equalsIgnoreCase("end"));
}
</code>```

I've tried using an if statement before my input.hasNextLine() but then it would ignore the rest of the whole program and do nothing and only typing end would work. I've tried using && in my current if statement too but that didn't work. And I tried using a boolean that I set to true if string contained end. I think the problem may be in the input.hasNextLine but I'm not sure why or what to change it to?

Thanks for any help

答:
Calling input.nextLine() again will not preserve your previous input string.

Store it in a variable, and compare that

```<code>public static void readingFiles() throws Exception {
    BufferedReader reader = null;
    String filename = null;
    Scanner input = new Scanner(System.in);
    boolean fileFound = true;
    do {
        System.out.print("Enter a file name or Type END to exit: ");
         if(input.hasNextLine()) {
             filename = input.nextLine();
                try {
                    File f = new File(filename);
                    // reader =
           ...
    } while (!filename.equalsIgnoreCase("end");
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to write a do while loop that will read a file that the user input and read it out and will loop until the user types end. The do part is working, but my while just isn't being activated and I'm struggling to figure out why.

public static void readingFiles() throws Exception {
    BufferedReader reader = null;
    Scanner input = null;
    boolean fileFound = true;
    do {
        System.out.print("Enter a file name or Type END to exit: ");

        input = new Scanner(System.in);

        if(input.hasNextLine())
                {
                    try {
                        File f = new File(input.nextLine());
                        reader = new BufferedReader(new FileReader(f));
                        String str = null;

                        while((str = reader.readLine()) != null)
                        {
                            System.out.println(str);
                        }

                    }
                    catch (FileNotFoundException e)
                    {
                        System.out.println("File Not Found. Please try again.");
                        fileFound = false;
                        continue;
                    }
                    catch (IOException e)
                    {
                        System.out.println("There was an IOException. Please try again.");
                        continue;
                    }
                    catch (Exception e)
                    {
                        System.out.println("There was an exception. Please try again.");
                        continue;
                    }
                    finally
                    {
                        {
                        if(fileFound)
                            reader.close();
                        }
            }
        }
     } while(!input.nextLine().equalsIgnoreCase("end"));
}

I've tried using an if statement before my input.hasNextLine() but then it would ignore the rest of the whole program and do nothing and only typing end would work. I've tried using && in my current if statement too but that didn't work. And I tried using a boolean that I set to true if string contained end. I think the problem may be in the input.hasNextLine but I'm not sure why or what to change it to?

Thanks for any help

Body:
Calling input.nextLine() again will not preserve your previous input string.

Store it in a variable, and compare that

public static void readingFiles() throws Exception {
    BufferedReader reader = null;
    String filename = null;
    Scanner input = new Scanner(System.in);
    boolean fileFound = true;
    do {
        System.out.print("Enter a file name or Type END to exit: ");
         if(input.hasNextLine()) {
             filename = input.nextLine();
                try {
                    File f = new File(filename);
                    // reader =
           ...
    } while (!filename.equalsIgnoreCase("end");


问:
How to bind counter value to the textblock?
I'd like to be able to see the counter value in the textblock which incremented on a click of the button. I need to bind it to the textblock. I am wondering what will be the correct way to do it.

XAML:

```<code><TextBlock Text="{Binding Path=counter}" />
<Button x:Name="Nextbt" Content="Next" Click="ClickNextButton"/>
</code>```

C#:

```<code>private void ClickNextButton(object sender, System.Windows.RoutedEventArgs e){
counter += 1;
if (counter == 1)
{

}
if (counter == 2)
{

}}
</code>```

Thank you in advance.

答:
1) Make a public property, that returns the counter value. Name it "Counter"

2) Implement INotifyPropertyChanged and call PropertyChanged(new PropertyChangedEventArgs("Counter")) for every change of the counter-value

3) Change your markup as follows:

```<code><TextBlock Text="{Binding Path=counter,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}" />
</code>```

This is only one possiblity of many. This link leads you to an overview of DataBinding. I could imagine that this document will clarify the above steps.

Update

As you wished in your comment, here an example, I assume you are in the main-window. I have changed some things against the above sequence: I have set the DataContext in the constructor. Therefore it is no more necessary to use a relative source for the Binding. Both ways are possible (and both are not very elegant, but to learn WPF-Databinding, they are appropriate). Maybe you try both, the only difference is the binding-declaration and the constructor code.

```<code>public partial class MainWindow : Window , INotifyPropertyChanged{

        public event PropertyChangedEventHandler PropertyChanged;
        int m_counter;

        public MainWindow() {
            InitializeComponent();
            DataContext=this;
        }

        public int Counter {
            get { return m_counter; }
            set {
                if (m_counter != value) {
                    m_counter = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("Counter"));
                }
            }
        }
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
            if (null != PropertyChanged) {
                PropertyChanged(this,e);
            }
        }

        private void ClickNextButton(object sender, System.Windows.RoutedEventArgs e){
             Counter += 1;
             if (Counter == 1) { }
             if (Counter == 2) { }
        }

        Continue with class declaration...
</code>```

And the XAML:

```<code>        <TextBlock Text="{Binding Path=Counter}" />
        <Button x:Name="Nextbt" Content="Next" Click="ClickNextButton"/>
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I'd like to be able to see the counter value in the textblock which incremented on a click of the button. I need to bind it to the textblock. I am wondering what will be the correct way to do it.

XAML:

<TextBlock Text="{Binding Path=counter}" />
<Button x:Name="Nextbt" Content="Next" Click="ClickNextButton"/>

C#:

private void ClickNextButton(object sender, System.Windows.RoutedEventArgs e){
counter += 1;
if (counter == 1)
{

}
if (counter == 2)
{

}}

Thank you in advance.

Body:
1) Make a public property, that returns the counter value. Name it "Counter"

2) Implement INotifyPropertyChanged and call PropertyChanged(new PropertyChangedEventArgs("Counter")) for every change of the counter-value

3) Change your markup as follows:

<TextBlock Text="{Binding Path=counter,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}" />

This is only one possiblity of many. This link leads you to an overview of DataBinding. I could imagine that this document will clarify the above steps.

Update

As you wished in your comment, here an example, I assume you are in the main-window. I have changed some things against the above sequence: I have set the DataContext in the constructor. Therefore it is no more necessary to use a relative source for the Binding. Both ways are possible (and both are not very elegant, but to learn WPF-Databinding, they are appropriate). Maybe you try both, the only difference is the binding-declaration and the constructor code.

public partial class MainWindow : Window , INotifyPropertyChanged{

        public event PropertyChangedEventHandler PropertyChanged;
        int m_counter;

        public MainWindow() {
            InitializeComponent();
            DataContext=this;
        }

        public int Counter {
            get { return m_counter; }
            set {
                if (m_counter != value) {
                    m_counter = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("Counter"));
                }
            }
        }
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
            if (null != PropertyChanged) {
                PropertyChanged(this,e);
            }
        }

        private void ClickNextButton(object sender, System.Windows.RoutedEventArgs e){
             Counter += 1;
             if (Counter == 1) { }
             if (Counter == 2) { }
        }

        Continue with class declaration...

And the XAML:

        <TextBlock Text="{Binding Path=Counter}" />
        <Button x:Name="Nextbt" Content="Next" Click="ClickNextButton"/>


问:
Scaling the UIView resets rotation
I am using this code to scale the view :

```<code>view.transform = CGAffineTransform(scaleX: 2, y: 2)
</code>```

It scales the view perfectly, But problem is that:

If I rotate the view first and then scale it, in this case also scaling works as required but it resets the rotation.

It should not reset the rotation.

答:
You are creating a transform that only has a scale and you are then applying just that scale to the view.

You want to apply the scale transform to the existing transform.

```<code>view.transform = view.transform.scaledBy(x: 2, y: 2)
</code>```

Title: Scaling the UIView resets rotation

Body:
I am using this code to scale the view :

view.transform = CGAffineTransform(scaleX: 2, y: 2)

It scales the view perfectly, But problem is that:

If I rotate the view first and then scale it, in this case also scaling works as required but it resets the rotation.

It should not reset the rotation.

Body:
You are creating a transform that only has a scale and you are then applying just that scale to the view.

You want to apply the scale transform to the existing transform.

view.transform = view.transform.scaledBy(x: 2, y: 2)


问:
Quicksort 3 way partition code is not doing what it's told
I need to make a quicksort method that utilizes 3 way partitioning. The algorithm I'm using can be found here https://algs4.cs.princeton.edu/lectures/23DemoPartitioning.pdf scroll down to the Dijkstra 3-way partitioning demo. For some arrays such as, 5 5 7 3 5 1 6 2 4 8, my method works. However when I put an array such as, 5 5 7 3 5 1 6 2 4 8 9 8, my code does not work properly. I get the output: 1 2 3 4 5 5 5 6 7 8 9 8. I know what the problem is, but I don't understand why my code isn't handling it. Here is my code:

```<code>import java.util.Scanner;

public class QuickSortDriver {

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        System.out.print("\n\nEnter array elements: ");
        String s = scan.nextLine();
        String[] token = s.split(" ");
        int[] array = new int[token.length];

        for(int i=0; i < array.length; i++)
            array[i] = Integer.parseInt(token[i]);

        quicksort(array, 0, array.length - 1);

        System.out.print("\nSorted array: ");

        for(int i = 0; i < array.length; i++)
            System.out.printf("%d ", array[i]);

        System.out.print("\n\n");
        scan.close();
    }

    public static void quicksort(int [] array, int low, int high)
    {
        //debugging: shows what the array is
        //before the while loop
        System.out.print("\n");
        for(int j = low; j <= high; j++)
            System.out.printf("%d ", array[j]);

        if(high <= low)
            return;

        int lt = low;
        int gt = high;
        int i = low;

        while(i <= gt)
        {
            if(array[i] < array[low])
                swap(array, lt++, i++);
            else if(array[i] > array[low])
                swap(array, i, gt--);
            else
                i++;
        }

        //debugging: shows what the array is
        //after the while loop
        System.out.print("\n");
        for(int j = low; j <= high; j++)
            System.out.printf("%d ", array[j]);

        quicksort(array, low, lt -1);
        quicksort(array, gt + 1, high);
    }

    public static void swap(int array[], int i, int j)
    {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

}
</code>```

I put the for loops that print out the array at the beginning and end of the sorting method for debugging purposes and by doing that I found the problem. Here is my input output with the debugging statements printed:

```<code>Enter array elements: 5 5 7 3 5 1 6 2 4 8 9 8

5 5 7 3 5 1 6 2 4 8 9 8
4 3 2 1 5 5 6 5 8 9 8 7
4 3 2 1
3 2 1 4
3 2 1
2 1 3
2 1
1 2
1

6 5 8 9 8 7
5 6 9 8 7 8
5
9 8 7 8
8 7 9 8 <--right here is the problem
8 7
7 8
7

Sorted array: 1 2 3 4 5 5 5 6 7 8 9 8
</code>```

When my program gets to the 9 8 7 8 part of the array, it should do this:

(Please follow along with the logic in the Dijkstra 3-way partitioning algorithm.)

```<code>9 8 7 8

i = 9 lt = 9 gt = 8(at end) increment i

9 8 7 8

i = 8 lt = 9 gt = 8(at end) swap i and lt and increment i

8 9 7 8

i = 7 lt = 9 gt = 8(at end) swap i and lt and increment i

8 7 9 8
</code>```

i = 8(at end) lt = 9 gt = 8(at end) Now at this point it should swap i and lt and increment i. However, it doesn't and I have no idea why. The condition in my while loop is while(i <= gt), therefore it should keep iterating at that point because i and gt are at the same indices (refer to the code), but it doesn't. If anyone here can help me fix this bug it would be greatly appreciated I'm literally about to start pulling my hair out.

答:
Try to use lt instead of low within your while loop. It should look like this:

```<code>    while(i <= gt)
    {
        if(array[i] < array[lt])
            swap(array, lt++, i++);
        else if(array[i] > array[lt])
            swap(array, i, gt--);
        else
            i++;
    }
</code>```

Body:
I need to make a quicksort method that utilizes 3 way partitioning. The algorithm I'm using can be found here https://algs4.cs.princeton.edu/lectures/23DemoPartitioning.pdf scroll down to the Dijkstra 3-way partitioning demo. For some arrays such as, 5 5 7 3 5 1 6 2 4 8, my method works. However when I put an array such as, 5 5 7 3 5 1 6 2 4 8 9 8, my code does not work properly. I get the output: 1 2 3 4 5 5 5 6 7 8 9 8. I know what the problem is, but I don't understand why my code isn't handling it. Here is my code:

import java.util.Scanner;

public class QuickSortDriver {

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        System.out.print("\n\nEnter array elements: ");
        String s = scan.nextLine();
        String[] token = s.split(" ");
        int[] array = new int[token.length];

        for(int i=0; i < array.length; i++)
            array[i] = Integer.parseInt(token[i]);

        quicksort(array, 0, array.length - 1);

        System.out.print("\nSorted array: ");

        for(int i = 0; i < array.length; i++)
            System.out.printf("%d ", array[i]);

        System.out.print("\n\n");
        scan.close();
    }

    public static void quicksort(int [] array, int low, int high)
    {
        //debugging: shows what the array is
        //before the while loop
        System.out.print("\n");
        for(int j = low; j <= high; j++)
            System.out.printf("%d ", array[j]);

        if(high <= low)
            return;

        int lt = low;
        int gt = high;
        int i = low;

        while(i <= gt)
        {
            if(array[i] < array[low])
                swap(array, lt++, i++);
            else if(array[i] > array[low])
                swap(array, i, gt--);
            else
                i++;
        }

        //debugging: shows what the array is
        //after the while loop
        System.out.print("\n");
        for(int j = low; j <= high; j++)
            System.out.printf("%d ", array[j]);

        quicksort(array, low, lt -1);
        quicksort(array, gt + 1, high);
    }

    public static void swap(int array[], int i, int j)
    {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

}

I put the for loops that print out the array at the beginning and end of the sorting method for debugging purposes and by doing that I found the problem. Here is my input output with the debugging statements printed:

Enter array elements: 5 5 7 3 5 1 6 2 4 8 9 8

5 5 7 3 5 1 6 2 4 8 9 8
4 3 2 1 5 5 6 5 8 9 8 7
4 3 2 1
3 2 1 4
3 2 1
2 1 3
2 1
1 2
1

6 5 8 9 8 7
5 6 9 8 7 8
5
9 8 7 8
8 7 9 8 <--right here is the problem
8 7
7 8
7

Sorted array: 1 2 3 4 5 5 5 6 7 8 9 8

When my program gets to the 9 8 7 8 part of the array, it should do this:

(Please follow along with the logic in the Dijkstra 3-way partitioning algorithm.)

9 8 7 8

i = 9 lt = 9 gt = 8(at end) increment i

9 8 7 8

i = 8 lt = 9 gt = 8(at end) swap i and lt and increment i

8 9 7 8

i = 7 lt = 9 gt = 8(at end) swap i and lt and increment i

8 7 9 8

i = 8(at end) lt = 9 gt = 8(at end) Now at this point it should swap i and lt and increment i. However, it doesn't and I have no idea why. The condition in my while loop is while(i <= gt), therefore it should keep iterating at that point because i and gt are at the same indices (refer to the code), but it doesn't. If anyone here can help me fix this bug it would be greatly appreciated I'm literally about to start pulling my hair out.

Body:
Try to use lt instead of low within your while loop. It should look like this:

    while(i <= gt)
    {
        if(array[i] < array[lt])
            swap(array, lt++, i++);
        else if(array[i] > array[lt])
            swap(array, i, gt--);
        else
            i++;
    }


问:
jQuery selector exclude child table
Here is the jQuery script try to remove the first column of a html table

```<code>var order_table = $('.hor-scroll').eq(1);
//alert(order_table.html());
var order_table_copy = order_table;

order_table_copy.find(".order-tables th:first-child").remove();
order_table_copy.find(".order-tables td:first-child").remove();
</code>```

but above script also remove the th, td of qty-table

the html

```<code><table cellspacing="0" class="data order-tables" style="width: 100%;">
   <colgroup>
      <col>
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
   </colgroup>
   <thead>
      <tr class="headings">
         <th width="1">Localisation</th>
         <th>Image</th>
         <th>Product</th>
         <th>Sku</th>
         <th><span class="nobr">Item Status</span></th>
         <th>Unit Price</th>
         <th class="a-center">Qty</th>
         <th>Subtotal</th>
         <th>Marge</th>
      </tr>
   </thead>
   <tbody class="even">
      <tr class="border">
         <td class="a-left"></td>
         <td class="a-center">
            <img src="" width="100px">
         </td>
         <td class="a-left">Laser Pants</td>
         <td class="a-left">test</td>
         <td class="a-center">Mixed</td>
         <td class="a-right">
            <span class="price-excl-tax">
            <span class="price">$64.99</span>
            </span>
            <br>
         </td>
         <td>
            <table cellspacing="0" class="qty-table">
               <tbody>
                  <tr>
                     <td>Ordered</td>
                     <td><strong>100</strong></td>
                  </tr>
                  <tr>
                     <td>Invoiced</td>
                     <td><strong>100</strong></td>
                  </tr>
                  <tr>
                     <td>Refunded</td>
                     <td><strong>9</strong></td>
                  </tr>
               </tbody>
            </table>
         </td>
         <td class="a-right">
            <span class="price-excl-tax">
            <span class="price">$6,499.00</span>
            </span>
            <br>
         </td>
         <td class="a-center">
            0<span>%</span>
         </td>
      </tr>
   </tbody>
   <tbody class="odd">
      <tr class="border">
         <td class="a-left"></td>
         <td class="a-center">
            <img src="" width="100px">
         </td>
         <td class="a-left">Laser Hoody</td>
         <td class="a-left">test</td>
         <td class="a-center">Invoiced</td>
         <td class="a-right">
            <span class="price-excl-tax">
            <span class="price">$84.99</span>
            </span>
            <br>
         </td>
         <td>
            <table cellspacing="0" class="qty-table">
               <tbody>
                  <tr>
                     <td>Ordered</td>
                     <td><strong>100</strong></td>
                  </tr>
                  <tr>
                     <td>Invoiced</td>
                     <td><strong>100</strong></td>
                  </tr>
               </tbody>
            </table>
         </td>
         <td class="a-right">
            <span class="price-excl-tax">
            <span class="price">$8,499.00</span>
            </span>
            <br>
         </td>
         <td class="a-center">
            0<span>%</span>
         </td>
      </tr>
   </tbody>
</table>
</code>```

but i can't exclude the qty-table, i had tried so many different but not work.

答:
Try order_table_copy.find(".order-tables th:first-child:not(.qty-table)")

Also look into :first-of-type. And also remember that jQuery selectors returns an array. So if all else fails, you can always use the js filter function of arrays.

Update: To avoid the td the the .qty-table, make sure that the selected td is not a td under the .qty-table

```<code>order_table_copy.find(".order-tables tr td:first-child:not(.qty-table td)").remove();
</code>```

Title: jQuery selector exclude child table

Body:
Here is the jQuery script try to remove the first column of a html table

var order_table = $('.hor-scroll').eq(1);
//alert(order_table.html());
var order_table_copy = order_table;

order_table_copy.find(".order-tables th:first-child").remove();
order_table_copy.find(".order-tables td:first-child").remove();

but above script also remove the th, td of qty-table

the html

   <colgroup>
      <col>
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
      <col width="1">
   </colgroup>

         Localisation
         Image
         Product
         Sku
         Item Status
         Unit Price
         Qty
         Subtotal
         Marge

         Laser Pants
         test
         Mixed

            $64.99

                     Ordered
                     100

                     Invoiced
                     100

                     Refunded
                     9

            $6,499.00

            0%

         Laser Hoody
         test
         Invoiced

            $84.99

                     Ordered
                     100

                     Invoiced
                     100

            $8,499.00

            0%

but i can't exclude the qty-table, i had tried so many different but not work.

Body:
Try order_table_copy.find(".order-tables th:first-child:not(.qty-table)")

Also look into :first-of-type. And also remember that jQuery selectors returns an array. So if all else fails, you can always use the js filter function of arrays.

Update: To avoid the td the the .qty-table, make sure that the selected td is not a td under the .qty-table

order_table_copy.find(".order-tables tr td:first-child:not(.qty-table td)").remove();


问:
How to test with Enzyme shallow and component based UIs?
We are using the  Semantic React UI library. The code often looks like:

```<code><div className="EditTemplateMetaDataPage">
        <Page title={...}>
          <Container text>
            <Segment>
              <Grid columns={1}>
                <Grid.Column>
                  <Button ...>
</code>```

This might be interesting for many people, using similar React Component libraries like Material UI or Bootstrap React.

We currently use mount with the enzyme library instead of shallow, because we would render only one level deep
, to the first <Grid> component in a test, which is just a visual helper, while we really need the deeper buried Button instead.

Because of performance and to avoid overlapping tests it is recommended to use shallow. (We follow London school TDD, and check only that sub-components exist and their interfaces are used properly)

We came up with using CSS-only for visual components, i.e.

```<code><div className='ui one column grid'>
</code>```

instead of:

```<code><Grid columns={1}>
</code>```

But we are not sure, whether this is the optimal approach. Do you have other ideas? How can we use shallow(...) in this case?

答:
shallow actually allow you to use your component as selector, so you can do something like

```<code>import Button from '../Button'

const page = shallow(<Page />)

expect(page.find(Button).length).toBe(1)
</code>```

http://airbnb.io/enzyme/docs/api/selector.html

Body:
We are using the  Semantic React UI library. The code often looks like:

        <Page title={...}>
          <Container text>
            <Segment>
              <Grid columns={1}>
                <Grid.Column>
                  <Button ...>

This might be interesting for many people, using similar React Component libraries like Material UI or Bootstrap React.

We currently use mount with the enzyme library instead of shallow, because we would render only one level deep
, to the first <Grid> component in a test, which is just a visual helper, while we really need the deeper buried Button instead.

Because of performance and to avoid overlapping tests it is recommended to use shallow. (We follow London school TDD, and check only that sub-components exist and their interfaces are used properly)

We came up with using CSS-only for visual components, i.e.

instead of:

<Grid columns={1}>

But we are not sure, whether this is the optimal approach. Do you have other ideas? How can we use shallow(...) in this case?

Body:
shallow actually allow you to use your component as selector, so you can do something like

import Button from '../Button'

const page = shallow(<Page />)

expect(page.find(Button).length).toBe(1)

http://airbnb.io/enzyme/docs/api/selector.html


问:
How to remove or hide Image Description field in TinyMCE image popup
First disclaimer, I am stuck in TinyMCE v4.2 as because of some stability and business issue.

What I want to do is, hide the Image Description field from the Image upload popup, thats something comes with their image plugin.

Here is a fiddle I created with my code so far I done for attaching data images in richtext.

NB: I know there is a option for disabling this in updated version of TinyMCE. I already read their doc and its as simple as having just a option

```<code>tinymce.init({
    image_description: false
});
</code>```

But what about the earlier version. I find no proper documentation for their older versions.

Any kind of help or idea is appreciatable. Thanks.

答: The ability to disable the image description is a relatively new feature introducted to TinyMCE. You won't be able to find a built-in feature that is synonymous with the image_description property in the newer versions.

Body:
First disclaimer, I am stuck in TinyMCE v4.2 as because of some stability and business issue.

What I want to do is, hide the Image Description field from the Image upload popup, thats something comes with their image plugin.

Here is a fiddle I created with my code so far I done for attaching data images in richtext.

NB: I know there is a option for disabling this in updated version of TinyMCE. I already read their doc and its as simple as having just a option

tinymce.init({
    image_description: false
});

But what about the earlier version. I find no proper documentation for their older versions.

Any kind of help or idea is appreciatable. Thanks.


问:
How to remove vertical dashed lines
Does anyone know how I can get rid of the lines shown in this screenshot?

Thanks a lot!

答:
For me I was using Visual Studio 2017 Professional and wanted to get rid of these as well. I was able to find the setting here:

Tools --> Options --> Text Editor --> General --> UNCHECK Show structure guide lines

Hope this helps

Title: How to remove vertical dashed lines


问:
SQL Update on Duplicate key
In SQL Server, I have a table with just one primary key but I need to Insert or Update if a set of columns (non primary) exists.

I know about the composed keys - multiple keys on a table but I can not alter the table.

Is there a way to do it on a single query, maybe a variable of the on duplicate key functionality? or should be resolve on several queries?

For example:

Table_Name: Contacts

Columns:

```<code>id (int) PK
Name (vc30)
usrName (vc20)
Email (vc30)
Pass (vc15)
otherUsrData (...)
</code>```

The constraint should be (usrName,Email)

You can have the same usrName with different emails each or different usrName with the same email (I know that sounds illogic but it's just an example)

```<code>1 - usr1 - email_A@example.com - textA
2 - usr1 - email_B@example.com - textA
3 - usr2 - email_A@example.com - textA
4 - usr2 - email_B@example.com - textA
</code>```

So a new record is generated with usr2 and email email_C, I insert it on the table, because the combination (user2,email_C) doesn't exist.

But if it's usr2 with email_B, then I will update textA to textB because there exists a record with a combination (user2,email_B)

答:
I think you can use MERGE-statement

```<code>DECLARE
  @usrName varchar(20)='usr1',
  @Email varchar(30)='email_A@example.com',
  @Pass varchar(15)='111';

-- update test
MERGE Contacts trg
USING
  (
    SELECT
      @usrName NewUsrName,
      @Email NewEmail,
      @Pass NewPass
  ) src
ON trg.usrName=src.NewUsrName AND trg.Email=src.NewEmail

WHEN MATCHED THEN
  UPDATE SET
    trg.Pass=src.Newpass

WHEN NOT MATCHED BY TARGET THEN
  INSERT(usrName,Email,Pass)
  VALUES(src.NewUsrName,src.NewEmail,src.NewPass);

SELECT *
FROM Contacts;

SET @usrName='usr1';
SET @Email='QQQ@example.com';
SET @Pass='222';

-- insert test
MERGE Contacts trg
USING
  (
    SELECT
      @usrName NewUsrName,
      @Email NewEmail,
      @Pass NewPass
  ) src
ON trg.usrName=src.NewUsrName AND trg.Email=src.NewEmail

WHEN MATCHED THEN
  UPDATE SET
    trg.Pass=src.Newpass

WHEN NOT MATCHED BY TARGET THEN
  INSERT(usrName,Email,Pass)
  VALUES(src.NewUsrName,src.NewEmail,src.NewPass);

SELECT *
FROM Contacts;
</code>```

Title: SQL Update on Duplicate key

Body:
In SQL Server, I have a table with just one primary key but I need to Insert or Update if a set of columns (non primary) exists.

I know about the composed keys - multiple keys on a table but I can not alter the table.

Is there a way to do it on a single query, maybe a variable of the on duplicate key functionality? or should be resolve on several queries?

For example:

Table_Name: Contacts

Columns:

id (int) PK
Name (vc30)
usrName (vc20)
Email (vc30)
Pass (vc15)
otherUsrData (...)

The constraint should be (usrName,Email)

You can have the same usrName with different emails each or different usrName with the same email (I know that sounds illogic but it's just an example)

1 - usr1 - email_A@example.com - textA
2 - usr1 - email_B@example.com - textA
3 - usr2 - email_A@example.com - textA
4 - usr2 - email_B@example.com - textA

So a new record is generated with usr2 and email email_C, I insert it on the table, because the combination (user2,email_C) doesn't exist.

But if it's usr2 with email_B, then I will update textA to textB because there exists a record with a combination (user2,email_B)

Body:
I think you can use MERGE-statement

DECLARE
  @usrName varchar(20)='usr1',
  @Email varchar(30)='email_A@example.com',
  @Pass varchar(15)='111';

-- update test
MERGE Contacts trg
USING
  (
    SELECT
      @usrName NewUsrName,
      @Email NewEmail,
      @Pass NewPass
  ) src
ON trg.usrName=src.NewUsrName AND trg.Email=src.NewEmail

WHEN MATCHED THEN
  UPDATE SET
    trg.Pass=src.Newpass

WHEN NOT MATCHED BY TARGET THEN
  INSERT(usrName,Email,Pass)
  VALUES(src.NewUsrName,src.NewEmail,src.NewPass);

SELECT *
FROM Contacts;

SET @usrName='usr1';
SET @Email='QQQ@example.com';
SET @Pass='222';

-- insert test
MERGE Contacts trg
USING
  (
    SELECT
      @usrName NewUsrName,
      @Email NewEmail,
      @Pass NewPass
  ) src
ON trg.usrName=src.NewUsrName AND trg.Email=src.NewEmail

WHEN MATCHED THEN
  UPDATE SET
    trg.Pass=src.Newpass

WHEN NOT MATCHED BY TARGET THEN
  INSERT(usrName,Email,Pass)
  VALUES(src.NewUsrName,src.NewEmail,src.NewPass);

SELECT *
FROM Contacts;


问:
Can you navigate the contents of a Vector's index via a String?
Is it possible to do something similar to this in Haxe?

```<code>private var _bindingsFiltered:Vector<String>;
_bindingsFiltered = new Vector<String>();

_controller_touched_binding.action = "meta_start";
</code>```

What I would like to be able to do:

```<code>_bindingsFiltered[_controller_touched_binding.action] = "BUTTON_13";
trace(_bindingsFiltered["meta_start"]); //result: "BUTTON_13"
</code>```

I want to be able to override a specific index too (still accessed via a string), with a new value, rather than keep pushing new content to the end of the vector. I have been using 'openfl.utils.Object' to cheat for now but I am looking for a more reliable approach for the long run.

Is there a way to do this in Haxe?

If not, what are my options?

I would also be interested in a solution for this in AS3, if there is one (avoiding the Array class).

My goal is to find a method that I can use in both languages seamlessly (next-to-none, differences).

答:
I think you could do this using flash.utils.Dictionary:

ActionScript

import flash.utils.Dictionary;

...

var _bindingsFiltered:Dictionary = new Dictionary ();

_bindingsFiltered[_controller_touched_binding.action] = "BUTTON_13";
trace(_bindingsFiltered["meta_start"]); //result: "BUTTON_13"
```

<h3>Haxe</h3>

<pre class="lang-js prettyprint-override"><code>import openfl.utils.Dictionary;

...

var _bindingsFiltered = new Dictionary<String, String> ();

_bindingsFiltered[_controller_touched_binding.action] = "BUTTON_13";
trace(_bindingsFiltered["meta_start"]); //result: "BUTTON_13"
</code>```

Body:
Is it possible to do something similar to this in Haxe?

private var _bindingsFiltered:Vector<String>;
_bindingsFiltered = new Vector<String>();

_controller_touched_binding.action = "meta_start";

What I would like to be able to do:

_bindingsFiltered[_controller_touched_binding.action] = "BUTTON_13";
trace(_bindingsFiltered["meta_start"]); //result: "BUTTON_13"

I want to be able to override a specific index too (still accessed via a string), with a new value, rather than keep pushing new content to the end of the vector. I have been using 'openfl.utils.Object' to cheat for now but I am looking for a more reliable approach for the long run.

Is there a way to do this in Haxe?

If not, what are my options?

I would also be interested in a solution for this in AS3, if there is one (avoiding the Array class).

My goal is to find a method that I can use in both languages seamlessly (next-to-none, differences).

Body:
I think you could do this using flash.utils.Dictionary:

ActionScript

import flash.utils.Dictionary;

...

var _bindingsFiltered:Dictionary = new Dictionary ();

_bindingsFiltered[_controller_touched_binding.action] = "BUTTON_13";
trace(_bindingsFiltered["meta_start"]); //result: "BUTTON_13"

Haxe

import openfl.utils.Dictionary;

...

var _bindingsFiltered = new Dictionary<String, String> ();

_bindingsFiltered[_controller_touched_binding.action] = "BUTTON_13";
trace(_bindingsFiltered["meta_start"]); //result: "BUTTON_13"


问:
Get image from script attached to gameobject using getComponent in Unity
I'm trying to introduce a radar scan feature so that when a button is clicked the image on the radar is updated based on the tag of the object with a new image. I'm getting a "NullReferenceException: Object reference not set to an instance of an object" on Enemy.GetComponent line in my Radar Scan Script.
but I have a image set?
dot 1 which I will now show below

Am I accessing it wrong? Here's my RadarScan script

```<code>public class RadarScan : MonoBehaviour
{
GameObject Enemy;
Image RadarImageToChange;

void Start()
{
    Enemy = GameObject.Find("Enemy");
}

public void ChangeImage(Image UpdateImage)
{
    if (Enemy.tag == "Enemy")
    {
        RadarImageToChange = Enemy.GetComponent<MakeRadarObject>().image;
        UpdateImage = RadarImageToChange;
    }

}
}
</code>```

Here's my radar Script

```<code>public class RadarObject
{
    public Image icon { get; set; }
    public GameObject owner { get; set; }
}

public class Radar : MonoBehaviour {

public Transform playerPos; //position of player
float mapScale = 0.1f; //scale radar size

public static List<RadarObject> radObjects = new List<RadarObject>();

//Registers Object to the radar
public static void RegisterRadarObject(GameObject o, Image i)
{
    Image image = Instantiate(i);
    radObjects.Add(new RadarObject() { owner = o, icon = image }); //adds to List
}

//It loops through the list looking for the owner existing in the list, when it finds the owner is detroys the icon
public static void RemoveRadarObject(GameObject o)
{
    //New list for destroyed objects
    List<RadarObject> newList = new List<RadarObject>();
    for (int i = 0; i < radObjects.Count; i++)
    {
        if (radObjects[i].owner == o)
        {
            Destroy(radObjects[i].icon);
            continue;
        }
         else
            newList.Add(radObjects[i]);
        }
    radObjects.RemoveRange(0, radObjects.Count);
    radObjects.AddRange(newList);
}

void DrawRadarDots()
{
    //loops through the list and for each Object it gets the owners transform position and determins the difference between it's
    //position and the players position, does calculations on the angle and distance and position on a circle using polar equations.
    foreach (RadarObject ro in radObjects)
    {
        Vector3 radarPos = (ro.owner.transform.position - playerPos.position);
        float distToObject = Vector3.Distance(playerPos.position, ro.owner.transform.position) * mapScale;
        float deltay = Mathf.Atan2(radarPos.x, radarPos.z) * Mathf.Rad2Deg - 270 - playerPos.eulerAngles.y;
        radarPos.x = distToObject * Mathf.Cos(deltay * Mathf.Deg2Rad) * -1;
        radarPos.z = distToObject * Mathf.Sin(deltay * Mathf.Deg2Rad);

        //grabs icon of players objects and make it a child of panel and set it's postion based on radarPos.x and radarPos.z
        ro.icon.transform.SetParent(this.transform);
        ro.icon.transform.position = new Vector3(radarPos.x, radarPos.z, 0) + this.transform.position;
    }
}

    //Update is called once per frame
    void Update ()
    {
        DrawRadarDots();
    }
 }
</code>```

Here is my stack trace

答:
Each Gameobject in your case does not directly contain Image as a component, but MakeRadarObject and RadarScan components.

```<code>Enemy.GetComponent<Image>();
</code>```

returns null as Enemy does not contain Image.

However, Enemy does contain MakeRadarObject.

```<code>RadarImageToChange = Enemy.GetComponent<MakeRadarObject>().variableContainingImage;
</code>```

Besides, you should be checking if Enemy is really an enemy or another gameobject.

Try adding

```<code>if (Enemy.tag == "Enemy") RadarImageToChange = Enemy.GetComponent<Image>();
</code>```

Body:
I'm trying to introduce a radar scan feature so that when a button is clicked the image on the radar is updated based on the tag of the object with a new image. I'm getting a "NullReferenceException: Object reference not set to an instance of an object" on Enemy.GetComponent line in my Radar Scan Script.
but I have a image set?
dot 1 which I will now show below

Am I accessing it wrong? Here's my RadarScan script

public class RadarScan : MonoBehaviour
{
GameObject Enemy;
Image RadarImageToChange;

void Start()
{
    Enemy = GameObject.Find("Enemy");
}

public void ChangeImage(Image UpdateImage)
{
    if (Enemy.tag == "Enemy")
    {
        RadarImageToChange = Enemy.GetComponent<MakeRadarObject>().image;
        UpdateImage = RadarImageToChange;
    }

}
}

Here's my radar Script

public class RadarObject
{
    public Image icon { get; set; }
    public GameObject owner { get; set; }
}

public class Radar : MonoBehaviour {

public Transform playerPos; //position of player
float mapScale = 0.1f; //scale radar size

public static List<RadarObject> radObjects = new List<RadarObject>();

//Registers Object to the radar
public static void RegisterRadarObject(GameObject o, Image i)
{
    Image image = Instantiate(i);
    radObjects.Add(new RadarObject() { owner = o, icon = image }); //adds to List
}

//It loops through the list looking for the owner existing in the list, when it finds the owner is detroys the icon
public static void RemoveRadarObject(GameObject o)
{
    //New list for destroyed objects
    List<RadarObject> newList = new List<RadarObject>();
    for (int i = 0; i < radObjects.Count; i++)
    {
        if (radObjects[i].owner == o)
        {
            Destroy(radObjects[i].icon);
            continue;
        }
         else
            newList.Add(radObjects[i]);
        }
    radObjects.RemoveRange(0, radObjects.Count);
    radObjects.AddRange(newList);
}

void DrawRadarDots()
{
    //loops through the list and for each Object it gets the owners transform position and determins the difference between it's
    //position and the players position, does calculations on the angle and distance and position on a circle using polar equations.
    foreach (RadarObject ro in radObjects)
    {
        Vector3 radarPos = (ro.owner.transform.position - playerPos.position);
        float distToObject = Vector3.Distance(playerPos.position, ro.owner.transform.position) * mapScale;
        float deltay = Mathf.Atan2(radarPos.x, radarPos.z) * Mathf.Rad2Deg - 270 - playerPos.eulerAngles.y;
        radarPos.x = distToObject * Mathf.Cos(deltay * Mathf.Deg2Rad) * -1;
        radarPos.z = distToObject * Mathf.Sin(deltay * Mathf.Deg2Rad);

        //grabs icon of players objects and make it a child of panel and set it's postion based on radarPos.x and radarPos.z
        ro.icon.transform.SetParent(this.transform);
        ro.icon.transform.position = new Vector3(radarPos.x, radarPos.z, 0) + this.transform.position;
    }
}

    //Update is called once per frame
    void Update ()
    {
        DrawRadarDots();
    }
 }

Here is my stack trace

Body:
Each Gameobject in your case does not directly contain Image as a component, but MakeRadarObject and RadarScan components.

Enemy.GetComponent<Image>();

returns null as Enemy does not contain Image.

However, Enemy does contain MakeRadarObject.

RadarImageToChange = Enemy.GetComponent<MakeRadarObject>().variableContainingImage;

Besides, you should be checking if Enemy is really an enemy or another gameobject.

Try adding

if (Enemy.tag == "Enemy") RadarImageToChange = Enemy.GetComponent<Image>();


问:
Suggestions for Looping in reactjs
There is an an array of objects. I want to put that in a loop to find whether the checked is true or false.. if it is true then i wanna concatinate with the value of each array. Any suggestions please</p>

```<code>plugin:[
{checked :true,value:'link', name:'link', id:'linkId'},
 {checked  :true,value:'plug', name:'plug', id:'plugId'},
 {checked :true, value:'switch', name:'switch', id:'switchId'},
]
</code>```

答:
Here you go :</p>

```<code>const plugin = [
    {checked :true,value:'link', name:'link', id:'linkId'},
    {checked  :true,value:'plug', name:'plug', id:'plugId'},
    {checked :true, value:'switch', name:'switch', id:'switchId'},
];

render() {
    return (
        <div>
        { plugin.map(el => {
            return el.checked ? el.value : null ;
        }) }
        </div>
    )
}
</code>```

Title: Suggestions for Looping in reactjs

Body:
There is an an array of objects. I want to put that in a loop to find whether the checked is true or false.. if it is true then i wanna concatinate with the value of each array. Any suggestions please

plugin:[
{checked :true,value:'link', name:'link', id:'linkId'},
 {checked  :true,value:'plug', name:'plug', id:'plugId'},
 {checked :true, value:'switch', name:'switch', id:'switchId'},
]

Body:
Here you go :

const plugin = [
    {checked :true,value:'link', name:'link', id:'linkId'},
    {checked  :true,value:'plug', name:'plug', id:'plugId'},
    {checked :true, value:'switch', name:'switch', id:'switchId'},
];

render() {
    return (
        <div>
        { plugin.map(el => {
            return el.checked ? el.value : null ;
        }) }
        </div>
    )
}


问:
Error:(52, 14) error: cannot find symbol method onPreExecute() on Android Studio
I'm trying out a login tutorial (Create an Android login system using MySQL) on Android Studio 3.0. I ran into these errors:

import android.os.AsyncTask; (Click here to see the error)

When I hover on it, it says:

Unused import statement

onPreExecute() (Click here to see the error)

The message shows:

Error:(52, 14) error: cannot find symbol method onPreExecute()

Can anybody help me out? I'm new to this. I'm sorry if the question is not that clear.

答: I feeling your question unclearly, if you have error: cannot find symbol method onPreExecute() so right click Source in your Asyntask class -> Override --> Implement method and figure out onPreExecute() method.


问:
In this node definition, why are we using the "Node" after the structure definition?
```<code>typedef struct node
{
 int data;
 struct node *next;
}Node;  // ???
</code>```

<p>I don't understand why we use the Node after the definition. What function does is perform? Does it prevent the structure from pointing to itself infinitely?
Question might sound stupid, by i'm still learning.
Thanks. </p>

答:
Here, You have Defined a struct, and declare a structure variable at the same time. typedef keyword is used in creating a type Node, which is of type as struct node.

So, you can easily use Node n1; instead of struct node n1.

Body:
typedef struct node
{
 int data;
 struct node *next;
}Node;  // ???

I don't understand why we use the Node after the definition. What function does is perform? Does it prevent the structure from pointing to itself infinitely?
Question might sound stupid, by i'm still learning.
Thanks.


问:
C++ how to format a pointer to an array of classes?
I want to read information from a file and put that information in an pointer to an array of classes. it keeps throwing an exception at us->setUserName(name); but if I change it to us[i]->setUserName(name); it says "expression must have pointer type". How can I fix this?

```<code>    const int SIZE = 100;
    User *us = new User[SIZE];

    input.open("Account.txt", ios::in);

    if (input)
    {
       input >> size;

       for (int i = 0; i < size; i++)
       {
          us = new User[i];
          getline(input, uName);
          us->setUserName(uName);

          getline(input, password);
          us->setPassword(password);

          getline(input, name);
          us->setName(name);
       }
    else
       cout << "Error opening file" << endl;
</code>```

here is the user class:

```<code>    class User
    {
    public:
      User();
      ~User();

      void setName(string);
      string getName();

      void setUserName(string);
      string getUserName();

      void setPassword(string);
      string getPassword();

      void setFollower(vector<User*>*);
      vector<User*>* getFollower();

      void setFollowing(vector<User*>*);
      vector<User*>* getFollowing();

    protected:
      string name;
      string userName;
      string password;

      vector <User*>* followers;
      vector <User*>* following;

  };
</code>```

答:
```<code>      us = new User[i];
</code>```

Here you throw away all the arrays you have created by this moment and allocate a new array and thus eventually get N(O²) leaked space.

First, remove this line. Next, you might use us[i] in the succeeding property settings but since it will be a reference to an array element, not a pointer, you'll need to call its methods via ., not ->.

BTW, in the listing you've provided one brace is missing, the one before else.

As a side note, you are using too many plain pointers in your class. You did manage to handle and cleanup them properly, didn't you?

As another side note, it is generally a bad idea to store usernames+passwords as plain text (are passwords hashes here?). :)

Body:
I want to read information from a file and put that information in an pointer to an array of classes. it keeps throwing an exception at us->setUserName(name); but if I change it to us[i]->setUserName(name); it says "expression must have pointer type". How can I fix this?

    const int SIZE = 100;
    User *us = new User[SIZE];

    input.open("Account.txt", ios::in);

    if (input)
    {
       input >> size;

       for (int i = 0; i < size; i++)
       {
          us = new User[i];
          getline(input, uName);
          us->setUserName(uName);

          getline(input, password);
          us->setPassword(password);

          getline(input, name);
          us->setName(name);
       }
    else
       cout << "Error opening file" << endl;

here is the user class:

    class User
    {
    public:
      User();
      ~User();

      void setName(string);
      string getName();

      void setUserName(string);
      string getUserName();

      void setPassword(string);
      string getPassword();

      void setFollower(vector<User*>*);
      vector<User*>* getFollower();

      void setFollowing(vector<User*>*);
      vector<User*>* getFollowing();

    protected:
      string name;
      string userName;
      string password;

      vector <User*>* followers;
      vector <User*>* following;

  };

Body:
      us = new User[i];

Here you throw away all the arrays you have created by this moment and allocate a new array and thus eventually get N(O²) leaked space.

First, remove this line. Next, you might use us[i] in the succeeding property settings but since it will be a reference to an array element, not a pointer, you'll need to call its methods via ., not ->.

BTW, in the listing you've provided one brace is missing, the one before else.

As a side note, you are using too many plain pointers in your class. You did manage to handle and cleanup them properly, didn't you?

As another side note, it is generally a bad idea to store usernames+passwords as plain text (are passwords hashes here?). :)


问:
How to schedule a task that runs php using window task scheduler?
I've been trying to run a php file using window task scheduler. I've tried using the .bat file, but it won't work.
Here's what I've done:

I've created a task "Download Image"

I've created a .bat file, and the content is:

"C:\xampp\php\php.exe" -f "D:\server\newxml\download.php";

The php file that I want to run is:

```<code>    ini_set('max_execution_time', 300);
    $doc = simplexml_load_file('xml_edit_feeds.xml');

    foreach ($doc->xpath("//item") as $item) {
        $name = $item->productname;
        $realname = preg_replace('/\s/', '',$name);
        $url = $item->thumbnail_url;
        $img = 'D:/server/newxml/imagethumbnail/'.$realname.'.png';
        $filename = 'D:server/newxml/imagethumbnail/'.$realname.'.png';
            file_put_contents($img, file_get_contents($url));
    }
?>
</code>```

This is the screen shoot of the windows task scheduler:

Is there something wrong from what I did? Thank you for your help

答:
Eureka! I got the answer to this, so, I what I've done is:

Set the Program/Script to: C:\xampp\php\php.exe

Set the arguments to: D:\path\to\php.php (In my case D:\server\newxml\download.php)

Set the start-in to the folder that contains download.php (php file that you want to run). In my case: D:\server\newxml\

Body:
I've been trying to run a php file using window task scheduler. I've tried using the .bat file, but it won't work.
Here's what I've done:

I've created a task "Download Image"

I've created a .bat file, and the content is:

"C:\xampp\php\php.exe" -f "D:\server\newxml\download.php";

The php file that I want to run is:

    ini_set('max_execution_time', 300);
    $doc = simplexml_load_file('xml_edit_feeds.xml');

    foreach ($doc->xpath("//item") as $item) {
        $name = $item->productname;
        $realname = preg_replace('/\s/', '',$name);
        $url = $item->thumbnail_url;
        $img = 'D:/server/newxml/imagethumbnail/'.$realname.'.png';
        $filename = 'D:server/newxml/imagethumbnail/'.$realname.'.png';
            file_put_contents($img, file_get_contents($url));
    }
?>

This is the screen shoot of the windows task scheduler:

Is there something wrong from what I did? Thank you for your help


问:
Android, parsing html, problem with strings in strings
Im trying to parse some html code line by line. However, when i search for a line that start with <td class="departure", i cant manage to syntax it correctly because of the string delimiter signs (") (what is the name of this sign in english anyway?) in the html. It sees two strings and departure as a variable in between.

Can anyone help me with this?

```<code>if (line.startsWith("   <td class="departure"")){

   result += Html.fromHtml(line) + " ";
}
</code>```

答:
Escape that character (it's called quotes) by using \:

```<code>if (line.startsWith("   <td class=\"departure\"")){

   result += Html.fromHtml(line) + " ";
}
</code>```

Body:
Im trying to parse some html code line by line. However, when i search for a line that start with <td class="departure", i cant manage to syntax it correctly because of the string delimiter signs (") (what is the name of this sign in english anyway?) in the html. It sees two strings and departure as a variable in between.

Can anyone help me with this?

if (line.startsWith("   <td class="departure"")){

   result += Html.fromHtml(line) + " ";
}

Body:
Escape that character (it's called quotes) by using \:

if (line.startsWith("   <td class=\"departure\"")){

   result += Html.fromHtml(line) + " ";
}


问:
How to get around lack of covariance with IReadOnlyDictionary?
I'm trying to expose a read-only dictionary that holds objects with a read-only interface. Internally, the dictionary is write-able, and so are the objects within (see below example code). My problem is that IReadOnlyDictionary doesn't support covariant conversions because of the reason outlined in the question here. This means I can't just expose my internal dictionary as a read only one.

So my question is, is there an efficient way to convert my internal dictionary to an IReadOnlyDictionary, or some other way to handle this? The options I can think of are:

Hold two internal dictionaries and keep them in sync.

Create a new dictionary when the property is accessed and cast all the objects within.

Cast the IReadOnly's back to NotReadOnly when using it internally.

1 seems like a pain, 2 seems highly inefficient. 3 sounds like the most promising at the moment, but is still ugly. Do I have any other options?

```<code>public class ExposesReadOnly
{
    private Dictionary<int, NotReadOnly> InternalDict { get; set; }
    public IReadOnlyDictionary<int, IReadOnly> PublicList
    {
        get
        {
            // This doesn't work...
            return this.InternalDict;
        }
    }

    // This class can be modified internally, but I don't want
    // to expose this functionality.
    private class NotReadOnly : IReadOnly
    {
        public string Name { get; set; }
    }
}

public interface IReadOnly
{
    string Name { get; }
}
</code>```

答:
Depending on your use case, you might be able to get away with exposing a Func<int,IReadOnly>.

```<code>public class ExposesReadOnly
{
    private Dictionary<int, NotReadOnly> InternalDict { get; set; }
    public Func<int,IReadOnly> PublicDictionaryAccess
    {
        get
        {
            return (x)=>this.InternalDict[x];
        }
    }

    // This class can be modified internally, but I don't want
    // to expose this functionality.
    private class NotReadOnly : IReadOnly
    {
        public string Name { get; set; }
    }
}

public interface IReadOnly
{
    string Name { get; }
}
</code>```

Body:
I'm trying to expose a read-only dictionary that holds objects with a read-only interface. Internally, the dictionary is write-able, and so are the objects within (see below example code). My problem is that IReadOnlyDictionary doesn't support covariant conversions because of the reason outlined in the question here. This means I can't just expose my internal dictionary as a read only one.

So my question is, is there an efficient way to convert my internal dictionary to an IReadOnlyDictionary, or some other way to handle this? The options I can think of are:

Hold two internal dictionaries and keep them in sync.

Create a new dictionary when the property is accessed and cast all the objects within.

Cast the IReadOnly's back to NotReadOnly when using it internally.

1 seems like a pain, 2 seems highly inefficient. 3 sounds like the most promising at the moment, but is still ugly. Do I have any other options?

public class ExposesReadOnly
{
    private Dictionary<int, NotReadOnly> InternalDict { get; set; }
    public IReadOnlyDictionary<int, IReadOnly> PublicList
    {
        get
        {
            // This doesn't work...
            return this.InternalDict;
        }
    }

    // This class can be modified internally, but I don't want
    // to expose this functionality.
    private class NotReadOnly : IReadOnly
    {
        public string Name { get; set; }
    }
}

public interface IReadOnly
{
    string Name { get; }
}

Body:
Depending on your use case, you might be able to get away with exposing a Func<int,IReadOnly>.

public class ExposesReadOnly
{
    private Dictionary<int, NotReadOnly> InternalDict { get; set; }
    public Func<int,IReadOnly> PublicDictionaryAccess
    {
        get
        {
            return (x)=>this.InternalDict[x];
        }
    }

    // This class can be modified internally, but I don't want
    // to expose this functionality.
    private class NotReadOnly : IReadOnly
    {
        public string Name { get; set; }
    }
}

public interface IReadOnly
{
    string Name { get; }
}