我已經看到了這個question,這不是我的情況,因爲我沒有反斜槓在我的網址,
我有簡單的URL一樣,https://url.com/login
java.net.MalformedURLException android的asp.net的Web API
我代碼,
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class LoginActivity extends AppCompatActivity {
URL url = new URL("https://url.net/login/");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
FloatingActionButton btn = (FloatingActionButton) findViewById(R.id.submitbtn);
EditText edtxt = (EditText) findViewById(R.id.usernm);
EditText edtxt2 = (EditText) findViewById(R.id.usrpwd);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),HomeActivity.class);
startActivity(i);
}
});
HttpURLConnection urlConnection = null;
try {
urlConnection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
} finally {
urlConnection.disconnect();
}
}
}
截屏:
當我徘徊在new URL();
,我得到錯誤爲:
Unhandled Exception: java.net.MalformedURLException
這就是爲什麼我得到的線另一個錯誤,
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
在堆棧跟蹤我得到錯誤如,
Error:(48, 13) error: cannot find symbol method readStream(InputStream)
請將源代碼作爲文本發佈,而不是圖片。 – CommonsWare
圖像是錯誤的,這是錯誤的行,我得到錯誤爲'錯誤:(48,13)錯誤:找不到符號方法readStream(InputStream)' –