如何实施罪恶。 COS。 android中的其他trignometric值

时间:2016-05-10 07:52:15

标签: android

  

如何在MainActivity中使用onclick方法在android中编写以下代码。作为Android格式的计算新手。我希望有人详细解释。

public class Test{ 

public static void main(String args[]){
 double degrees = 45.0;
 double radians = Math.toRadians(degrees);

 System.out.format("The value of pi is %.4f%n", Math.PI);
 System.out.format("The sine of %.1f degrees is %.4f%n", degrees, Math.sin(radians));

}
}
  

我试着用android格式写它。但它没有奏效。    任何帮助将不胜感激。

     

我试着编写的代码。

public void onclicksin (View v){
        double degrees = 45.0;
        double radians = Math.toRadians(degrees);

        screen.setText(display+radians+Math.PI);
        screen.setText(display+degrees+Math.sin(radians));
  

logcat的

05-10 14:59:49.221 889-889/? D/AndroidRuntime: CheckJNI is ON
05-10 14:59:50.451 889-889/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
05-10 14:59:50.471 83-236/? I/ActivityManager: Force stopping package scientific.calculator.cal.scientific_calculator uid=10047
05-10 14:59:50.471 83-236/? I/Process: Sending signal. PID: 863 SIG: 9
05-10 14:59:50.491 83-236/? I/ActivityManager:   Force finishing activity ActivityRecord{4161a620 scientific.calculator.cal.scientific_calculator/.Calculator}
05-10 14:59:50.511 83-435/? I/WindowManager: WIN DEATH: Window{415ffbd0 scientific.calculator.cal.scientific_calculator/scientific.calculator.cal.scientific_calculator.Calculator paused=true}
05-10 14:59:50.581 889-889/? D/AndroidRuntime: Shutting down VM
05-10 14:59:50.611 889-899/? I/AndroidRuntime: NOTE: attach of thread 'Binder Thread #3' failed
05-10 14:59:50.641 889-893/? D/dalvikvm: GC_CONCURRENT freed 95K, 79% free 446K/2048K, paused 1ms+1ms
05-10 14:59:51.201 902-902/? D/AndroidRuntime: CheckJNI is ON
05-10 14:59:51.981 902-902/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
05-10 14:59:52.011 83-94/? I/ActivityManager: START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=scientific.calculator.cal.scientific_calculator/.Calculator} from pid 902
05-10 14:59:52.021 83-94/? W/WindowManager: Failure taking screenshot for (180x300) to layer 21005
05-10 14:59:52.061 83-111/? I/WindowManager: createSurface Window{41613cb8 Starting scientific.calculator.cal.scientific_calculator paused=false}: DRAW NOW PENDING
05-10 14:59:52.091 902-902/? D/AndroidRuntime: Shutting down VM
05-10 14:59:52.121 902-914/? I/AndroidRuntime: NOTE: attach of thread 'Binder Thread #3' failed
05-10 14:59:52.121 912-912/? D/dalvikvm: Not late-enabling CheckJNI (already on)
05-10 14:59:52.201 83-237/? I/ActivityManager: Start proc scientific.calculator.cal.scientific_calculator for activity scientific.calculator.cal.scientific_calculator/.Calculator: pid=912 uid=10047 gids={}
05-10 14:59:52.351 902-906/? D/dalvikvm: GC_CONCURRENT freed 98K, 77% free 477K/2048K, paused 1ms+1ms
05-10 14:59:52.401 83-122/? W/NetworkManagementSocketTagger: setKernelCountSet(10047, 1) failed with errno -2
05-10 14:59:53.221 912-912/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
05-10 14:59:53.221 912-912/? I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
05-10 14:59:53.221 912-912/? W/dalvikvm: VFY: unable to resolve interface method 18900: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
05-10 14:59:53.221 912-912/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-10 14:59:53.231 912-912/? I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
05-10 14:59:53.231 912-912/? W/dalvikvm: VFY: unable to resolve interface method 18904: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
05-10 14:59:53.231 912-912/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-10 14:59:53.331 912-912/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
05-10 14:59:53.331 912-912/? W/dalvikvm: VFY: unable to resolve virtual method 399: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-10 14:59:53.331 912-912/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-10 14:59:53.331 912-912/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
05-10 14:59:53.331 912-912/? W/dalvikvm: VFY: unable to resolve virtual method 401: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-10 14:59:53.331 912-912/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-10 14:59:53.521 83-237/? I/WindowManager: createSurface Window{4161a438 scientific.calculator.cal.scientific_calculator/scientific.calculator.cal.scientific_calculator.Calculator paused=false}: DRAW NOW PENDING
05-10 14:59:53.621 912-912/? D/gralloc_goldfish: Emulator without GPU emulation detected.
05-10 14:59:53.651 912-912/? W/TextLayoutCache: computeValuesWithHarfbuzz -- need to force to single run
05-10 14:59:53.711 83-111/? I/ActivityManager: Displayed scientific.calculator.cal.scientific_calculator/.Calculator: +1s667ms
05-10 14:59:53.791 83-122/? W/NetworkManagementSocketTagger: setKernelCountSet(10005, 0) failed with errno -2
05-10 14:59:56.831 912-912/? D/AndroidRuntime: Shutting down VM
05-10 14:59:56.831 912-912/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x409961f8)
05-10 14:59:56.921 912-912/? E/AndroidRuntime: FATAL EXCEPTION: main
05-10 14:59:56.921 912-912/? E/AndroidRuntime: java.lang.IllegalStateException: Could not execute method for android:onClick
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:289)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.view.View.performClick(View.java:3480)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:13983)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:605)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:92)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at  android.app.ActivityThread.main(ActivityThread.java:4340)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:  Caused by: java.lang.reflect.InvocationTargetException
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.view.View.performClick(View.java:3480) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:13983) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:605) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:92) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:4340) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:  Caused by: java.util.UnknownFormatConversionException: Conversion: F
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1397)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.util.Formatter$FormatToken.checkFlags(Formatter.java:1334)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.util.Formatter.transform(Formatter.java:1440)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.util.Formatter.doFormat(Formatter.java:1079)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.util.Formatter.format(Formatter.java:1040)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.util.Formatter.format(Formatter.java:1009)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.String.format(String.java:1998)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.String.format(String.java:1972)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at scientific.calculator.cal.scientific_calculator.Calculator.onclicksin(Calculator.java:125)
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.view.View.performClick(View.java:3480) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:13983) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:605) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:92) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:4340) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
05-10 14:59:56.921 912-912/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
05-10 14:59:56.981 83-436/? W/ActivityManager:   Force finishing activity scientific.calculator.cal.scientific_calculator/.Calculator
05-10 14:59:56.991 83-436/? W/WindowManager: Failure taking screenshot for (180x300) to layer 21010
05-10 14:59:57.171 912-916/? D/dalvikvm: GC_CONCURRENT freed 221K, 4% free 10121K/10439K, paused 7ms+26ms
05-10 14:59:57.201 83-98/? I/WindowManager: createSurface Window{4162efc8  paused=false}: DRAW NOW PENDING
05-10 14:59:57.511 83-97/? W/ActivityManager: Activity pause timeout for ActivityRecord{4165d4c0 scientific.calculator.cal.scientific_calculator/.Calculator}
05-10 14:59:57.551 83-122/? W/NetworkManagementSocketTagger: setKernelCountSet(10005, 1) failed with errno -2
05-10 14:59:57.601 83-237/? I/WindowManager: createSurface Window{415eb1a8 com.android.launcher/com.android.launcher2.Launcher paused=false}: DRAW NOW PENDING
05-10 14:59:58.491 83-122/? W/NetworkManagementSocketTagger: setKernelCountSet(10047, 0) failed with errno -2
05-10 15:00:08.451 83-97/? W/ActivityManager: Activity destroy timeout for ActivityRecord{4165d4c0 scientific.calculator.cal.scientific_calculator/.Calculator}

2 个答案:

答案 0 :(得分:0)

在计算方面没有特定于Android的内容。只需使用标准Java Math类即可在Android应用程序中的特定操作中执行所有计算

答案 1 :(得分:0)

使用此:

screen.setText(display + radians + "" + Math.PI);

screen.setText(display + degrees + "" + Math.sin(radians));

如果你想打印像“sin(45)= x”这样的东西,你可以写

screen.setText("sin(" + degrees + ") = " + Math.sin(radians));

编辑:

请改用String.format()。例如screen.setText(String.format("The sine of %.1f degrees is %.4f%n", degrees, Math.sin(radians)));