I had this code that worked well last Thursday (04/19/2012):
Connection conn = null;
Statement inst;
try {
System.out.println("Connected to the database");
Class.forName ("net.sourceforge.jtds.jdbc.Driver");
//217.126.108.151
conn = java.sql.DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/prueba;sa;sa1234");
inst = conn.createStatement();
System.out.println("Connected to the database");
inst.executeUpdate("INSERT INTO TIENDAS (NOMBRE) VALUES ('ZZZZZZZ') ");
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
But after the last update of the Android SDK stopped working.
Now I get this error:
java.lang.RuntimeException: No message resource found for message property prop.servertype
Does anyone know why?
Thanks in advance.
Clean your project and rebuild at again. Still if your getting the same problem
try the following way..
-> Instead of localhost in url use this ip : 10.0.2.2
I'm not sure, but since Android >=3.0, network connection have to run in seperate Thread or Task. But if this is the problem, you should get an other exception.
But give it a try :)
And don't forget to check the permissions in your Manifest.
Related
I tried to use
try {
new TwitterFactory(new ConfigurationBuilder()
.setOAuthConsumerKey(TWITTER_KEY)
.setOAuthConsumerSecret(TWITTER_SECRET)
.setOAuthAccessToken(TWITTER_TOKEN)
.setOAuthAccessTokenSecret(TWITTER_TOKEN_SECRET)
.build()).getInstance().updateStatus("HELLO WORLD!");
} catch (TwitterException e) {
e.printStackTrace();
}
But as soon as I run it, it gives me this error:
this might be a possible answer: In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api#twitter.com — all other applications will receive an HTTP 401 error. from here but his answer is not complete (does not have steps to follow)
How to fix this? Thanks!
i get a strange error message when i try to start an url connection.
here´s the log output:
E/admarvelservice( 2366): postString: &site_id=14488&partner_id=ef8a30b841b36346& timeout=5000&version=1.5&language=java&format=android&sdk_version=2.1.3&sdk_version_date=2011-08-08&device_model=Nexus+S&device_name=GRJ22&get_cached_ads=true&device_systemversion=2.3.5&resolution_width=480&max_image_width=480&resolution_height=800&max_image_height=800&device_os=Android&target_params=appv%3D%3ES%7C%7Cla%3D%3Ede%7C%7Cco%3D%3EAT%7C%7Cscreenorient%3D%3Ep%7C%7Cappvn%3D%3E3.4.0%252F%7C%7Cosv%3D%3E2.3.5
D/admarvelservice( 2366): Error: java.net.ConnectException: ads.admarvel.com/127.0.0.1:80 - Connection refused
anybody an idea whats the problem here?
thanks.
EDIT: how i connect:
URL myURL;
try {
myURL = new URL(_url);
m_ucon = myURL.openConnection();
m_ucon.setConnectTimeout(8000);
} catch (Exception e) {
e.printStackTrace();
}
funny thing is that the connection is working, but every second my logcat shouts the errormessage shown above.
I think this has nothing to do with your application.
The exception comes from an Advertising Service (admarvelservice).
You are using an adblocker app and you have Shazam installed. Just either get the paid version of Shazam, remove ad blocker or just ignore the error.
Check this first in your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Localhost ip address is: 127.0.0.1 so u can check by this too.
try with this http connection:
public SomeClass {
HTTTPUrlConnection conn = new HTTPUrlConnection(...);
SomeClass instance = new SomeClass();
private SomeClass() {}
public static getInstance() {
return instance;
}
}
you should try Singleton pattern for request response.
You must set uses permission in the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
For my experience
Connection Refused
is caused by :
a|- You don´t have access because probably you are under a Proxy and you need credentials to establish a connection.
b|- You need to add the persmission for connection inside your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
I'm trying to invoke a webservice and parse the returned XML, so my invoke URL is :
http://192.168.1.12/cr.ws/CarCategories.asmx/CarCategoryComparatorRQ?IdUser=1076&IdCurrency=1&IdLanguage=1&IdCarCategory=0&IdPickupRentCarAgencies=3&IdReturnRentCarAgencies=3&PickupDate=6/4/2011&ReturnDate=9/4/2011&Supplier=Prima%20Rent%20a%20Car&b=prima
in my browser I get the desired response :
<CarCategoryComparatorRS>
<CarCategory>
<IdCar>22</IdCar>
<IdCarCategory>22</IdCarCategory>
<Supplier>AvantGarde Rent a Car</Supplier>
<PickupRentCarAgencies>Tunis; Aéroport de Tunis-Carthage</PickupRentCarAgencies>
<IdPickupRentCarAgencies>5</IdPickupRentCarAgencies>
<ReturnRentCarAgencies>Tunis; Aéroport de Tunis-Carthage</ReturnRentCarAgencies>
<IdReturnRentCarAgencies>5</IdReturnRentCarAgencies>
<IdUser>705</IdUser>
<Title>Catégorie A [ex:Kia Rio;Renault Symbol]</Title>
<IdCurrency>1</IdCurrency>
<ImageUrl>Car-22-20090521-125545.jpg</ImageUrl>
<MemberReductionValue>0</MemberReductionValue>
<Rate>150</Rate>
<DelayRate>0</DelayRate>
<ReductionValue>135</ReductionValue>
<DayRate>45</DayRate>
<Reduction>10%</Reduction>
<AccompteValue>67.500</AccompteValue>
<Accompte>50</Accompte>
<TotalRate>0000135000</TotalRate>
</CarCategory>
</CarCategoryComparatorRS>
But this function trows java.io.FileNotFoundException
protected InputStream getInputStream() {
try {
return feedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
Please help me, I wasted couple hours searching but nothing :(
Thanks.
The error is caused by the spaces in this param :"Supplier=Prima Rent a Car", so i replaced this param by UrlEncoder.encode("Supplier=Prima Rent a Car") and it worked.
If you type that URL in your device's browser address bar do you get anything?
It looks like you are trying to request an address on a local machine or LAN. Are you requesting this on the android device? My guess is you need to run your server on the machine on a different interface or open up connections to the required port.
I think your url is being interpreted as a file url.
What about logging your url before you call openConnection as a sanity check:
Log.e("MyApp", feedUrl);
On second thought, could you post the logcat output? I'm skeptical as to how your code could ever throw a FileNotFoundException.
I have a wierd problem. I have the following code:
if (fbIntent.hasExtra("Link")) {
try{
postData[0]= fbIntent.getStringExtra("Link");
} catch (Exception e) {Log.d("fbIntent error",e.getMessage() );}
}
fbIntent.hasExtra("Link") is true. So the compiler goes into the if statement. But I am not able to get the string using fbIntent.getStringExtra("Link"). This I know from debugging in eclipse. When I run it, I get :
01-21 14:12:01.030: ERROR/AndroidRuntime(311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.Kikin/com.examples.Kikin.FacebookLogin}: java.lang.NullPointerException: println needs a message
Please help me.
You need to initialize postData. Try something like String[] postData = new String[1]. Obviously, if you want use postData[1], [2], and [3], you'd need to say new String[4].
1) Your current issue is in
Log.d("fbIntent error", e.getMessage());
e.getMessage() may return null, so you get the java.lang.NullPointerException: println needs a message. Use e.toString() instead. Or the best way would be:
Log.e("some tag", "some comment", e);
2) When you fix this, you will be able to see the actual error to go further in fixing your root/real issue. So feel free to update your post with new log data.
I am new to both Android and Java so I beg your pardon if my question
is asked at the inappropriate group or forum. I made a .Net
application for my company and recently they asked me to port it on
Android so as to install it on Samsung Galaxy Tabs.
First of all, I am using Eclipse, JDK 6, target platform android 2.2
and an Emulator with the GalaxyTab plugin. My operating system is Windows 7.
This application, sends and receives messages to and from a certain
controller on the network using UDP.
In short my application uses a "DatagramSocket", binds it to a local
"InetSocketAddress" and then launches a thread that listens for
datagrams, while another thread sends requests to the controller upon
the user's request. Here is a some code snippet:
This is where I assign the local address and the socket:
try {
loc_addr = new InetSocketAddress(
Inet4Address.getByAddress(
new byte[]{(byte) 192,(byte) 168,1,(byte)240}), 0xBAC0);
//192.168.1.240 is the IP of my machine on the network
} catch (UnknownHostException e) {
.......
}
try {
soc = new DatagramSocket();
soc.setReuseAddress(true);
soc.setBroadcast(true);
soc.bind(loc_addr);
} catch (SocketException e) {
.......
}
This is where I listen for incoming datagrams:
try{
buf = new byte[1024];
receive_pac = new DatagramPacket(buf, 1024);
soc.receive(receive_pac);
if (receive_pac.getData() != null){
.......
}
}
This is where I send data:
try {
addr = (Inet4Address) Inet4Address.getByAddress (new byte[]
{(byte) 192,(byte) 168,1,(byte) 255}); //The message I am sending should be broadcasted
} catch (UnknownHostException e) {
......
}
sendPacket = new DatagramPacket(buf, buf.length, addr,
loc_addr.getPort());
try {
soc.send(sendPacket);
} catch (IOException e) {
......
}
Well when I use "soc.bind(...)" I receive the following exception:
cannot assign requested address
Then I receive a debug message (I don't know if it is relevant):
DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
The application is working, I verified through "WireShark" that when I
ask from the emulator to send the data to the controller, the
controller replies back with the expected data correctly. However, the
socket, in the application, on the emulator doesn't receive anything and stays blocked on
the "Receive" call!
Can anyone help me figure out what problem or error I have committed with the receiving part of my application!
Any help is much appreciated,
TMI,
[Edited: If you saw my other answer, please disregard, I made the classic mistake of changing two variables in one test and it was the other variable that made the difference.]
In regards to this:
I tried binding it to the socket and it resulted with the "SocketException: Invalid Argument". Still the program delivered the same operation! Do you have any idea what this exception might mean?
You may have solved this by now, but I just had the same question and answered it myself here.
What got rid of this exception for me was to change the way I was creating the DatagramSocket.
From:
sock = new DatagramSocket();
To:
DatagramChannel channel = DatagramChannel.open();
DatagramSocket socket = channel.socket();
Usually you see that error message if you're trying to bind to an IP address that you don't own. Are you sure that the IP address of your Android emulator is 192.168.1.240? The emulator IP can be different from your host machine IP.