前提・実現したいこと
小数点2桁目まで表記しようと試みたがエラーが発生した。
解決方法がないでしょうか。
発生している問題・エラーメッセージ
11/22 13:38:17: Launching 'app' on MyQ(Pixel2). $ adb shell am start -n "com.example.intentapplication/com.example.intentapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Connected to process 22745 on device 'emulator-5554'. Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. I/tentapplicatio: Not late-enabling -Xcheck:jni (already on) E/tentapplicatio: Unknown bits set in runtime_flags: 0x8000 W/tentapplicatio: Unexpected CPU variant for X86 using defaults: x86 D/libEGL: Emulator has host GPU support, qemu.gles is set to 1. W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied) W/RenderThread: type=1400 audit(0.0:380): avc: denied { write } for name="property_service" dev="tmpfs" ino=7423 scontext=u:r:untrusted_app:s0:c137,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so W/tentapplicatio: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) W/tentapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) D/HostConnection: HostConnection::get() New Host Connection established 0xd1279be0, tid 22776 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0 D/EGL_emulation: eglCreateContext: 0xdc881860: maj 2 min 0 rcv 2 D/EGL_emulation: eglMakeCurrent: 0xdc881860: ver 2 0 (tinfo 0xdc8c7010) W/Gralloc3: mapper 3.x is not supported D/HostConnection: createUnique: call D/HostConnection: HostConnection::get() New Host Connection established 0xd127b710, tid 22776 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 D/eglCodecCommon: allocate: Ask for block of size 0x1000 allocate: ioctl allocate returned offset 0x3ff00a000 size 0x2000 D/EGL_emulation: eglMakeCurrent: 0xdc881860: ver 2 0 (tinfo 0xdc8c7010) D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
該当のソースコード
package com.example.intentapplication; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import androidx.appcompat.app.AppCompatActivity; public class SecondActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); setTitle("second Activity"); final Intent inIntent = getIntent(); final double hapValue = inIntent.getDoubleExtra("Num1", 0) / inIntent.getDoubleExtra("Num2", 1); Button buttonBack = (Button) findViewById(R.id.buttonBack); buttonBack.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent outIntent = new Intent(getApplicationContext(), MainActivity.class); outIntent.putExtra("Hap", String.format("%.2f", hapValue)); setResult(RESULT_OK, outIntent); finish(); } }); } }
該当のソースコード 2
package com.example.intentapplication; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTitle("Main Activity"); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText editText1 = (EditText) findViewById(R.id.editText1); EditText editText2 = (EditText) findViewById(R.id.editText2); Intent intent = new Intent(getApplicationContext(), SecondActivity.class); intent.putExtra("Num1", Integer.parseInt(editText1.getText().toString())); intent.putExtra("Num2", Integer.parseInt(editText2.getText().toString())); startActivityForResult(intent, 0); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { int hap = data.getIntExtra("Hap", 0); Toast.makeText(getApplicationContext(), "Result" + hap, Toast.LENGTH_SHORT).show(); } } }
該当のソースコード xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp" /> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp" /> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="division" android:textSize="30dp" /> </LinearLayout>
該当のソースコード xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/buttonBack" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp" android:text="Comeback" /> </LinearLayout>
試したこと
final double hapValue = inIntent.getDoubleExtra("Num1", 0)
/ inIntent.getDoubleExtra("Num2", 1);
outIntent.putExtra("Hap", String.format("%.2f", hapValue));
intからdoubleに切り替えて出力するときに表示する結果を "%.2f" これに変更したのですがエラーが発生しました。
このプログラムを回しても結果は0.0%のみ表示されます。
私が望むのは 12/23した時答えが0.52が出るように表示させることです.
解決方法をお願いします。
補足情報(FW/ツールのバージョンなど)
CPU AMD Ryzen™ 7 3700X
マザーボード B450M 박격포
メモリー 삼성 32기가
グラフィックカード 2070s
パワー 마이크로닉스 700W
SSD 삼성전자 970 EVO PLUS NVMe M.2 2280
このパソコンは韓国で買ったものですべて韓国製品です。 CPUだけ除いてです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/11/22 07:14
2020/11/22 07:20
2020/11/22 07:36
2020/11/22 07:39
2020/11/22 08:35