Search Results

Search found 555 results on 23 pages for 'unchecked'.

Page 1/23 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Java generics SuppressWarnings("unchecked") mystery

    - by Johannes Ernst
    Why does code alternative(1) compile without warnings, and code alternative(2) produce an "unchecked cast" warning? Common for both: class Foo<T> { Foo( T [] arg ) { } } Alternative (1): class Bar<T> extends Foo<T> { protected static final Object [] EMPTY_ARRAY = {}; @SuppressWarnings("unchecked") Bar() { super( (T []) EMPTY_ARRAY ); } } Alternative (2): class Bar<T> extends Foo<T> { @SuppressWarnings("unchecked") Bar() { super( (T []) EMPTY_ARRAY ); } protected static final Object [] EMPTY_ARRAY = {}; } Alternative (2) produces: javac -Xlint:unchecked Foo.java Bar.java Bar.java:4: warning: [unchecked] unchecked cast super( (T []) EMPTY_ARRAY ); ^ required: T[] found: Object[] where T is a type-variable: T extends Object declared in class Bar 1 warning This is: java version "1.7.0_07" Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

    Read the article

  • Decision for Unchecked Exceptions in Scala

    - by Jatin
    As a java programmer, I have always been critical of Unchecked Exceptions. Mostly programmers use it as an en-route to coding easiness only to create trouble later. Also the programs (though untidy) with checked exceptions are much robust compared to unchecked counterparts. Surprisingly in Scala, there is nothing called Checked Exceptions. All the Java checked and unchecked are unchecked in Scala. What is the motivation behind this decision? For me it opens wide range of problems when using any external code. And if by chance the documentation is poor, it results in KILL.

    Read the article

  • [Java] Type safety: Unchecked cast from Object

    - by Matthew
    Hi, I try to cast an object to my Action class, but it results in a warning: Type safety: Unchecked cast from Object to Action<ClientInterface> Action<ClientInterface> action = null; try { Object o = c.newInstance(); if (o instanceof Action<?>) { action = (Action<ClientInterface>) o; } else { // TODO 2 Auto-generated catch block throw new InstantiationException(); } [...] Thank you for any help

    Read the article

  • Thunderbird adds ***UNCHECKED*** to subjects of GPG messages

    - by Roman Geber
    Thunderbird seems to consider it a great idea to add the string UNCHECKED in front of the subject of GPG encrypted messages. Well, its not a good idea but rather annoying. At first I thought it would be a mailserver thing, so I checked. No trace of it, anywhere. Same goes for the raw message source. When I look at it the subject appears untouched, therefore I assume its a Thunderbird thing. Does anyone know an option to turn this ill behavior off? Thanks a lot in advance! cu Roman

    Read the article

  • I can't find the cause of an "unchecked or unsafe operations" warning in Java.

    - by Peter
    Hello, as per the title I am struggling to find the cause of an "unchecked or unsafe operations" warning in some code. If I have the following code, it compiles without any warnings: public void test() { Set<String> mySet = new HashSet<String>(); Set<String> myNewSet = mySet; //do stuff } Now, if I change where mySet comes from, specifically as the result of a method call, I get the "unchecked yadda yadda" warning: public void test() { Set<String> myNewSet = this.getSet(); //do stuff } public Set getSet() { Set<String> set = new HashSet<String>(); return set; } I have tried and tried to work out what the problem is and I am completely stumped. The issue is present whether I use Sets or Lists. Why would the Set returned by the getSet method be any different to the Set in the first example? Any help would be greatly appreciated as while the warning isn't the end of the world, it is bugging the hell out of me! :( Regards

    Read the article

  • MVVM-Light EventToCommand Behavior for CheckBox Checked/Unchecked in Silverlight

    - by George Durzi
    I would like to handle the Checked and Unchecked events of a Checkbox control and execute a command in my ViewModel. I wired up an EventTrigger for both the Checked and Unchecked events as follows: <CheckBox x:Name="chkIsExtendedHr" IsChecked="{Binding Schedule.Is24Hour, Mode=TwoWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="Checked"> <GalaSoft_MvvmLight_Command:EventToCommand CommandParameter="{Binding IsChecked, ElementName=chkIsExtendedHr}" Command="{Binding Path=SetCloseTime, Mode=OneWay}" /> </i:EventTrigger> <i:EventTrigger EventName="Unchecked"> <GalaSoft_MvvmLight_Command:EventToCommand CommandParameter="{Binding IsChecked, ElementName=chkIsExtendedHr}" Command="{Binding Path=SetCloseTime, Mode=OneWay}" /> </i:EventTrigger> </i:Interaction.Triggers> </CheckBox> I defined a RelayCommand in my ViewModel and wired up an action for it: public RelayCommand<Boolean> SetCloseTime{ get; private set; } ... SetCloseTime= new RelayCommand<bool>(ExecuteSetCloseTime); The parameter in the action for the command always resolves to the previous state of the CheckBox, e.g. false when the CheckBox is checked, and true when the CheckBox is unchecked. void ExecuteSetCloseTime(bool isChecked) { if (isChecked) { // do something } } Is this expected behavior? I have a workaround where I have separate triggers (and commands) for the Checked and Unchecked and use a RelayCommand instead of RelayCommand<bool>. Each command executes correctly when the CheckBox is checked and unchecked. Feels a little dirty though - even dirtier than having UI code in my ViewModel :) Thanks

    Read the article

  • Force an unchecked call

    - by François Cassistat
    Hello, Sometimes, when using Java reflection or some special storing operation into Object, you end up with unchecked warnings. I got used to it and when I can't do anything about it, I document why one call is unchecked and why it should be considered as safe. But, for the first time, I've got an error about a unchecked call. This function : public <K,V extends SomeClass & SomeOtherClass<K>> void doSomethingWithSomeMap (Map<K,V> map, V data); I thought that calling it this way : Map someMap = ...; SomeClass someData = ...; doSomethingWithSomeMap(someMap, someData); would give me an unchecked call warning. Jikes does a warning, but javac gives me an error : Error: doSomethingWithSomeMap(java.util.Map,V) in SomeClass cannot be applied to (java.util.Map,SomeClass) Any way to force it to compile with a warning? Thanks.

    Read the article

  • [Java] Force an unchecked call

    - by François Cassistat
    Hello, Sometimes, when using Java reflection or some special storing operation into Object, you end up with unchecked warnings. I got used to it and when I can't do anything about it, I document why one call is unchecked and why it should be considered as safe. But, for the first time, I've got an error about a unchecked call. This function : public <K,V extends SomeClass & SomeOtherClass<K>> void doSomethingWithSomeMap (Map map, V data); I thought that calling it this way : Map someMap = ...; SomeClass someData = ...; doSomethingWithSomeMap(someMap, someData); would give me an unchecked call warning. Jikes does a warning, but javac gives me an error : Error: <K,V>doSomethingWithSomeMap(java.util.Map<K,V>,V) in SomeClass cannot be applied to (java.util.Map,SomeClass) Any way to force it to compile with a warning? Thanks.

    Read the article

  • How do I recover from an unchecked exception?

    - by erickson
    Unchecked exceptions are alright if you want to handle every failure the same way, for example by logging it and skipping to the next request, displaying a message to the user and handling the next event, etc. If this is my use case, all I have to do is catch some general exception type at a high level in my system, and handle everything the same way. But I want to recover from specific problems, and I'm not sure the best way to approach it with unchecked exceptions. Here is a concrete example. Suppose I have a web application, built using Struts2 and Hibernate. If an exception bubbles up to my "action", I log it, and display a pretty apology to the user. But one of the functions of my web application is creating new user accounts, that require a unique user name. If a user picks a name that already exists, Hibernate throws an org.hibernate.exception.ConstraintViolationException (an unchecked exception) down in the guts of my system. I'd really like to recover from this particular problem by asking the user to choose another user name, rather than giving them the same "we logged your problem but for now you're hosed" message. Here are a few points to consider: There a lot of people creating accounts simultaneously. I don't want to lock the whole user table between a "SELECT" to see if the name exists and an "INSERT" if it doesn't. In the case of relational databases, there might be some tricks to work around this, but what I'm really interested in is the general case where pre-checking for an exception won't work because of a fundamental race condition. Same thing could apply to looking for a file on the file system, etc. Given my CTO's propensity for drive-by management induced by reading technology columns in "Inc.", I need a layer of indirection around the persistence mechanism so that I can throw out Hibernate and use Kodo, or whatever, without changing anything except the lowest layer of persistence code. As a matter of fact, there are several such layers of abstraction in my system. How can I prevent them from leaking in spite of unchecked exceptions? One of the declaimed weaknesses of checked exceptions is having to "handle" them in every call on the stack—either by declaring that a calling method throws them, or by catching them and handling them. Handling them often means wrapping them in another checked exception of a type appropriate to the level of abstraction. So, for example, in checked-exception land, a file-system–based implementation of my UserRegistry might catch IOException, while a database implementation would catch SQLException, but both would throw a UserNotFoundException that hides the underlying implementation. How do I take advantage of unchecked exceptions, sparing myself of the burden of this wrapping at each layer, without leaking implementation details?

    Read the article

  • Why does WPF toggle button pulse once unchecked

    - by randyc
    Wihtin a Desktop app I have a toggle button: For the Checked event I am setting a value and then executing a method FilterView(); //ommitting code Unchecked state is just the opposite. resets a variable and executed the method again The question I have is I noticed when I uncheck the toggle button the button continues to pulse or flash ( going from blue to chrome) as if it still has focus. The button will stay like this until another button is clicked. Is there a way to remove this focus so that when the button is unchecked the button goes back to a unchecked state without the flashing / pulsing color. As you can see from above this is a standard toggle button no styles or custom I tested this on just a regular button and I found the same occured when clicked the button will continue to pulse / flash until another button is clicked. How do you work around this or prevent this effect from happening. Thank you

    Read the article

  • Should Java IOException have been an unchecked RuntimeException?

    - by Derek Mahar
    Do you agree that the designers of Java class java.io.IOException should have made it an unchecked run-time exception derived from java.lang.RuntimeException instead of a checked exception derived only from java.lang.Exception? I think that class IOException should have been an unchecked exception because there is little that an application can do to resolve problems like file system errors. However, in When You Can't Throw An Exception, Elliotte Rusty Harold claims that most I/O errors are transient and so you can retry an I/O operation several times before giving up: For instance, an IOComparator might not take an I/O error lying down, but — because many I/O problems are transient — you can retry a few times, as shown in Listing 7: Is this generally the case? Can a Java application correct I/O errors or wait for the system to recover? If so, then it is reasonable for IOException to be checked, but if it is not the case, then IOException should be unchecked so that business logic can delegate handling this exception to a separate system error handler.

    Read the article

  • Unchecked call to compareTo

    - by Dave Jarvis
    Background Create a Map that can be sorted by value. Problem The code executes as expected, but does not compile cleanly: http://pastebin.com/bWhbHQmT The syntax for passing Comparable as a generic parameter along to the Map.Entry<K, V> (where V must be Comparable?) -- so that the (Comparable) typecast shown in the warning can be dropped -- eludes me. Warning Compiler's cantankerous complaint: SortableValueMap.java:24: warning: [unchecked] unchecked call to compareTo(T) as a member of the raw type java.lang.Comparable return ((Comparable)entry1.getValue()).compareTo( entry2.getValue() ); Question How can the code be changed to compile without any warnings (without suppressing them while compiling with -Xlint:unchecked)? Related TreeMap sort by value How to sort a Map on the values in Java? http://paaloliver.wordpress.com/2006/01/24/sorting-maps-in-java/ Thank you!

    Read the article

  • Wi-Fi won't automatically connect (box in Windows configuration gets unchecked)

    - by greg88
    The checkbox that says "Use windows to configure my wireless network settings" keeps getting unchecked (Wirless Network Connection - Change advanced settings - Wireless networks tab.) How do I stop that from happening? (So the wi-fi will reconnect.) When I manually re-check the box, it automatically connects.) I have a D-Link AirPremier DWL-G550 PCI adapter. I installed the newest driver, 5.3.0.46, and that didn't solve the problem. I took the "Atheros Client Utility" (the program window says "D-Link AirPremier Client Utility" when you run it) out of the start menu, rebooted, and that didn't solve the problem. (That utility puts a signal bar similiar to the one MS Windows puts there, and it's gone now.) The D-Link client utility has an option to automatically connect to preferred networks, but it is greyed out. It is also greyed out if I install the driver and utility right off the D-Link installation CD, so the problem isn't that the utility and driver are incompatible versions. I want to use Windows to handle the connection anyway, as the D-Link utility is garbage. Windows XP SP3 w/all current updates.

    Read the article

  • Is there a way to force JUnit to fail on ANY unchecked exception, even if swallowed

    - by Uri
    I am using JUnit to write some higher level tests for legacy code that does not have unit tests. Much of this code "swallows" a variety of unchecked exceptions like NullPointerExceptions (e.g., by just printing stack trace and returning null). Therefore the unit test can pass even through there is a cascade of disasters at various points in the lower level code. Is there any way to have a test fail on the first unchecked exception even if they are swallowed? The only alternative I can think of is to write a custom JUnit wrapper that redirects System.err and then analyzes the output for exceptions.

    Read the article

  • Java exception translations

    - by user3079275
    Apologies if this has been discussed on other threads but I find it helps clarify my thinking when I am forced to write down my questions. I am trying to properly understand the concept of checked vs unchecked exceptions and exception translation in Java but I am getting confused. So far I understood that checked exceptions are exceptions that need to be always caught in a try/catch block otherwise I get a compile time error. This is to force programmers to think about abnormal situations that might happen at run time (like disk full etc). Is this right? What I did not get was why we have unchecked exceptions, when are they useful? Is it only during development time to debug code that might access an illegal array index etc? This confusion is because I see that Error exceptions are also unchecked as is RunTimeException but its not clear to me why they are both lumped together into an unchecked category?

    Read the article

  • Java unchecked method invocation

    - by Sam
    I'm trying to setup a multithreaded application using SQLite4java, and everything is working fine. However, according to the getting started tutorial I am meant to create an object of type "object" and in order to return a value of null (due to use of generic types). Here is the suggested code: queue.execute(new SQLiteJob<Object>() { protected Object job(SQLiteConnection connection) throws SQLiteException { // this method is called from database thread and passed the connection connection.exec(...); return null; } }); Source The following example code I created produces the same error: error: test.java:9: warning: [unchecked] unchecked method invocation: <T,J>execute(J) in com.almworks.sqlite4java.SQLiteQueue is applied to (query<java.lang.Integer>) queue.execute(new query<Integer>()); test.java: import com.almworks.sqlite4java.*; import java.util.ArrayList; import java.io.File; class test{ public static void main(String[] args){ File f = new File("file.db"); SQLiteQueue queue = new SQLiteQueue(f); queue.execute(new query<Integer>()); } } query.java: import com.almworks.sqlite4java.SQLiteException; import com.almworks.sqlite4java.SQLiteJob; import com.almworks.sqlite4java.SQLiteConnection; import com.almworks.sqlite4java.SQLiteStatement; import java.util.ArrayList; class query<T> extends SQLiteJob{ protected ArrayList<Integer> job(SQLiteConnection connection) throws SQLiteException{ ArrayList<Integer> ints = new ArrayList<Integer>(); //DB Stuff return ints; } } I have read a lot about how this particular message appears when people fail to specify a type for an ArrayList. However, I am not attempting to cast the object or do anything with it. It is merely a mechanism implemented by the library developers in order to return a null. I do not believe this to be an issue relating directly to the library, which is why I'm asking this on StackOverflow. I believe it all comes down to my lack of experience with generic types. I've already spent a few hours on this and don't feel like I am getting anywhere. How do I stop the warning?

    Read the article

  • C# Multi CheckboxList update inserts checked records but doesn't delete unchecked records

    - by DLL
    I have a multi checkboxlist on a formview. Both use queries in a tableadapter. I'm using VS 2012. When the user updates the form, I use the following code to update the checkbox data. If a user checks a new box, a new record is inserted correctly, however if the user unchecks a box the existing record is not deleted. The delete query works fine if I run it from the query builder in the table adapter, it's reaching the expected line in the code correctly, all values are correct and I receive no errors. I use a similar query to delete records when the form level data is deleted which works fine. The very last line is the one that doesn't work. Query: DELETE FROM [SLA_Categories] WHERE (([SLA_ID] = @SLA_ID) AND ([Choice_ID] = @Choice_ID)) protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) { if (FormView1.DataKey.Value != null) { Categs = (CheckBoxList)FormView1.FindControl("CheckBoxList1"); CurrentSLA_ID = (int)FormView1.DataKey.Value; } if (CurrentSLA_ID > 0) { foreach (ListItem li in Categs.Items) { // See if there's a record for the current sla in this category int CurrentChoice_ID = Convert.ToInt32(li.Value); SLADataSetTableAdapters.SLA_CategoriesTableAdapter myAdapter; myAdapter = new SLADataSetTableAdapters.SLA_CategoriesTableAdapter(); int myCount = (int)myAdapter.FindCategoryBySLA_IDAndChoice_ID(CurrentSLA_ID, CurrentChoice_ID); // If this category is checked and there is not an existing rec, insert one if (li.Selected == true && myCount < 1) { // Insert a rec for this sla myAdapter.InsertCategory(CurrentChoice_ID, CurrentSLA_ID); } // If this category is unchecked and there is and existing rec, delete it if (li.Selected == false && myCount > 0) { // Delete this rec myAdapter.DeleteCategoryBySLA_IDAndChoice_ID(CurrentChoice_ID, CurrentSLA_ID); } } } }

    Read the article

  • checkbox unchecked when i scroll listview in android

    - by Mathew
    I am new to android development. I created a listview with textbox and checkbox. When I check the checkbox and scroll it down to check some other items in the list view, the older ones are unchecked. How to avoid this problem in listview? Please guide me with my code. Here is the code: main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="List of items" android:textStyle="normal|bold" android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"></TextView> <ListView android:id="@+id/ListView01" android:layout_height="250px" android:layout_width="fill_parent"> </ListView> <Button android:text="Save" android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> </LinearLayout> This is the xml page I used to create dynamic list row: listview.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"></TextView> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10px" android:textColor="#0099CC"></TextView> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"> </EditText> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> This is my activity class. CustomListViewActivity.java: package com.listivew; import android.app.Activity; import android.os.Bundle; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.listview, parent, false); holder = new ViewHolder(); holder.text = (TextView) convertView .findViewById(R.id.TextView01); holder.text2 = (TextView) convertView .findViewById(R.id.TextView02); holder.txt = (EditText) convertView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) convertView.findViewById(R.id.chkbox1); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return convertView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // I want to print the text which is in the listview one by one. //Later i will insert it in the database // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } }catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } Please help me to slove this problem. I have referred in many places. But I could not get proper answer to solve this problem. Please provide me the code to avoid unchecking the checkbox while scrolling up and down. Thank you.

    Read the article

  • get value of checked[ALL] or unchecked box jquery

    - by python
    I have read this. http://stackoverflow.com/questions/2048485/jquery-checkbox <input type="checkbox" name="checkGroup" id="all"> <input type="checkbox" name="checkGroup" id="one" value="1"> <input type="checkbox" name="checkGroup" id="two" value="2"> <input type="checkbox" name="checkGroup" id="three" value="3"> <input type="hidden" name="storeCheck" value=""> $(function(){ $("#all").click(function(){ $("input:checkbox[name='checkGroup']").attr("checked",$(this).attr("checked")); }); $("input:checkbox[name='checkGroup']:not('#all')").click ( function(){ var totalCheckboxes = $("input:checkbox[name='checkGroup']:not('#all')").length; var checkedCheckboxes = $("input:checkbox[name='checkGroup']:not('#all'):checked").length; if ( totalCheckboxes === checkedCheckboxes ) { $("#all").attr("checked" , true ); } else { $("#all").attr("checked" , false ); } }); }); Demo I am trying to get the value of the checkboxs are checked as an array. for example if I checked All Get value array_check = 1,2,3 and passed this array to hidden name="storeCheck" otherwise: Get value of array_check( checkboxs checked ).and passed this array to hidden name="storeCheck"

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >