String and character sequence error (force close) Android - android

I am facing a problem in solving this issue.
I have 30 smiley images. In a grid view I display all the 30 images. So when I select the image based on the position of the image, the corresponding special character will be displayed from SQLite DB. Before I send message to service it is like "hi :)". What I need is to replace the ":)" with the corresponding smiley image in the local folder of my project (eg. R.drawable.facea.png). I am able to fetch the data and replace ":)" with "aaaaa"(example). But when I try to replace the ":)" with Char Sequence (Image), I get 'force close error'. Where am I going wrong?
I have a function to draw image and I get image as in Character Sequence. How can I use the value in this function globally. I also tried to create a global variable and use the CS value globally. But I still get 'force close error.

You need to use a span (specifically an ImageSpan) to be able to embed bitmap in a string. I have written about this on my blog which also covers some common pitfalls.
If you still cannot get it to work I would suggest posting the precise details of what is going wrong: i.e. your code, and the stacktrace that is getting dumped to logcat.

Related

How to separate a string without removing the spaces

FireStore Array
I already retrieve the vaccine name and the number of count but the problem is the SPACE is also replace or being removed.
Retrived
I WANT TO OUTPUT THE ITEM LIKE THIS
WITH SPACE SAME VALUE IN THE FIRE STORE
I ALREADY GET IT USING THIS CODE BELOW IT I HOPE YOU GET THE POINT OF THE CODE BELOW CLICK THE LINKED TEXT TO SEE IT
IMAGE FOR THE CODE
Basically I used the Character.isDigit, isAlphabetic, isWhiteSpace
then save it to stringbuffer. then save it to my textview
I assigned my buffer variable for text to get also the whitespace.

App Inventor 2 "Invalid Index 0, Size is 0" Error

I am trying to create an Exercise Tracker app in App Inventor 2 for a school project, and everything seemed to be going great until I made it to the third screen.
I hit my start button and it said Invalid Index 0, Size is 0.
This is my code: MY CODE.
Randy: Here is al link to an .aia file for my app. Using this, you should be able to view all my code. Let me know what you find!!!!
It will be in the comments-sorry!!!
First of all,your open another screen's screen no was invalid.
After i fixed it and tested it in the AppInventor's Emulator and it didn't show any error.
But I suspect that your problem was came from the data type of the global Time.The data type for the global Time is integer and the data that you store in the TinyDB is not only contents integer value (you can try to displays it in a label).So I would suggest you to store it in "Text/String" type rather than "Number/Integer".
Below is my way to store the Date and Time in the TinyDB after proper format it:

Filter url JSON results using App Inventor 2

I'm trying to filter a JSON url results using App Inventor 2, following sample codes from here1 and here2, but I still cannot get it done right. I only get one result at a time.
The JSON results are data in the form shown in the following figure:
{
"field1":"alphaNumeric1",
"field2":"aNumber1",
"field3":"DD/MM/YY",
"field4":"HH/MM/SS",
"field5":"https://",
"field6":"aText",
"field7":"aNumber2",
"field8":"alphaNumeric2",
"field9":"aNumber3",
"field10":"alphaNumeric3"
}
The JSON url is constantly updated, so are the results, but this is not a problem for now. I can get it read by a timer.
The problem is that from the above results, I need to parse "field2", "field5", "field6", in according labels in the app.
So e.g., when I input a "aNumber1" to get searched in the JSON data, and have the result in a label.
Is it possible this JSON data search be done with App Inventor 2?
Anyone kind enough please answer with a sample blocks if possible.
Thank you all in advance!
[EDIT 1]
No matter what I've tried, JSON could not get filtered right. Therefore I'm to filter the url results in XML.
The XML results are data in the form shown in the following figure:
<results>
<decision>
<alphaNumeric1>ABC1D</alphaNumeric1>
<aNumber1>ABCD</aNumber1>
<aDate>123</aDate>
<doc>HTTP</doc>
<aNumber2>1234</aNumber2>
<alphaNumeric2>TYPE</talphaNumeric2>
<aNumber3>12345</aNumber3>
<aNumber4>1234567</aNumber4>
<aText>SomeText</aText>
<aHour>00:00:00</aHour>
</decision>
.
.
.
<decision>
.
.
.
</decision>
.
.
.
</results>
I have tried to follow the example at here2, but I don't get it right. According to the XML output, what should I put in starTag and endTag, to get a parsing result if I'm searching for e.g. aNumber4 value (= 1234567) ?
Can someone respond with an answer?
[EDIT 2]
Well I'm trying to make some progress here following the example at here3.
The XML is being parsed with a runtime error "this is not a well formatted list of pairs".
Following is the blocks code I'm using:
Why is that so, since I'm following the example to the letter? Any clues anyone to solve this out?
well, your blocks look a little bit strange...
you have a complex list of lists, just use Do it to find out, how it looks like after each step of using lookup in pairs...
It helps to follow the already provided links:
how to work with lists
how to work with list of lists (pdf) by appinventor.org
see also An example of a complex List of Lists
In the example blocks below I looked for the first <decision> and displayed the value of tag aDate in Label1 like this
you might want to loop through the different <decision>s using a for each in list loop....

Need a way to save a meteor.collection as a text file on a mobile

a newbie to Meteor, but I have created under localhost a simple passenger counter I intend to use on an android app for a passenger survey (holding a laptop in an airport isn't a particularly wise idea). It works, but there is no export function. Basically uses meteor.collection as simple rows of data - one row been one passenger with a date/time stamp, two buttons - Add Passenger and Reset. I have tried looking everywhere for a simple answer, but what I want to do is now add to the client side (on browser - but ultimately on the mobile) a button called export, and when clicked, takes each row in the meteor.collection and export it to a text file - line by line. Very simple. Alas right now I haven't got a clue how to proceed. Seen some references to FS.collection, but don't think there is what I want. This is ultimately for a mobile application.
Thanks.
JSON.stringify each object into a larger object of pure text, say bytes
Create a blob from that text object, ex: blob = new Blob([bytes]);
Use the filesaver package to save to a file locally.

Scan string for characters and return bounded text

I am writing a dictionary-type app. I have a list of hash-mapped terms and definitions. The basic premise is that there is a list of words that you tap on to see the definitions.
I have this functionality up and running - I am now trying to put dynamic links between the definitions.
Example: say the user taps on an item in the list, "dog". The definition might pop up, saying "A small furry [animal], commonly kept as a pet. See also [cat].". The intention is that the user can click on the word [animal] or [cat] and go to the appropriate definition. I've already gone to the trouble of making sure that any links in definitions are bounded by square brackets, so it's just a case of scanning the pop-up string for text [surrounded by brackets] and providing a link to that definition.
Note that definitions can contain multiple links, whilst some don't contain any links.
I have access to the string before it is displayed, so I guess the best way to do this is to do the scanning and ready the links before the dialog box is displayed.
The question is, how would I go about scanning for text surrounded by square brackets, and returning the text contained within those brackets?
Ideally the actual dialog box that is displayed would be devoid of the square brackets, and I need to also figure out a way of putting hyperlinks into a dialog box's text, but I'll cross that bridge when I come to it.
I'm new to Java - I've come from MATLAB and am just about staying afloat, but this is a less common task than I've had to deal with so far!
You could probably do this with a regular expression; something like this:
([^[]*)(\[[^]]+\])
which describes two "match groups"; the first of which means any string of zero or more characters that aren't "[" and the second of which means any string starting with "[", containing one or more characters that aren't "]", and ending with "]".
Then you could scan through your input for matches to this pattern. The first match group is passed through unchanged, and the second match group gets converted to a link. When the pattern stops matching your input, take whatever's left over and transmit that unchanged as well.
You'll have to experiment a little; regular expressions typically take some debugging. If your link text can only contain alphanumerics and spaces, your pattern would look more like this:
([^[]*)(\[[\s\w]+\])
Also, you may find that regular expression matching under Android is too slow to be practical, in which case you'll have to use wasyl's suggestion.
Quite simple, I think... As the text is in brackets, you need to scan every letter. So the basic recipe would be :
in a while loop scan every character (let's say, while i < len(text))
If scanned character is [:
i++;
Add letter at index i to some temporary variable
while (character # i) != ']' append it to the temporary variable
store this temporary variable in a list of results.
Some tips:
If you use solution above, use StringBuilder to append text (as regular string is immutable)
You might also want (and it's better, I think) to store starting and ending positions of all square brackets first, and then use string.substring() on each pair to get the text inside. This way you'd first iterate definition to find brackets (maybe catch unmatched ones, for early error handling), then iterate pairs of indices...
As for links, maybe this will be of use: How can I get clickable hyperlinks in AlertDialog from a string resource?

Categories

Resources