이 코드를 실행하면 Input stream in =url.openstream
에 오류가 발생합니다. 도와주세요. 이url.openstream 사용 방법
내가 추가 한 인터넷 및 쓰기를 해결하고 매니페스트
에 허가를 읽고 난 createmethod 에 내가 doInbackground
에서 url.openstream
하지만 여전히 오류
asyncktask 클래스가 없으면 Java 프로그램에서 실행했습니다. 그러나 안드로이드에서 당신은 UI 스레드에서 실행되는, onPostExecute()
에 url.openStream()
를 실행하는
private class Mine extends AsyncTask<Void,Void,Void>
{
@Override
protected void onPreExecute() {
Toast.makeText(getApplicationContext(),"its loading",Toast.LENGTH_LONG).show();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
try {
Document doc=Jsoup.connect(addr).get();
come=doc.title();
Elements image=doc.getElementsByTag("img");
for(Element thereimage:image)
{
thereimagelink=thereimage.attr("abs:src");
}
int indexname = thereimagelink.lastIndexOf("/");
if(indexname==thereimagelink.length())
{
thereimagelink=thereimagelink.substring(1,indexname);
}
indexname = thereimagelink.lastIndexOf("/");
hereimagename=thereimagelink.substring(indexname,thereimagelink.length());
} catch (IOException e) {
e.printStackTrace();
}
//Toast.makeText(getApplicationContext(),""+come,Toast.LENGTH_SHORT).show();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
try {
URL url=new URL(thereimagelink);
InputStream in=url.openStream();
OutputStream out=new BufferedOutputStream(new FileOutputStream(folder+hereimagename));
for (int b; (b = in.read()) != -1;) {
out.write(b);
}
out.close();
in.close();
}catch (IOException e)
{
}
Toast.makeText(getApplicationContext(),"its finishd",Toast.LENGTH_LONG).show();
super.onPostExecute(aVoid);
}
오류 세부 정보를 추가 할 수 있습니까? – ghosh