Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
System.out.println("There once was a person named " +Calvin+ " who lived in " +Baton Rouge+ ". At the age of " +23+ " , " +Calvin+ " went to college at " +Southern University+ ". " +Calvin+ " graduated and went to work as a " +Software Engineer+ ". Then, " +Calvin+ " adopted a(n)" +cat+ " named " +Alice+ ". They both live happily ever after!");
I'm having trouble getting it to run
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
Let's assume valid json is
{
"a": "valueA",
"b": "valueB"
}
Is there a neat way in java to validate the keys of json so that if the following is processed it fails with a message stating a particular key(in this case 'a1') is not a supported key/wrong key
{
"a1": "valueA", //wrong key a1 instead of a
"b": "valueB"
}
You have to map this json to any java class something like:
class Foo{
String a;
String b;
}
& then calling :
Foo foo=new ObjectMapper().readValue("{ \"a1\" : \"valueA\", \"b\" : \"valueB\"}",Foo.class);
will give you exception as
Unrecognized field "a1"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have used below php code to insert the data into table...but i need response 1 after successfully insert and 0 for failed insert...or any msg like 'your msg has been successfully inserted'..
<?php
$myname=$_GET["name"];
$mycity=$_GET["city"];
$myname=urlencode($myname);
$mycity=urlencode($mycity);
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
$sql="insert into tbl_sazal(name,city) values ('$myname','$mycity') ";
$result=mysql_query($sql);
if($result){
echo "1";
}
else{
echo "0";
}
?>
also for reference i m calling below url
http://localhost/testurl/test1.php?name=akash&city=ngong
Thanks....
You are not passing link identifier to mysql_query();
It returns error as string which in boolean except if the string is 0, it is true;
Change your code on line 10 to
$result = mysql_query($sql, $con);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to return values in the json format. I am using (MediaType.APPLICATION_JSON) for to return the values. How to return the ArrayList using this?
Example:
[
{
"node_title": "Ambivalence About Government Will Be Topic at next Lecture ",
"nid": "Topic - Get the Government Off of Our Backs – There Ought to Be a Law: Reconciling Our National Ambivalence About Government."
},
{
"node_title": "Recycling initiative gains steam under new director",
"nid": "University administrators listened and hired a sustainability coordinator whose main focus has been to heighten recycling efforts and awareness."
},
{
"node_title": "Special Week to Combat Hate and Discrimination",
"nid": "For the seventh year, University students will observe “Why Do You Hate Me?” Week, which will run from March 28th through April 2nd."
},
{
"node_title": "AUSP joins Nursing School on mission trip to Caribbean",
"nid": "The School of Audiology and Speech-Language Pathology during spring break went to Dominican Republic to provide much-needed assistance to a school for deaf and impoverished children."
}
]
Please guide me.
If you want to parse this into java code, you can do something like this:
First, get Gson, a google library to work with JSON.
Next, define a class like:
class Node {
String node_title;
String nid;
}
Then you can do
Type collectionType = new TypeToken<List<Node>>(){}.getType();
List<Node> details = gson.fromJson(myJsonString, collectionType);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I understand the Jsoup code to retrieve "Stock Name" and "Current Stock Price" from a Yahoo Finance page (e.g. http://finance.yahoo.com/q?s=goog):
String price = doc.select(".time_rtq_ticker").first().text();
String name = doc.select(".title h2").first().text();
But I am not sure how to select other data, for example the Open: or Volume: values.
This is what I have tried so far:
Elements open = doc.getElementsByTag("Open");
Elements volume = doc.getElementsByTag("Volume");
You could get all of the data from the table and then get the correct indexes as separate Elements:
Elements e = doc.select("td.yfnc_tabledata1");
Element open = e.get(1); // index for open is 1
Element volume = e.get(9); // index for volume is 9
System.out.println("Open: " + open.text());
System.out.println("Volume: " + volume.text());
Will output:
Open: 1,037.16
Volume: 1,613,009
You can't use getElementsByTag("Open") or getElementsByTag("Volume") because those tags don't exist.
I don't sure it return right result but data will contain in :
doc.select("span.time_rtq_ticker");
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Trying to compare and print only members with Inactive status. The problem is that it will not search the array and check the status of each element. If the first element has an "Active" status, it prints the error message and doesnt continue to check the other elements.
If the status of the first element is "Inactive" it will print but throws an exception before the output which looks like this:
Exception in thread "main" java.lang.NullPointerException at
GymAss.MemberTest.AllInactive(MemberTest.java:293) at
GymAss.MemberTest.main(MemberTest.java:58)
Account Number: 1 Name: 1 Date: 1 Status: INACTIVE Type: 1 Any
help would be greatly appreciated! Code below:
....
public static void AllInactive()
{
int check=0;
do
{
if ( accounts[check] instanceof Student && accounts[check].getStatus().equals("INACTIVE") )
{
System.out.printf("\nAccount Number: %d \nName: %s \nDate: %d \nStatus: %s \nType: %s \n" , accounts[check].getIdNumber(),accounts[check].getName(),accounts[check].getDateJoined(),accounts[check].getStatus(),accounts[check].getMemberType());
check++;
}
else if ( accounts[check] instanceof Adult && accounts[check].getStatus().equals("INACTIVE"))
{
System.out.printf("\nAccount Number: %d \nName: %s \nDate: %s \nStatus: %s \nType: %s \n" , accounts[check].getIdNumber(),accounts[check].getName(),accounts[check].getDateJoined(),accounts[check].getStatus(),accounts[check].getMemberType());
System.out.print("\n");
check++;
}
else
{
System.out.println("**Account Does Not Exist**");
}
} while ( accounts[check].getStatus().equals("INACTIVE"));
}
Just to make sure we are talking about the same thing: As far as I understood you have an Array containing accounts of persons. What you want to do is get all the accounts which currently are inactive and nothing else.
Why do you stop your loop if you find an active account? If you have an inactive account followed by an active followed by an inactive again, your loop will stop at the active one, because the condition of while(accounts[check].getStatus().equals("INACTIVE")) is false. You want to check the whole array so you have to loop through the whole array. This can be done with
for(int check=0; check<accounts.length; check++)
This checks every account and stops if you reach the end of the array. There is even an easier way. I recommend looking up "java foreach".
The cause of your NullPointerException propably is not checking if you reached the end of your array. Let's assume you have only one inactive Student account in your array and nothing else, your code will do this:
check = 0;
is accounts[0] a Student and is it inactive? - yes
print stuff
check = 1
skip else if
skip else
is accounts[1] active? wait, there's no accounts[1] -> NullPointerException
I don't want to give you the complete code because trial and error is a great way of learning so try to fix it with those hints. If you encounter any problems you still can't solve after a while of thinking, come back.