[Solved] incompatible types: String cannot be converted to int even there’re no strings [closed]

[ad_1] You are passing two arguments as String type, “20”, “10”: int myBmi = myBmiCal(“20”, “10”); But it should be int type: int myBmi = myBmiCal(20, 10); “” – it means just empty String in Java. “20” – it means String with value 20. “20” and 20 are different types in Java. Here is documentation … Read more

[Solved] Save CheckBox in Android Studio

[ad_1] It is keeping the same state because you are using the same shared preference for both checkboxes. Also you can use only one editor public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox); final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); … Read more

[Solved] Hash collision in Hashmap

[ad_1] You could create your own type and create a bad hash function: public class BadHash { private String aString; public BadHash(String s) { aString = s; } public int hashCode() { return aString.length(); } public boolean equals(Object other) { // boilerplate stuff BadHash obj = (BadHash) other; return obj.aString.equals(aString); } } This will make … Read more

[Solved] Send/Receive byte[] via TCP Socket [closed]

[ad_1] Use the Socket class. There is no Poll method, however there are other methods that can be used to check the socket status. For example, you can use Socket.isOutputShutdown() to check if the output stream is available (Whether it has been shutdown or not), and you can use Socket.getInputStream().available() to get the number of … Read more

[Solved] Inconsistency with else statements?

[ad_1] First off, note that if and else always apply to the single statement that follows them. You can use { } to group multiple statements into a single compound statement, but the conditional then applies to the single { … } statement. Consider these two equivalent statements: if (foo) { bar(); } if (foo) … Read more

[Solved] How to use a method from other class Java Android onClick? [closed]

[ad_1] class MainActivity extends Activity { protected EditText textVoice; Button button; TextToVoice textToVoice; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ln_dialog); textVoice = (EditText) findViewById(R.id.textVoice); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { textToVoice = new TextToVoice(MainActivity.this,textVoice.getText().toString()); textToVoice.listenVoice(); } }); } public class TextToVoice extends MainActivity { String textString; Context … Read more

[Solved] HashMap key generation based on hashing

[ad_1] The problem here is that the hashCode of an array does not depend on the contents, but on the reference. That means that if you have two conjunction / disjunction keys that are equal, but the contained arrays are not the same objects, then the hashcode of the keys will be different. The solution … Read more

[Solved] Why does this basic Java boolean expression not work?

[ad_1] The ternary conditional operator must return a value. The second and third operands can’t be statements that don’t return anything. They must be expressions that return a value. You could switch it to : System.out.println(banana ? “True” : “False”); Note that banana == true || false is equivalent to banana == true, which is … Read more