Trouble in getting the meaning of the name in android - android

I am new with android development.I am creating an app that will tell the meaning of name entered by user, for this I am using www.babynamesworld.parentsconnect.com to fetch the data and parse the meaning of name out of it.Here is the code but it doesn't seem to work.
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new Button.OnClickListener()
{
TextView tv=(TextView)findViewById(R.id.textView1);
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
EditText et=(EditText)findViewById(R.id.editText1);
Document document = Jsoup.connect("http://babynamesworld.parentsconnect.com/meaning_of_"+et.getText().toString()+".html").get();
Element firstMeta = document.select("meta").first();
String title = firstMeta.attr("DESCRIPTION");
tv.setText(title);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
}
As soon I click on the button, program crashes. I've added internet access permission too.

It looks like the Virtual Machine can't find the Jsoup class definitions. Have you included either the source files or a jar in your project?
If you've already added the jar try cleaning the project.

Related

Windows Azure Service Client

I'm trying the my Azure Mobile Service. Below is the code to make a new ToDo item entry. The sample Android code shows how to create a mobile client. I added it to the onCreate method as mentioned in the example.
But the insert always fails. I always get an exception which says com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request.
mClient does get initialized. But, mClient.mCurrentUser is null. Not sure if this is a problem.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
mClient = new MobileServiceClient("https://myservice.azure-mobile.net/",
"slkerjasfi234eSomePrivateKey", this);
Item item = new Item();
item.setText("Awesome item");
item.setComplete(false);
mClient.getTable(Item.class).insert(item,
new TableOperationCallback<Item>() {
public void onCompleted(Item entity,
Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
ShowMessage("Success");
} else {
ShowMessage("Failed");
}
}
});
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
In my case, it looked like the key (parameter 2 in MobileServiceClient constructor) was incorrect. That is how I had downloaded it though. It happened again today and I manually fixed the key and it worked for another service. Believe it was the same issue here. To view your key, you go to your service in Azure and click Manage Keys at the bottom.

Open Epub from uri ActivityNotFoundException Error Android

Im open a epub file when I press a button, but when my android donĀ“t have any epub reader, show an toast saying please install epub reader, but my code not works, and stopp my app saying the app stop unexpectedly.
Button leer = (Button) findViewById(R.id.Btnleer);
leer.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v2) {
// TODO Auto-generated method stub
File file = new File("/sdcard/Mi Biblioteca/"+nomb+".epub");
Intent intentreadf = new Intent(Intent.ACTION_VIEW);
intentreadf.setDataAndType(Uri.fromFile(file),"application/epub+zip");
intentreadf.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intentreadf);
try {
startActivity(intentreadf);
}
catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(),
"favor descargar lector epub.",
Toast.LENGTH_SHORT).show();
}
}
});
Remove the first startActivity(intentreadf); command right after intentreadf.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);. It gets called before your try-catch block, and hence throws an exception.

display in textView basic operation result android

i have to show some operations in Android,,,
but Im having some noob problem,
public void calculateButtonPressed() {
// TODO Auto-generated method stub
Button button = (Button) findViewById(R.id.result);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Log.d("myTag", "result biatch");
String text=et.getText().toString();
//toast msg
//Toast msg = Toast.makeText(getBaseContext(),text, Toast.LENGTH_LONG);
// msg.show();
//set Text
tv.setText(text);
//result_tv.setText("copao");
int total = 1+2+3;
result_tv.setText(total);
}
});
}
so the app crashes , as im not using the variable correctly??
If I print the result_tv.setText("copao"); it works fine
but on my basic operation the app crashes,
int total = 1+2+3;
result_tv.setText(total);
so what Im I missing?
thanks!
It is assuming your total value as a string resource Id which might not be available in the R class as a valid resource Id, causing the app to crash.
Change:
result_tv.setText(total);
To:
result_tv.setText(String.valueOf(total));
//OR
result_tv.setText(total + ""); //to parse it as string
use
result_tv.setText(total+""); or result_tv.setText(String.valueOf(total));

Facebook Android SSO weird Error

I made a previous post and I fixed the issue in that problem but I get something weirder now. So I'm following http://developers.facebook.com/docs/mobile/Android/build/#register and everything goes fine until I actually start my app. Instead of getting an app log in page, I get this:
http://imgur.com/DHpde
I have no clue why it won't go to the app log-in page like it does for everyone else. The only thing that perhaps might be different is that I had to remove the "#Override" notations for the Facebook.authorize method call.
#Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
See this surely you will solve your error
you need to install an extension, similar to the core Android SDK, but no, here is what you need to do:
1.) go to github.com/facebook/facebook-android-sdk
2.) download the facebook directory ONLY! The other directories are only examples.
3.) Put the files from the src (you can copy the drawables too, if you want to) in the package, you are currently working with
4.) You are good to go, you can use the facebook "SDK"
see also this example https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook download it , it is working example provided by facebook

logOut from Facebook in Android Phonegap

I have successfully setup the Facebook Plugin by Jos located (https://github.com/jos3000/phonegap-plugins/tree/master/Android/Facebook) - but I can't seem to figure out a way to log the user out. Sure I could tell them to delete the App access on the website then try to login again and click on "Not you?" but I would really rather have a JS Function that does it for me.
Can anyone help provide some guidance on how to do this? I've looked through the files and it looks like there is a way to do it in the facebook.java but I just need to hack something together to connect it to webview. I'm not capable of doing so :) can anyone please help?
This solution is to disable the single sign on feature in the Facebook plugin
in FaceBook.java file
replace DEFAULT_AUTH_ACTIVITY_CODE in the Authorize method [2 overloads] by FORCE_DIALOG_AUTH
in FacebookAuth.Java file
append this to execute method [in the switch case section]
else if (action.equals("performLogout")){
this.performLogout(first);}
//Add this method to FacebookAuth.java class
public void performLogout(final String appid) {
Log.d("PhoneGapLog", "LOGOUT");
final FacebookAuth fba = this;
Runnable runnable = new Runnable() {
public void run() {
fba.mFb = new Facebook(appid);
fba.mFb.setPlugin(fba);
try {
fba.mFb.logout((Activity) fba.ctx);
fba.success(new PluginResult(PluginResult.Status.OK, ""), fba.callback);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
};
this.ctx.runOnUiThread(runnable);
}
//in facebook.js file add the following section
Facebook.prototype.Logout = function(app_id,callback){
PhoneGap.exec(callback,null, "FacebookAuth", "performLogout", [app_id]); };
// in your page add the following code
function LogoutClick() //on logout click
{
appId = "123" ; //your app Id
window.plugins.facebook.Logout(appId,CompleteLogout);
}
function CompleteLogout() //call back function
{
//do some logic for callback
}
//Enjoy..!!

Categories

Resources