java


How to solve this error in Android? java.net.MalformedURLException: Protocol not found: [duplicate]


This question already has an answer here:
“java.net.MalformedURLException: Protocol not found” read to html file
2 answers
I dont know what is exactly problem, But I am getting error like:
Even I also checking all paths, and it is correct but still it will get error.
java.net.MalformedURLException: Protocol not found: www.w3schools.com/webservices/tempconvert.asmx
My Code:
package com.example.mytest;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
#SuppressWarnings("deprecation")
public class MainActivity extends Activity {
private final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private final String METHOD_NAME = "CelsiusToFahrenheit";
public final String NAMESPACE = "http://tempuri.org";
public String URL = "www.w3schools.com/webservices/tempconvert.asmx";
TextView tv;
public static String TAG = "MyTest";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "MainActivity Started");
tv = (TextView) findViewById(R.id.txt1);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("Celsius", "32");
// URL=URL.replaceAll(" ", "%20");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
Log.d(TAG, "URL:"+URL);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
try {
// HttpTransportSE aht = new HttpTransportSE(URL);
Log.d(TAG, "aht:" + aht);
aht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive) soapEnvelope
.getResponse();
// Object resultString = (Object)soapEnvelope.getResponse();
Log.d(TAG, "result String=" + resultString);
tv.setText("Status: " + resultString);
} catch (Exception e) {
Log.d(TAG, "Error: ", e);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I dont know what is exact problem but I am getting error like:
02-01 21:07:01.264: D/MyTest(1068): MainActivity Started
02-01 21:07:01.534: D/MyTest(1068): Error:
02-01 21:07:01.534: D/MyTest(1068): java.net.MalformedURLException: Protocol not found: www.w3schools.com/webservices/tempconvert.asmx
02-01 21:07:01.534: D/MyTest(1068): at java.net.URL.<init>(URL.java:275)
02-01 21:07:01.534: D/MyTest(1068): at java.net.URL.<init>(URL.java:159)
02-01 21:07:01.534: D/MyTest(1068): at org.ksoap2.transport.ServiceConnectionSE.<init>(ServiceConnectionSE.java:65)
02-01 21:07:01.534: D/MyTest(1068): at org.ksoap2.transport.ServiceConnectionSE.<init>(ServiceConnectionSE.java:61)
02-01 21:07:01.534: D/MyTest(1068): at org.ksoap2.transport.AndroidServiceConnection.<init>(AndroidServiceConnection.java:27)
02-01 21:07:01.534: D/MyTest(1068): at org.ksoap2.transport.AndroidHttpTransport.getServiceConnection(AndroidHttpTransport.java:35)
02-01 21:07:01.534: D/MyTest(1068): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:124)
02-01 21:07:01.534: D/MyTest(1068): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
Add http:// before the www... or https://.
public String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
you missed the protocol http://
public String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
NOTE:
If you just need to convert from Celsius to Fahrenhiet ot vice-versa you could try this:
function C2F ( C ) {
var F = eval ((C x 9 / 5) +32)
return ( F ); }
function F2C ( F ) {
var C = eval ( F - 32 ) * 5 / 9;
return ( C ); }

Related Links

How to update variables from another class's method
Fill a list with objects from existing list object with particular value
play2 Java EBean ORM: Inheritance and Generics
S3 Java- Multipart upload using a presigned URL?
Need to convert a large file to string in Java
java program to read text file and output with out dublicate? loop to skip dublicate line
Return the index of a 2D Array
Can anyone help me to understand how Spring 4 works in this example?
Generating a self-signed X.509 certificate in Android without Bouncy Castle, etc
Android - Scaling my UI to fit all screen sizes?
Send RSA public key over network from C to Java
GWT listbox not getting populated
Identify if the session is idle and flush in Decoder with Mina?
java throws impossible NullPointerException
Largest Row and Column Java regex
Sort ArrayList of objects based on (dynamically changing) key

Categories

HOME
vim
magnific-popup
iterator
iot
webstorm
framework7
at-command
paw-app
cakephp-2.5
binary-tree
alpha
yum
echarts
pheatmap
dacpac
u-sql
php-7.1
jplayer
foselasticabundle
finite-automata
interop
jqwidget
nas
extjs5
mustache.php
pass-by-reference
selectedindexchanged
wpfdatagrid
google-cloud-nl
gsmcomm
google-rich-snippets
directx-10
repo
openoffice.org
android-kernel
mozilla
android-ble
overlap
io-redirection
qwerty
sharefile
reportbuilder
sqlite2
impersonation
lumberjack
cookiecutter-django
elmah
keydown
wptoolkit
google-datalayer
apache-fop
errordocument
dotnetzip
tactic
snmptrapd
sonarlint-vs
libpng
slicknav
url-masking
merge-conflict-resolution
sigabrt
master-slave
sdf
php-parse-error
ruby-2.2
dukescript
responsive-images
operation
pretty-print
streambase
rake-task
gadt
asp.net-dynamic-data
valueconverter
datagridviewcolumn
algebraic-data-types
centos5
gil
broken-links
multipage
nsdatecomponents
cinema-4d
javax.script
digest-authentication
nhibernate.search
photoshop-cs4
noscript
geneva-server

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile