Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!

Sven Sylta

+ Follow
since Aug 09, 2013
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sven Sylta

I 'm making an app that will use bluetooth to send messages.

Lets say I'm standing with a group of people(at most 7?) and all of them have bluetooth enabled on their android cellphones.
Is it then possible to discover and pair all of them(which is not paired before) in "one scanning"? The tutorials I've seen seems to find just one device and then the scanning stops.

This is how I want it to work:
I press a button and my scanning activity starts.
I find a device and allows it to get paired and add it to an ArrayAdapter.
The scanning continues...
I find another one which is already paired so it will not be added to the adapter.
The scanning continues...
And so on...

Is this possible? Or do I have to start the activity for each device? If it is possible, is it a bad/unstable approach?
3 years ago
The size of the text-file is 560 kilobytes and has about 24500 rows. Each row is added to a list. Maybe my phone is to old and slow? Phone-model: Samsung GT-S5570 with Android 2.3.4.
It takes about 30 seconds or more to read it and I'm pretty sure that my algorithms outside the RowReader-class is not the problem. Anyone else who has encountered a similar problem?

4 years ago

Steve Luke wrote:Will get back to you about URI. Half of it is 'why toURI() is needed'... but lack of time now for details.

I have been given a code-sceleton which I'm supposed to fill in. And the "row-reader"-class uses URI but I guess I could write my own "row-reader".

If I get the correct path then the File-object should work?
4 years ago

Steve Luke wrote:
Writing off a means to do something is almost always a red flag. Why don't you want to do it the easiest way?

Because I wanted to avoid passing Context or / ActivityMain.this( not sure what to pass exactly) through several classes and packages just to get a reference in order to read from the file. But as far as I understand, I have to.

I have now put the file in the /res/raw/ directory and I also had to change the file-name to lower-case-letters. "en_us2sv_sv.dict"

I need to find the file with the File-class. Something like File file = context.something(???); Is this possible?

I need to use File because later I must invoke toURI();

4 years ago
Is it even possible to read from a file the "ordinary/usual" way in an Android/Eclipse project? I want to do it without putting the files in the assets-folder and without using something like InputStream iS = resources.getAssets().open(fileName); ?
4 years ago

Rico Felix wrote:To solve you can either go up and out of the src directory then down into the dict directory or specify the absolute path from the root of the file system


Seeing that the RowReader class is within src/com/example/dict and the dict directory is relative to the src directory to access the file in that directory your path will have to be specified as ../../../../dict/en_US2sv_SV.dict or you can specify the absolute path as say /home/sven/workspace/Dictionary/dict/en_US2sv_SV.dict

I've tried both these suggestions but none of them worked so it would be great if the moderator could move this thread to the android forum? Thanks for your help.
4 years ago

Paul Clapham wrote:

Sven Sylta wrote:The dict-folder is on the same level as the source-folder.

But your code looks for it in the root directory. Remember, just because you see your code as an "Android project", that doesn't change how the operating system sees your file. If it starts with "/" then it starts looking for it in the root directory, not in your source directory.

I have tried without the "/" at the beginning but that didn't work either.

Just to clearify: In my project-folder I have the source folder and a dict-folder. The dict-folder contains the file i want to read. The dict-folder is not in the source-folder, maybe it should be(but I have tried this as well)?
4 years ago

Tony Docherty wrote:Try creating a File object for this path and print out the value returned from calling its getAbsolutePath() method. Is this value the same as the absolute path to the file on the file system?

If I understood correctly: File file = new File("/dict/en_US2sv_SV.dict"); --> file.getAbsolutePath() --> "/dict/en_US2sv_SV.dict". Yes it's the same.

I've tried to refresh, import, drag and drop but nothing works. The dict-folder is on the same level as the source-folder. Maybe it has something to do with it being an Android-project?

4 years ago
I attached two pictures that will help explain the problem. The Scanner in class RowReader can't find a file with this path: "/dict/en_US2sv_SV.dict".
The dict-folder is found at the bottom of the package-explorer. Maybe I should mention that this is an Android-project and I do not want to access the files from the assets-folder if it is possible to avoid.
Any ideas?

4 years ago

Ulf Dittmer wrote:You're setting "activity_main" as the layout, not "fragment_main" - which contains the spinners.

Thanks. I changed it to setContentView(R.layout.fragment_main); but it still didn't work. Then I removed this part from the onCreate()-method:

then, for some reason, it worked.
4 years ago
I don't understand why my spinnner is causing a nullpointerexception. Row 19 in the javacode. Is there somebody who have had the same problem or is able to figure it out? Thanks.


4 years ago
HI! I need some design-advice for my first Android-app. It is a translator between languages and the core of it is already done. So I only need help with the UI. I'm gonna use the MVC-model.

Graphically from top to bottom it looks like:

one big TEXT-VIEW

EDIT-TEXT (possible button)
From spinner 1 I choose the "from-language" and from spinner two I choose the "to-language".
Then I enter a prefix of a word in the Edit-text-view and all the words starting with that prefix displays in the Text-view.

Should I use multiple activity-classes? One activity-class for each view?

Hope this makes sense. Thanks!

4 years ago

Pawel Pawlowicz wrote:IX is an interface-type reference. Such reference can be cast without compiler error to every class (well... except final classes that don't implement that interface).

First cast:
You are casting IX reference to type B. B does not implement IX but some class that extends B could do that. Change B definition to final and you will see compile time error.

Great explanation.

Pawel Pawlowicz wrote:Second cast:
This cast is legal at compile time. You are getting compiler error because you are trying to cast variable a which does not exist!

I changed the variable to a3 and that caused a runtime-exception. Why is it not a complie-error instead since B and C are different branches. Same principle as the first casting?
4 years ago
I cannot figure out why one of the down-castings causes a runtime-error and the other causes a complie-error. I have read that some down-castings will not cause a compile-error because it *could* be the right type. And if it's not, a ClassCastException is thrown.
I my example, I don't see the difference. Can somebody explain this?

4 years ago
I have a piece of road which is a critical section. Only one car at a time can use it. In my monitor-class I have one enter()-method and one leave()-method. A boolean variable "occupied" is initially set to false. The lock-method confuses me.

Scenario: Car nr1 enters the critical section first. It locks the lock and sets occupied to true. Then it unlocks the lock and leaves the enter()-method. Now car nr1 one is driving in the critical section.
Then car nr2 tries to enter the critical-section. It invokes enter() and locks the lock. Then it has to wait(while-loop) for car nr1 to set the occupied-variable to false and to signal in order to continue.
What confuses me is that car nr2 has the lock while waiting for car nr1 to leave. How can car nr1 enter the leave()-method and signal when car nr2 has the lock?

4 years ago