Nativescript android.net.Uri.parse - java

I am trying to enable file upload in a webview for android using nativescript.
The problem i am facing is when i am calling my file path callback function "onReceiveValue" where i am supposed to pass by a "android.net.Uri[]".
var mFilePathCallback: android.webkit.ValueCallback<android.net.Uri[]>;
This is how the array is made:
let results: android.net.Uri[] = [];
let dataString = data.getDataString();
results.push(android.net.Uri.parse(dataString));
And then the call:
mFilePathCallback.onReceiveValue(results);
The error i am getting:
Error: Cannot convert array to Ljava/lang/Object; at index 0
I am trying to make this implementation: https://github.com/OpenGeeksMe/Android-File-Chooser/blob/master/app/src/main/java/it/floryn90/webapp/MainActivity.java

Your code for generating an array should look like this:
let results = Array.create(android.net.Uri, 1);
let dataString = data.getDataString();
results[0] = android.net.Uri.parse(dataString);
Where the 1 in it is the number of elements the array is going to hold...

Related

org.json.JSONException: JSONObject["minutes"] not found

This is my JSON object and I am trying to access the minutes from this JSON object but unable to access it, I have also tried writing some code, can anyone please help.
{"summary":"B.Com; LL.B.(Hons.) 5-Year integrated-MIBCBT802R01","recurrence":["RRULE:FREQ=DAILY;COUNT=1"],"reminders":{"overrides":[{"method":"email","minutes":1440}],"useDefault":"false"},"attendees":["qatest1#dc01.tcs-itontap.com"],"start":{"dateTime":"2022-10-24T08:40:00+05:30","timeZone":"India+5:30"},"description":"Lecture scheduled for Subject:Down Stream Processing Lab II and Activity: Practical","location":"India","end":{"dateTime":"2022-10-24T09:30:00+05:30","timeZone":"India+5:30"},"id":2300036}
```String remMinutes = new org.json.JSONObject(new org.json.JSONObject(jsonFromSolJSON.getJSONObject("reminders")).getJSONArray("overrides").getJSONObject(0)).getInt("minutes")```
Err - JSONError:: org.json.JSONException: JSONObject["minutes"] not found.
This could be one of the solution
var jsonObject = new JSONObject(json);
var result = jsonObject.getJSONObject("reminders").getJSONArray("overrides");
var minutes = result.getJSONObject(0).get("minutes");

Extract data from returned string

I'm using Katalon Studio and using it to send an API request. The request is basically returning information I want to use in the HTTP Header. I can use Groovy or Java to extract this but not sure how I can do it.
I've tried create_game_response.getHeadewrFields(GameCode) in order to get the GameCode but it won't work.
Here is the code I use
WS.sendRequest(findTestObject('UserRestService/Create Game'))
WS.verifyResponseStatusCode(create_game_response, 201)
def header_text = create_game_response.getHeaderFields()
println(header_text)
def game_code = create_game_response.getHeaderFields();
String game_code_list = game_code.toString()
println(game_code_list)
And this is the response:
{GameCode=[1jwoz2qy0js], Transfer-Encoding=[chunked], null=[HTTP/1.1 201 Created]}
I'm trying to extract "1jwoz2qy0js" from the game code and use it as a string, how can I do this?
getHeaderFields() returns a Map of the headers where each header is a List. Rather than converting that to a String and attempting to parse it, just get the field you want:
Map headers = create_game_response.getHeaderFields()
List gameCodes = headers["GameCode"]
And then select the first one, if that's all there is:
assert gamesCodes[0] == "1jwoz2qy0js"
Groovy code below:
​
str = '{GameCode=[1jwoz2qy0js], Transfer-Encoding=[chunked], null=[HTTP/1.1 201 Created]}'​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
left_idx = str.indexOf('[') + 1
right_idx = str.indexOf(']')
print str.substring(left_idx,right_idx)
Output:
1jwoz2qy0js

Accessing data in an object array with Java

I'm currently working with Cucumber and Java. I would like to retrieve that path of a file from ITestResult.
I'm currently retrieving the parameters with:
Object[] test = testResult.getParameters();
However the only thing I can access would seem the be the first objects name and nothing else.
test = {Object[1]#1492}
0 = {CucumberFeatureWrapper#1493} "Links at EDM Documents View,"
cucumberFeature = {CucumberFeature#1516}
path = "test/01-automation.feature"
feature = {Feature#1518}
cucumberBackground = null
currentStepContainer = {CucumberScenario#1519}
cucumberTagStatements = {ArrayList#1520} size = 1
i18n = {I18n#1521}
currentScenarioOutline = null
I cannot see anyway of retrieving path = "test/01-automation.feature" under cucumber feature.
Have you tried something like ((CucumberFeatureWrapper)test[0]).getCucumberFeature().getPath()?

Dealing with multiple JSON objects (Android Java)

I am currently dealing with some JSON and apparently running into a bit of trouble. I have a PHP page that fetches two unrelated MySQL requests at the same time and displays both of them, one after the other. I have two JSON encodings. My issue is, I can't get my Java program to recognize the second one. First one is parsed fine.
I ran the JSON through an online validator and it is quite clear those two shouldn't follow as they are now. What is the correct way of dealing with those two ?
Please note that the comma between them (line 11) was added manually because I thought it would help. It didn't.
{
"player_update":[
{
"id":"16",
"name":"Phil_TEST",
"last_login":"2015-10-12 00:36:05",
"for_update":"00:00:00",
"newplayer":"no"
}
]
},
{
"player_list":[
{
"id":"16",
"name":"Phil_TEST",
"last_login":"2015-10-12 01:00:42"
},
{
"id":"15",
"name":"Phil8",
"last_login":"2015-10-12 00:50:49"
}
]
}
Edit : here's the code I'm using. I can parse the player_update fine, but nothing is done after I ask to find the the player_list, my Logs stop there. Test 00 AND Test 1 both don't display.
JSONObject obj = new JSONObject(stream);
JSONArray arr_player_update = obj.getJSONArray("player_update");
String newplayer = arr_player_update.getJSONObject(0).getString("newplayer");
Log.i("PhLog LobbyActivity", "Newplayer : "+newplayer);
Log.i("PhLog LobbyActivity", "Test 0");
JSONArray arr_player_list = obj.getJSONArray("player_list");
Log.i("PhLog LobbyActivity", "Test 00");
for (int i = 0; i < arr_player_list.length(); i++) {
String id = arr_player_list.getJSONObject(i).getString("id");
String name = arr_player_list.getJSONObject(i).getString("name");
String last_login = arr_player_list.getJSONObject(i).getString("last_login");
}
My PHP pages consists of : json_encode($array1);echo",";json_encode($array2);
But the comma is useless. Maybe if my JSON was valid then it would work better.
Logcat :
10-12 09:48:00.086 1052-1052/? I/PhLog LobbyActivity: Newplayer : no
10-12 09:48:00.086 1052-1052/? I/PhLog LobbyActivity: Test 0
10-12 09:48:00.086 1052-1052/? W/System.err: org.json.JSONException: No value for player_list
Problem:
The way you are encoding JSON is wrong. That was not an example of valid JSON formatted data. You can check it's validness here.
Solution :
You have two different arrays to send as response. Then combine both of them in single array first and then encode it in json format.
Example: (in your php file)
$data_to_send=array();
$data_to_send['player_update']=$player_update; // an array of player update
$data_to_send['player_list']=$player_list; // an array of player_list
json_encode($data_to_send); // to send the response

Uncaught TypeError: Cannot read property 'length' of undefined while accessing arraylist through Json Object

I am returning an array list from my struts2 action class.
When I an trying to access that Array list in my JavaScript file through JSON,
I am getting
"Uncaught TypeError: Cannot read property 'length' of undefined".
in below line json.EmpListByOffsetAndLength
See my code below. I want to display data that is in arraylist into the table in my jsp page.
alert(url);
$.ajax({
type : "POST",
cache : false,
url : url,
success : function(json) {
var table = document.getElementById("tablereload");
var rowCount = document.getElementById("tablereload").rows.length;
alert("this is row count" +rowCount);
$("#test").html('');
$.each(json.EmpListByOffsetAndLength, function(index, value) {
var row = table.insertRow(rowCount);
var i = 0;
for ( var key in value) {
var val = value[key];
alert(val);
var cell = row.insertCell(i);
var div = document.createElement('div'), // create
// DIV
// element
txt = document.createTextNode(val); // create
// text
// node
div.appendChild(txt);
cell.appendChild(div);
i++;
}
});
}
})
I think you didn't mention the dataType in ajax ...
$.ajax({
url:"",
type:"post",
dataType:"json",
success:function(outputdata){ //do somethins
console.log(outputdata);
}
});
Can you check if your selector is working properly? I suspect this line does not return a valid object:
var table = document.getElementById("tablereload");
Try this? You'll need to make sure you use the tbody tag in your table.
var rowCount = document.getElementById('tablereload').getElementsByTagName('tbody')[0].getElementsByTagName('tr').length;
Found here: Counting the number of rows in a table NOT using jquery
thanks for your help.
Issue is resolved. I actually , my arraylist in Java is EmpListByOffsetAndLength , but in console it is coming up as json object with e mpListByOffsetAndLength i.e. with small 'e' . thats why, when we are running length function over it, it was displaying cnnot read length function for underfined object.

Categories

Resources