TranslatableText inside a LiteralText SendMessage - java

I want to program an item that posts the coordinates of certain ores in the chat.
But now my question is whether I can also put parts of the chat message as a translation or only hardcoded, so that it only outputs what I programmed.
I work with Minecraft fabric for 1.18.2 and the code below is what i have:
private void outputValuableCoordinates(BlockPos blockPos, PlayerEntity player, Block blockBelow) {
player.sendMessage(new LiteralText("Found "
+ blockBelow.asItem().getName().getString()
+ " at " +
"(" + blockPos.getX() + ", " + blockPos.getY() + "," + blockPos.getZ() + ")"), false);
}
And i would make a TranslatableText out of "Found" and "at"

Related

I can't set a string in a TextView in an Android app (using Java)

I'm building a simple calculator Android app in Java that will receive 2 numbers as inputs and when the user presses one of the 4 action buttons (+, -, *, /) the exercise and it's solution will appear in the bottom of the screen inside a TextView in this format:
{num1} {action} {num2} = {solution}
I tried to declare a string and form the exercise's string in it and in the end I used "setText" to change the TextView but instead of showing the full exercise when I run the app it shows something like "androidx.appcompat.widget.AppCom".
Here is an example for the string I form when the user clicks on the + button:
exerciseStr = etNum1.toString() + " + " + etNum2.toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));
Does anybody know what the issue may be?
You should call getText() befor calling toString():
exerciseStr = etNum1.getText().toString() + " + " + etNum2.getText().toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));
Change it to like this.
exerciseStr = etNum1.getText().toString() + " + " + etNum2.getText().toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));

Consecutive log prints - only the first printed (no visible error)

I have this code fragment in my java class:
catch (AuthenticationFailedException afe) {
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + "E-Mail " + protocol + encStr + " login failed on " + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer());
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + afe.getMessage());
IlientConf.logger.debug("Email integration AuthenticationFailedException", afe);
return false;
}
IlientConf.logger is a log4j logger.
The actual log that is printed contains only the first line. This is it:
[someuser,sapunlock#someuser.com#outlook.office365.com] E-Mail pop3
(SSL) login failed on sapunlock#someuser.com#outlook.office365.com
The second and the third log statements are lost somehow.
I really need the stack trace of the error, but I can't get it.
No other related error is shown in the log.
Please help me understand what the reason for this is.
P.S.: Of course I can change the log statements to show this better, but this is deployed at a customers environment and needs to be solved before the next version.

How to make a specific part of Text Bold in Java for Android Project? [duplicate]

This question already has answers here:
how to make a specific text on TextView BOLD
(30 answers)
Closed 4 years ago.
How to make certain part of Text to Bold ? In String pars I want this specific part of the text to be in bold "How Stock Market works ?" and the remaining part of the text should remain normal.
public class second extends AppCompatActivity {
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
textView = (TextView)findViewById(R.id.Text1);
String pars = "How Stock Market works ?\n" +
"They are called by the collective names of ‘buyers’ and
‘sellers’.\n" +
"\n" +
"So imagine that there is a ‘tug of war’ situation between the
‘buyers’ and the ‘sellers’. The one who wins this war will control the
price.\n" +
"\n" +
"Case 1] Buyers control the game:\n" +
"\n" +
"For the buyers to control the game, there has to be more
supply. More supply of shares would mean that sellers are desperate to sell
their part and hence this would give the control in the hands of buyers.\n"
+
"\n" +
"This makes the market such an interesting place! After all
predictability is boring and tedious. ";
textView.setText(pars);
textView.setMovementMethod(new ScrollingMovementMethod());
}
}
Use spannable String like below code..
private String string="\"How Stock Market works ?\\n\" +\n" +
" \"They are called by the collective names of ‘buyers’ and \n" +
"‘sellers’.\\n\" +\n" +
" \"\\n\" +\n" +
" \"So imagine that there is a ‘tug of war’ situation between the \n" +
"‘buyers’ and the ‘sellers’. The one who wins this war will control the \n" +
"price.\\n\" +\n" +
" \"\\n\" +\n" +
" \"Case 1] Buyers control the game:\\n\" +\n" +
" \"\\n\" +\n" +
" \"For the buyers to control the game, there has to be more \n" +
"supply. More supply of shares would mean that sellers are desperate to sell \n" +
" their part and hence this would give the control in the hands of buyers.\\n\" \n" +
"+\n" +
"\n" +
" \"\\n\" +\n" +
" \"This makes the market such an interesting place! After all \n" +
"predictability is boring and tedious. ";
private SpannableString spannableString=new SpannableString(string);
spannableString.setSpan(new StyleSpan(Typeface.BOLD), 0, 21, 0);
textView.setText(spannableString);

GWT Java calculate days between two dates on the server side

I am using GWT java. I have a report on the client side that I want to export to csv. So I am trying to create the report on the server side to pass back to the client side as a csv file so the user can store the csv file in their selected destination.
The following code works on the client side; however, does not work on the server side (i.e., "Print 6." is displayed and "Print 7." is not displayed on the server side). There is no error message. The dates are "2016-11-09" and "2000-02-02".
System.out.println(todays_date);
System.out.println(pack.getDob());
System.out.println("Print 6.");
float diffDOB = (CalendarUtil.getDaysBetween(pack.getDob(), todays_date));
System.out.println("Print 7.");
I was talking about this with a fiend, who is not a programmer, and she said why not just send the MS Excel formula. Brilliant! So I have removed all the calclations and am now sending:
fileContent.append(pack.getSurname() + "," + pack.getFirstname() + "," + pack.getScout_no() + "," +
pack.getgroup() + "," + pack.getDob() + "," + '"' + "=ROUNDDOWN(((TODAY()-E"+row+")/365),1)" + '"' + "," +
pack.getstartDate() + "," + '"' + "=ROUNDDOWN(((TODAY()-G"+row+")/365),1)" + '"' + "," +
'"' + "=EDATE(E"+row+",216)" + '"' + "\n");
The only issue now is that spaces in the string fields appear as + in the output file.

Writing and reading inherited objects from a file with bufferred reader

I am writing a librarian admin program and I have two classes: members and premium members. there is no real difference other than the fact that premium members can take out 5 books as opposed to only 3. I am using a buffered reader and writer to read these items but I am wonderring how (or If I can at all) read and write both objects to a single .txt file?
here's my code I have so far:
Member class
public String toString(int i) {
String stg = "";
stg += memID + "#" + name + "#" + surname + "#" + address + "#" + email + "#" + cellnum + "#" + num + "#" + accntTyp + "#" + pass + "#" + book1 + "#" + book2 + "#" + book3 + "#";
return stg;
}
I have yet to do premium members class (wanted to get an answer while i do it) but it would pretty much look the same with an exception of 2 extra books.

Categories

Resources