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

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 to … Read more

[Solved] Save CheckBox in Android Studio

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); final … Read more

[Solved] AWS Dev env setup with Gradle

The = operator invokes the set<Field> method in Groovy. This is the reason why the classpath of the runDynamoDB task only contains a single file. You should use the classpath(Object… paths) which appends to the classpath: Change the line to the following example to add the file to the default classpath: classpath files(…) // without … Read more

[Solved] Hash collision in Hashmap

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 it … Read more

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

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 bytes … Read more

[Solved] Inconsistency with else statements?

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) bar(); … Read more

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

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 context; … Read more

[Solved] HashMap key generation based on hashing

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 that … Read more

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

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 equivalent … Read more