The problem is that when I use source code below, i receive cell id's only in 2G mode, if i switch to 3G mode i sometimes receive -1 for HSDPA or nothing for UMTS. Source code is:
for (int i = 0; i < neighCell.size(); i++) {
try {
NeighboringCellInfo thisCell = neighCell.get(i);
int thisNeighCID = thisCell.getCid();
int thisNeighRSSI = -113 + 2*thisCell.getRssi();
log("Base station "+(i+1)+":"+
"\nCellID: "+thisNeighCID+
"; RSSI: "+thisNeighRSSI+" dBm");
} catch (NumberFormatException e) {
e.printStackTrace();
NeighboringCellInfo thisCell = neighCell.get(i);
log(thisCell.toString());
}
}
Is there any way to get id's in 3G mode and especially for UMTS?
The -1 value you are getting corresponds to the value of the UNKNOWN_CID constant, which indicates the cell location is not available.
You can confirm this in the API here.
It also states that the get methods related with the information you want to acquire, only work in GSM. For UMTS and CDMA it treats them the same as unknown location.
Related
I have an unexpected issue with the sendKeys() method:
A long time before it all worked fine, but unexpectedly the (certain(!)) values are replaced when the code tries to set data into the input field:
For example, if I set value USER_NAME into the field, value replaced with /tmp/7d7b7...../upload123...file/USER_NAME. As we can see - some path was added into the USER_NAME value.
I added logs to the method and we can see a moment when the value was replaced:
clearInputFld(inputFld);
Log.info("INSIDE clearAndTypeIntoInputField() ---------> value after clearing: " + inputElement.getAttribute("value"));
Log.info("INSIDE clearAndTypeIntoInputField() ---------> value to set: " + value);
inputElement.sendKeys(value);
Log.info("INSIDE clearAndTypeIntoInputField() ---------> value after set: " + inputElement.getAttribute("value"));
Output:
INSIDE clearAndTypeIntoInputField() ---------> value after clearing:
INSIDE clearAndTypeIntoInputField() ---------> value to set: USER_NAME
INSIDE clearAndTypeIntoInputField() ---------> value after set: /tmp/7d7b7...../upload123...file/USER_NAME
So we can be sure - value sets exactly at the moment when value sets into the field.
Important to know, and conclusions:
Not all users replaced - Only several certain users! So I suppose a part of users is cached. But I do not understand the process with which this happens, why this happens, and where these users might be cached.
I also restarted the docker, so it seems the problem is not in the automatic side.
Is it possible that this issue occurs via the backend or UI part?
It looks like there is a script running on the page that changes the input you type, as this is a password field.
What I suggest is that you use the Robot object to mimic keyboard strokes.
First click on the text field using Selenium, then launch the Robot code (use package Java.awt):
Robot robot = null;
try {
robot = new Robot();
for (char c : textToType.toCharArray()) {
int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
if (KeyEvent.CHAR_UNDEFINED == keyCode) {
logger.error("Key code not found for character '" + c + "'");
} else {
try {
robot.keyPress(keyCode);
robot.delay(10);
robot.keyRelease(keyCode);
robot.delay(10);
} catch (Exception e) {
if (c == '_') {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_MINUS);
robot.keyRelease(KeyEvent.VK_MINUS);
robot.keyRelease(KeyEvent.VK_SHIFT);
}
if (c == ':') {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
}
}
}
}
robot.keyPress(KeyEvent.VK_ENTER);
} catch (Exception ex) {
logger.error(ex.getMessage());
}
According to Logs, I think there is something come with the value.
Suggest trying :
Get the changed text, do some operation, fill it back
string[] temp;
temp = (inputElement.Text).Split('/');
inputElement.Sendkeys(temp(temp.Length - 1));
I have a spreadsheet with a lot of formulas in it and several tabs. One of the tabs is for Input of numbers into 10 fields. Another tab is for viewing the output of calculated formulas.
Using Apache POI, I have opened the spreadsheet and input my numbers. The problem comes when I try to evaluate the spreadsheet.
I've tried
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
helper.createFormulaEvaluator();
evaluator.evaluateAll();
And I get an error (that nobody seems to have an answer for): Unexpected arg eval type (org.apache.poi.ss.formula.eval.MissingArgEval)] with root cause
So I've changed to evaluating cells individually so I could find which cell has the error, so my code looks like this:
FormulaEvaluator evaluator = this.workbook.getCreationHelper().createFormulaEvaluator();
for (Sheet sheet : this.workbook) {
System.out.println("Evaluating next sheet");
System.out.println(sheet.getSheetName());
for (Row r : sheet) {
System.out.println("Row Number:");
System.out.println(r.getRowNum());
for (Cell c : r) {
if (c.getCellType() == Cell.CELL_TYPE_FORMULA) {
System.out.println(c.getColumnIndex());
try {
evaluator.evaluateFormulaCell(c);
} catch (Exception e) {
rowArray.add(r.getRowNum());
cellArray.add(c.getColumnIndex());
System.out.println("Skipping failed cell");
}
}
}
}
And I'm getting the same error as when I run evaluateAll.
By putting the little bit of debugging in there, I found that the error is coming from Cell L3, which contains formula: =D5. Since the evaluator goes by row:column, it evaluates everything on row 3 first before getting to 5, so L3 references a field that has not been evaluated yet, and therefore throws an error.
I tried catching the errors and storing the row and cell number in an array, then after everything in a sheet is processed, attempt to reprocess the unprocessed cells, but I still get the same result. I'm a bit perplexed why the retry didn't work.
Retry code:
// try to fix any failed evaluations here
Iterator cellItr = cellArray.iterator();
Iterator rowItr = rowArray.iterator();
while (cellItr.hasNext()) {
Integer cellElement = (int) cellItr.next();
Integer rowElement = (int) rowItr.next();
XSSFRow row = sheet.getRow(rowElement);
XSSFCell cell = row.getCell(cellElement);
System.out.println("Re-evaluating: " + rowElement + " : " + cellElement);
evaluator.evaluateFormulaCell(cell);
}
}
The retry code gave the same result.
I tried changing the original evaluator to use evaluateInCell to change the formula to an actual number, but that didn't seem to help.
----------------- UPDATE ---------------------
I just realized that evaluateFormulaCell is deprecated in favor of evaluateFormulaCellEnum. I put all of the code into a function and ran the function multiple times and realized it's evaluating all of the cells over and over again, so I switched to using evaluateInCell and found that it only evaluates each cell once, but still can't get pass the cells mentioned.
Here is my updated code, which I have inside a function that I run 5 times:
for (Sheet sheet : this.workbook) {
System.out.println("Evaluating next sheet" + sheet.getSheetName());
for (Row r : sheet) {
for (Cell c : r) {
if (c.getCellType() == Cell.CELL_TYPE_FORMULA) {
System.out.println("Cell index: " + r.getRowNum() + " - " + c.getColumnIndex());
try {
evaluator.evaluateInCell(c);
} catch (Exception e) {
try {
evaluator.evaluateFormulaCellEnum(c);
} catch (Exception ee) {
System.out.println("Skipping failed cell after 2 attempts");
}
}
}
}
}
With the debugging I have in place, I was able to see which cells in the spreadsheet were failing, so I saved the formulas from the failing cells in a text document and replaced the formulas with their values, then recompiled the code and the spreadsheet actually evaluated!
Then I went through all of the cells and put their formulas back two by two until it broke again. It turned out to be a case I already knew about, but searching a spreadsheet for is no piece of cake.
This was the formula with the issue: =ROUNDUP('HW page'!$H$53*'HW page'!$H$54,)
I added a 0 as the last parameter so it looks like this: =ROUNDUP('HW assumptions'!$H$53*'HW assumptions'!$H$54,0), then the evaluator works.
I am trying to use dnsjava in an android app to find hostnames of devices in my local wifi network.
Below is the code used:
try
{
String ipAddress = "33.1.168.192";
String dnsblDomain = "in-addr.arpa";
Record[] records;
Lookup lookup = new Lookup(ipAddress + "." + dnsblDomain, Type.PTR);
SimpleResolver resolver = new SimpleResolver();
resolver.setAddress(InetAddress.getByName("192.168.1.1"));
lookup.setResolver(resolver);
records = lookup.run();
if(lookup.getResult() == Lookup.SUCCESSFUL)
{
for (int i = 0; i < records.length; i++)
{
if(records[i] instanceof PTRRecord)
{
PTRRecord ptr = (PTRRecord) records[i];
System.out.println("DNS Record: " + records[0].rdataToString());
}
}
} else {
System.out.println("Failed lookup");
}
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}
The code was taken from the below link and it seems to work there for OP:
any way to discover Android devices on your network?
192.168.1.33 is an active device on my wifi network . 192.168.1.1 is the router IP . The code reaches "Failed lookup" everytime .
I am not sure where I am going wrong as I am new to dnsJava and Networks.
An additional question is , will this yield perfect result when scanned over all 254 ip's ? I am thinking of using this code in prod and need to be sure of that .
Any help is very much appreciated.
PTR records for reverse names are not stored in the order you're thinking. In general terms for IP A.B.C.D you need to resolve D.C.B.A.in-addr.arpa, so you'll need to reverse the order of the IP components.
I am making database of my school's building and classroom with Realm. But, 'for-loop' in try-catch doesn't work:
public void startCheckRealm() {
// Writing DataBase with Realm
try {
Log.d("Realm", "Init");
InitializeAPI.init_BuildingRoom(getActivity().getApplicationContext());
Log.d("Realm", "Complete");
} catch(Exception e) {
e.printStackTrace();
}
// Trying to check the Database whether it is right or wrong
try {
Log.d("Realm Test", "2nd Try Catch");
Realm.init(getActivity().getApplicationContext());
Realm realm = Realm.getDefaultInstance();
RealmResults<BuildingList> buildingLists = realm.where(BuildingList.class).findAllSorted("buildingCode");
int totalNumber = 0;
for(int i = 0; i < buildingLists.size(); i++) {
Log.d("For", "index = " + i);
RealmResults<RoomList> rooms = buildingLists.get(i).getRoomList().sort("roomCode");
String BuildingName = buildingLists.get(i).getBuildingName();
String BuildingCode = buildingLists.get(i).getBuildingCode();
for(int idx = 0; idx < rooms.size(); idx++) {
totalNumber++;
String RoomCode = rooms.get(idx).getRoomCode();
String RoomName = rooms.get(idx).getRoomName();
Log.d("Realm Test", "Number :: " + String.valueOf(totalNumber) + " BuildingCode :: " + BuildingCode + "\t\t BuildingName :: " + BuildingName + "\t\t RoomCode :: " + RoomCode + "\t\t RoomName :: " + RoomName);
}
}
Log.d("Realm Test", "2nd Try Catch Complete + " + String.valueOf(totalNumber));
} catch(RealmException e) {
e.printStackTrace();
}
}
In the first try-catch, the method, which does making database, is complete without Exception. I was curious whether this database is right or wrong.
So, in 2nd try-catch, I was trying to check realm files with queries.
The problem is "for-loop" doesn't work in 2nd try-catch. Below snippet is my logcat.
D/Realm: Init
I/System.out: bdList getLength :: 52
I/System.out: roomList getLength :: 2376
D/Realm: Complete
D/Realm Test: 2nd Try Catch
D/Realm Test: 2nd Try Catch Complete + 0
I want to check my realm data with Log but, doesn't work as you can see.
If there is no problem, the logcat shows lots of my building and room lists and ends with "D/Realm Test: 2nd Try Catch Complete + 2376".
Could you explain the reason why it doesn't work? I cannot understand the reason why it doesn't work even though there is no Exception.
While in your use-case this doesn't pose a problem, when you're iterating a RealmResults inside a transaction, the results are live in every version <= 0.88.3 and >= 3.0.0.
So in that case,
RealmResults<BuildingList> buildingLists = realm.where(BuildingList.class).findAllSorted("buildingCode");
for(int i = 0; i < buildingLists.size(); i++) {
BuildingList buildingList = buildingLists.get(i); // <-- !!!
will fail (it will skip every second item!)
So you should use iterators instead (3.0.0+! on <= 0.88.3 you'd do reverse iteration)
RealmResults<BuildingList> buildingLists = realm.where(BuildingList.class).findAllSorted("buildingCode");
for(BuildingList buildingList : buildingLists) { // <-- !!!
The reason why this works is because iterators by default create a new snapshot collection (3.0.0+), and iterating by index on a snapshot also works
OrderedRealmCollection<BuildingList> snapshot = buildingLists.createSnapshot();
for(int i = 0; i < ...
Simple: there is no exception thrown; and you only have your print statements inside the loop.
Thus the one and only conclusion: at that point in time when your for loops are executed, the corresponding list is empty. Therefore the loop body is not entered; nothing gets printed. And that has nothing to do with the fact that this loop is within a try-catch block.
That is all there is to this. So, the direct answer is: print the list size directly in front of the loop to avoid such surprises.
(of course, the interesting part is to understand what happens to the list which seems to be non-empty earlier on - but in order to debug that, you would have to add more of your code).
Two inputs:
1.Haven't used realm but looks like the syntax for getting sorted entriesis a bit different Official documentation
2.If the above point is wrong than from your code it looks like buildingList size is zero. Have you tried checking the size?
Let me know the results.
Try logging your catch block. Chances are the rest of the code including the loop didn't complete because your app was caught with the Exception.
You should debug buildingLists.size(); before for loop
Log.d("Building List Size ", buildingLists.size()+"");
In that case you can find the value of buildingLists.size();
Greetings and salutations fellow coders,
I'm trying to parse a MIDI sequence and get note durations from it. When I get a note on command I do a look ahead to find either a note off command for the same key or a note on command with a velocity of 0. Here is the code block in question(probably not needed).
for (Track track : sequence.getTracks())
{
for (int i = 0; i < track.size(); i++)
{
MidiEvent event = track.get(i);
MidiMessage message = event.getMessage();
if (message instanceof ShortMessage)
{
ShortMessage sm = (ShortMessage) message;
long timeStamp = event.getTick();
String temp = "0x" + Integer.toHexString(sm.getCommand());
if (temp.contains(Definitions.NOTE_ON))
{
// look ahead for note off and find duration
for (int j = i; j < track.size(); j++)
{
MidiEvent event2 = track.get(j);
MidiMessage message2 = event2.getMessage();
if (message2 instanceof ShortMessage)
{
ShortMessage sm2 = (ShortMessage) message2;
long timeStamp2 = event2.getTick();
temp = "0x" + Integer.toHexString(sm2.getCommand());
if (temp.contains(Definitions.NOTE_OFF) && sm2.getData1() == sm.getData1())
{
song.addNote(trackNumber, sm.getData1(), timeStamp, timeStamp2 - timeStamp, sm.getData2());
break;
}
//another valid way of turning a note off is playing a note on with a velocity of 0
else if (temp.contains(Definitions.NOTE_ON) && sm2.getData1() == sm.getData1() && sm2.getData2() == 0)
{
song.addNote(trackNumber, sm.getData1(), timeStamp, timeStamp2 - timeStamp, sm.getData2());
break;
}
}
}
}
}
}
}
Definitions.NOTE_ON = "0x9"
Definitions.NOTE_OFF = "0x8"
The code is a little messy and definitely not optimized, but it shouldn't entirely be necessary for people with great expertise in midi. I should note that most MIDI files I read use note off for the corresponding note on. So most the songs I read are read successfully there are just a few that don't use note off and my application is not adding the notes.
My question is this:
What other ways than note off or note on with a velocity of 0 determines when a note stops playing?
These are the ways I know to stop a MIDI note:
Call "Note Off" (0x80)
Call "Note On" (0x90) with velocity of 0
Call "All Notes Off" (0x58)
Also, a second Note On event for a given channel and note can be received without having received a Note Off. In this case, I believe the original Note On should be considered finished.