안드로이드 초보입니다. 이유를 모르겟습니다...
위와 같은 에러가 떨어지는데 이유를 모르겠네요...저 에러 어디를 건드렸을때 나는 에러인가요...?
소스는 xml 파싱하는거 연습한다고 하는데 그런류의 에러가 아니라 어디 설정문제인거 같은데...
일단 소스 올려 보겠습니다. 선배님들 부탁좀 드립니다. 속터지네요 이런 에러가 계속 뜨니깐..
package com.example.administrator.example1;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView status = (TextView)findViewById(R.id.status);
TextView status1 = (TextView)findViewById(R.id.status1); //파싱된 결과를 보자
TextView status2 = (TextView)findViewById(R.id.status2);
boolean inItem = false, inTitle = false, inAddress = false, inMapx = false, inMapy = false;
String title = null, address = null, mapx = null, mapy = null;
String query = "%EA%B0%88%EB%B9%84%EC%A7%91";
System.out.println(query);
try{
URL url = new URL("http://openapi.naver.com/search?" +
"key=c1b406b32dbbbbeee5f2a36ddc14067f&query="+query+"" +
"&target=local&start=1&display=4");
XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = parserFactory.newPullParser();
parser.setInput(url.openStream(), null);
status.setText("파싱 중이에요..");
int parseEvent = parser.getEventType();
while(parseEvent != XmlPullParser.END_DOCUMENT){
switch (parseEvent){
case XmlPullParser.START_TAG :
if(parser.getName().equals("item")){
inItem = true;
}
if(parser.getName().equals("title")){
inTitle = true;
}
if(parser.getName().equals("address")){
inAddress = true;
}
if(parser.getName().equals("mapx")){
inMapx = true;
}
if(parser.getName().equals("mapy")){
inMapy = true;
}
if(parser.getName().equals("message")){
status1.setText(status1.getText()+"에러");
}
break;
case XmlPullParser.TEXT :
if(inTitle){ //isTitle이 true일 때 태그의 내용을 저장.
title = parser.getText();
inTitle = false;
}
if(inAddress){ //isAddress이 true일 때 태그의 내용을 저장.
address = parser.getText();
inAddress = false;
}
if(inMapx){ //isMapx이 true일 때 태그의 내용을 저장.
mapx = parser.getText();
inMapx = false;
}
if(inMapy){ //isMapy이 true일 때 태그의 내용을 저장.
mapy = parser.getText();
inMapy = false;
}
break;
case XmlPullParser.END_TAG:
if(parser.getName().equals("item")){
status1.setText(status1.getText()+"상호 : "+ title +"\n주소 : "+ address +"\n좌표 : " + mapx + ", " + mapy+"\n\n");
inItem = false;
}
break;
}
parseEvent = parser.next();
}
status2.setText("파싱 끝!");
}catch (Exception e){
status1.setText("에러가..났습니다...");
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.administrator.example1" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/status1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/status2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>