JButton.setBackground不起作用

时间:2015-11-18 03:36:18

标签: jbutton

E/AndroidRuntime: FATAL EXCEPTION: main    
E/AndroidRuntime: Process: com.locationget, PID: 16663    
E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.locationget/com.locationget.MapActivity}: java.lang.IllegalArgumentException: accuracy=3    
E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)    
E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271    
E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:144)    
E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)    
E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)    
E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)    
E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5146)    
E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)    
E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)    
E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)     
E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)    
E/AndroidRuntime:  Caused by: java.lang.IllegalArgumentException: accuracy=3    
E/AndroidRuntime:     at android.location.Criteria.setAccuracy(Criteria.java:223)    
E/AndroidRuntime:     at com.getlocation.MapActivity.onCreate(MapActivity.java:47)    
E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5231)    
E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)    
E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)    
E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271    
E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:144)     
E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)        
E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)        
E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)        
E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5146)        
E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)     
E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)     
E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)       
E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)     
E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 

我希望在这个实例中使JButton的内部颜色为红色,但代码不起作用,它只是使JButton周围的边框变红

1 个答案:

答案 0 :(得分:0)

您必须将button.contentAreaFilled(false)更改为button.contentAreaFilled(true)。