멍멍이네 블로그


  
        File newxmlfile = new File(Environment.getExternalStorageDirectory()+"/new.xml");
        try{
                newxmlfile.createNewFile();
        }catch(IOException e){
                Log.e("IOException", "exception in createNewFile() method");
        }
        //we have to bind the new file with a FileOutputStream
        FileOutputStream fileos = null;       
        try{
                fileos = new FileOutputStream(newxmlfile);
        }catch(FileNotFoundException e){
                Log.e("FileNotFoundException", "can't create FileOutputStream");
        }
        //we create a XmlSerializer in order to write xml data
        XmlSerializer serializer = Xml.newSerializer();
        try {
                //we set the FileOutputStream as output for the serializer, using UTF-8 encoding
                        serializer.setOutput(fileos, "UTF-8");
                        //Write <?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null)
                        serializer.startDocument(null, Boolean.valueOf(true));
                        //set indentation option
                        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
                        //start a tag called "root"
                        serializer.startTag(null, "root");
                        //i indent code just to have a view similar to xml-tree
                                serializer.startTag(null, "child1");
                                serializer.endTag(null, "child1");
                              
                                serializer.startTag(null, "child2");
                                //set an attribute called "attribute" with a "value" for
                                serializer.attribute(null, "attribute", "value");
                                serializer.endTag(null, "child2");
                      
                                serializer.startTag(null, "child3");
                                //write some text inside
                                serializer.text("some text inside child3");
                                serializer.endTag(null, "child3");
                              
                        serializer.endTag(null, "root");
                        serializer.endDocument();
                        //write xml data into the FileOutputStream
                        serializer.flush();
                        //finally we close the file stream
                        fileos.close();
                      
                } catch (Exception e) {
                        Log.e("Exception","error occurred while creating xml file");
                }

 

 

출처 : http://www.shop-wiz.com/document/android/execise_linkage_web_xml_create

이클립스에서 자바언어로 비교문이 제대로 안됨.

 

원인 : 특히나 문자열 같은 경우 a == b로 잘 안됨

 

해결

String a = "check";

String b = "check";

 

if(a == b) // X

 

if(a.equals(b)) // O

 

아래꺼도 문자열 비교!

 

-------------- 추가 --------------

 

a.CompareToString인가.. 있길래 추가함

if(a.CompareToString(b) == 0) // a 와 b 가 같으면 0의 값이 출력되나봄.

 

지금 이클립스 안키고 있어요 .. ㅜㅜ 정확한건 컨트롤 + 스페이스바 눌러서 자동완성 뭐지 그거.. 어시스트 써서 보세요!

Android는 기본 탐색기가 사용되지 않는다. (확인불가. 100% 정확한건 아님.)

 

* 해결방법

 

1. 탐색기 프로그램을 사용한다.

 

2. 탐색기를 만들어 쓴다.

 

* 부가설명

한꺼번에 설명하자면,

탐색기를 사용한 어플들이 많이 있다.

핸드폰에서 sdcard의 폴더들을 탐색. 하위 폴더 및 파일들을 찾아서 리스트뷰로 뿌려주고, 선택 시 파일인지 폴더인지 확인해서 알맞게 사용함. ( 1번같은경우 자동으로 생략 가능함. 편리함. 다만 직접 탐색기를 설치해야된다는 점 등 불편한 점이 있을 수 있음. )

그걸 이용해서 파일 이름과 경로를 리턴해서 업로드에 사용함.

I/Choreographer(5855): Skipped 99 frames!  The application may be doing too much work on its main thread.

 

현재 에러 찾는중.
동영상 업로드 하는중인데, 메인UI에서 쓰레드를 사용하려 해서 스킵된듯..

에러 해결.

 

- 원인
동영상 업로드 시 메인 UI에서도 사용가능하도록
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
를 써줬는데도 프레임이 초과함.

 

- 해결
그냥 다른곳에서 쓰레드 사용. (어신크테스크 씀)

android.os.NetworkOnMainThreadException 이 에러가 발생했다.

주로 메인UI에서 쓰레드를 쓰려고 할 경우 뜨는 에러.

해결방법
1. 메인UI 외 다른 부분에서 쓰레드 만들어서 사용.
2. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); 사용!

 

2번예시
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.layout_name);
  
  StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  StrictMode.setThreadPolicy(policy);

}

 

출처 : http://seemoon.tistory.com/288