I am trying to integrate twitter api using library twitter4j-core-2.1.1-SNAPSHOT.jar. But i am getting error Unknown host Exception from 2 days. here is the part of code(index by .....(1)) that is generating Exception.
public String beginAuthorization() {
//showDialog("Authorization...........");
//new AuthorizationTask(this).execute("Authorize");
try {
if (null == currentRequestToken) {
Log.e("begin","i am here the line below is throwing excetion");
currentRequestToken = twitter.getOAuthRequestToken();............(1)
}
Log.e("beginAuthorization", currentRequestToken.getAuthorizationURL());
return currentRequestToken.getAuthorizationURL();
} catch (TwitterException e) {
e.printStackTrace();
}
return null;
}
anyone have idea about this problem???
thank u in advance
Did you put permission in xml manifest?
Have you tried opening a browser in android and going to twitter.com?
Try to connect to any url from the code and see what happens.
This is what I'd forgotten to include in my AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
Related
I'm trying to connect my Android application to my company local network (Windows) using smb protocol. The problem is I'm kinda newbie on this matter and something is missing me.
The goal is download the file AREQA.txt from the network to the device. However I don't even can verify if the code can trace the file location because the application crashes when I compile it to the device (it loads fine but crashes when I call the DownLoadF001 procedure). Here's the code:
public void DownLoadF001(View v) {
jcifs.Config.registerSmbURLHandler();
String user;
String password;
String filename;
File localFile;
SmbFile path = null;
try {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,"######", "********");
path = new SmbFile("smb:\\192.168.1.11/.../AREQA.txt", auth);
try {
if(path.exists()){
Toast.makeText(getApplicationContext(), "Sucesso!", Toast.LENGTH_LONG).show();
}
} catch (Exception e1) {
Toast.makeText(getApplicationContext(), e1.toString(), Toast.LENGTH_LONG).show();
}
} catch (MalformedURLException e2) {
Toast.makeText(getApplicationContext(), e2.toString(), Toast.LENGTH_LONG).show();
}
}
I already tried to remove the inside try from the main one (with all its associated code), and the application stops crashing. However, without it, I can't see if the connection is working.
EDIT: I managed to catch the error (Exception e1):
java.lang.NullPointerException: Attempt to invoke virtual method int java.lang.String.length()' on a null object reference. Any ideas to solve it?
Also, as pointed by #greenapps, I'm calling this procedure from a .xml button by onClick method.
I am using the following code to delete a particular number from the call log, but it is not working on Android Marshmallow:
String queryString = "NUMBER=" + number;
try {
context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, queryString, null);
} catch (Exception e) {
e.printStackTrace();
}
How can I delete the call log on Android Marshmallow?
On Marshmallow you will need to request the permissions from user to read and write from call log
See official doc link below on how to request permissions
http://developer.android.com/training/permissions/requesting.html
I've sucessfully compiled jNetPcap as a shared library for Android. I have made a simple application using this code: http://jnetpcap.com/examples/classic to test the API.
The problem is that when I call the method findAllDevs and exception is raised with this message: "Can't read list of devices, error issocket: Permission denied"
I cannot understand the reason, since I have made a call in the first part of my program so as to get root permissions for my application and I test my application to a rooted phone. When I run the application, a pop up is raised with this message:"SnifferApp has been granted Superuser permissions" and then the exception occurs.
Any ideas?
Here is a piece of my code:
Process p = Runtime.getRuntime().exec("su");
/*try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // do nothing for 1000 miliseconds (1 second)
*/
try {
System.loadLibrary(JNETPCAP_LIBRARY_NAME);
}
catch (UnsatisfiedLinkError e) {
System.out.println("Native code library failed to load.\n" + e);
}
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
tv.append("Can't read list of devices, error is" + errbuf
.toString());
setContentView(tv);
return;
}
As far as I understand, you're creating a new process and getting superuser permission, but your app doesn't have them.
Try adding this permission in your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
as I guess findAllDevs is going to open the network devices on the phone.
Why might this code throws exception? I don't have any idea. I entered the consumer key correctly and that's the only reason I can think that can cause this exception. (currentRequestToken is RequestToken)
public String beginAuthorization() {
try {
if(null == currentRequestToken) {
currentRequestToken = twitter.getOAuthRequestToken();
}
return currentRequestToken.getAuthorizationURL();
} catch (TwitterException e) {
e.printStackTrace();
}
return null;
}
I had the same problem, in my case the solution was in my twitter account --> for developers --> My applications --> Settings --> Application type I changed to: Read, Write and Access direct messages.
I've got it wrapped in a try catch, but the exception still trips that ugly screen.
URL u = null;
try {
u = new URL(txturl.getText().toString());
}
catch (MalformedURLException e) {
ReportError(e,"Unable to connect to "+u);
}
calls this:
private void ReportError(Exception e, String message){
Display(message+" - "+ e.getMessage().toString());
System.out.println(">>>>>>>>>>>>>>>>>>>>> "+message+" - "+e.getMessage().toString());printStackTrace();
}
Any way around this. It happens on the Android 2.2 emulator with Eclipse and on my Sprint Hero.
Do I have to validate the form?
Thanks.
I just needed to return after these exceptions. duh. sorry.