Android 안드로이드2014. 12. 5. 00:05


최신 버전 구글 맵은 프로그래먼트를 사용해서 표시된다. 구글맵 프래그먼트를 붙여놓은 초기 상태에서 에러없이 실행된다. 레이아웃을 바꾸고자 layout폴더에서 activity_mainmapmap.xml를 수정했다. 


뷰 위치를 조금 변경했다. 

오류가 틔어나왔다.


되돌리기해서 내부 중첩 LinearLayout의 위치를 바꿨다.

역시 오류가 나왔다.


Button위치를 바꿨다.

오류


TextView

에러


.

.

.

.


이쪽에서는 잘 쓰는 단어가 있다.

무한반복.


감으로 fragment에 문제가 있을 것이라!


디버그를 돌렸더니

mcGoogleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_google)).getMap();

에서 mcGoogleMap가 null값을 받는다.


관련한 에러가 주르륵 뜨는데 googlemap fragment에 해당하는 부분만 복사해서 아래에 붙여놓았다.


12-05 16:48:21.070: E/AndroidRuntime(7241): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapmmap/com.example.mapmmap.GPSInfo}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.MapFragment.getMap()' on a null object reference




구글링(googling)을 해보면 많은 답변이 나온다. 보통 때와 같이 다 쓸데 없는 답변이다. 

http://stackoverflow.com/questions/13722192/google-maps-android-api-v2-throws-googleplayservicesnotavailableexception-out-o

https://code.google.com/p/android-developer-preview/issues/detail?id=1947

http://android-er.blogspot.in/2012/12/a-simple-example-using-google-maps.html

http://stackoverflow.com/questions/21569716/nullpointerexception-for-googlemap-object


구글서비스플레이(Google Play Services)가 설치되었나?

==> 당연설치되어있다. 이미 구글 지도는 잘 뜬다. 요소변경 다시 말해 레이아웃 변경이 안될 뿐이다. 그러니 xml 레이아웃(layout) 파일에서 각종 뷰 요소나 중첩레이아웃 요소를 


구글맵 api키 (Google Map API KEY )가 정상작동하나?
==> 두말하면 잔소리다. 이미 지도는 잘 나왔다. 디자인 변경이 안될 뿐이다.


mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

아래와 같이 사용해보라고 

FragmentManager myFM = getActivity().getSupportFragmentManager();
final SupportMapFragment myMAPF = (SupportMapFragment) myFM
                .findFragmentById(R.id.map);
==> 아직 프로요나 진저 등 하위 버전까지 지원하기에는 벅차다. 이제 시작이다.


지금 어제부터 정답을 찾아 헤매고 있는중이다. 더 정확히는 몇일 전에도 만졌다. 조금씩 뷰 구성 요소를 이동시키고 단말기와 에물레이터로 에러있나 없나를 확인하면서 레이아웃을 얼쭈변경했다. 이렇게 해서 앞으로도 있을 무수한 같은 작업을 인내할 수는 없는 노릇이다. 그래서 지금 이러고 있다. 

내 생각에 답은 구글맵에 없다. 프래그먼트에 있다고 본다. 이 부분을 입맛에 맛게 제단하려면 fragment를 파고들어야한다. 아래 링크에 보면 나의 눈에만 띄는 구절을 누군가가 달아놓았다. 직접 해결책은 아닌데 이 길로 적어놨다. 나도 그렇게 생각한다. 
http://stackoverflow.com/questions/24947483/google-maps-apiv2-app-not-working-keeps-crashing


public final GoogleMap getMap ()

Gets the underlying GoogleMap that is tied to the view wrapped by this fragment.

Returns the GoogleMap. Null if the view of the fragment is not yet ready. This can happen if the fragment lifecyle have not gone through onCreateView(LayoutInflater, ViewGroup, Bundle) yet. This can also happen if Google Play services is not available. If Google Play services becomes available afterwards and the fragment have gone through onCreateView(LayoutInflater, ViewGroup, Bundle), calling this method again will initialize and return the GoogleMap.





http://developer.android.com/guide/components/fragments.html
http://developer.android.com/training/location/index.html




Posted by 코드버무려
자바 Java2014. 12. 5. 00:04






















public class JavaExam {

public static void main(String[] args) {

System.out.println("Start");

Thread threadA = new MyThread("Thread AAA");

threadA.start();


try {

Thread.sleep(1500);

} catch (InterruptedException e) {

e.printStackTrace();

}

threadA.interrupt();


System.out.println("------  끝  ------");

}

}


class MyThread extends Thread {

MyThread(String name) {

setName(name);

}


public void run() {


try {

Thread.sleep(10000);

}

catch (InterruptedException e) {

System.out.println("   " +getName() + "InterruptedException예외 발생");

}

System.out.println("   " +getName() +"   끝");

}

}


*************************************************


class JavaExam {

public static void main(String[] args) {

        System.out.println("------- 시작 -------");

        Thread threadA = new MyThread("Thread AAA");

        threadA.start();

        

        try {

Thread.sleep(1500);

} catch (InterruptedException e) {

e.printStackTrace();

}

        

        threadA.interrupt();

        try {

threadA.join();

} catch (InterruptedException e) {

e.printStackTrace();

}

        

        System.out.println("------  끝  ------");

   

   }


}


class MyThread extends Thread {

MyThread(String name) {

setName(name);

}

    public void run() {

        

        try {

            Thread.sleep(10000);

        }

        catch (InterruptedException e) {

            System.out.println("   " +getName() + "InterruptedException예외 발생");

        }

        

        try {

Thread.sleep(10); // main 스레드 출력 순서 테스트

} catch (InterruptedException e) {

e.printStackTrace();

}

        System.out.println("    " +getName() +"   끝");

    }

}


**************************************************


class JavaExam {

public static void main(String[] args) {

        System.out.println("------- 시작 -------");

        MyThread threadA = new MyThread("Thread AAA");

        

        threadA.setRunning(true);

        threadA.start();

        

        try {

Thread.sleep(1500);

} catch (InterruptedException e) {

e.printStackTrace();

}

        

        threadA.interrupt();

        try {

threadA.join();

} catch (InterruptedException e) {

e.printStackTrace();

}

        

boolean done = true;

threadA.setRunning(false);

while (done) {

try {

threadA.join();

done = false;

} catch (InterruptedException e) {

e.printStackTrace();

}

}

        

        System.out.println("------  끝  ------");

   }

}


class MyThread extends Thread {

boolean isRun;

MyThread(String name) {

setName(name);

}

public void setRunning(boolean run) {

this.isRun = run;

}

    public void run() {

        

        try {

            Thread.sleep(10000);

        }

        catch (InterruptedException e) {

            System.out.println("   " +getName() + "InterruptedException예외 발생");

        }

        

        try {

Thread.sleep(10); // main 스레드 출력 순서 테스트

} catch (InterruptedException e) {

e.printStackTrace();

}

        System.out.println("   "  +getName() +"   끝");

    }

}

Posted by 코드버무려
Android 안드로이드2014. 12. 4. 02:31

이클립스로 안드로이드 코드를 작성하면 에러는 아닌 비스한 문구가 해당 줄 좌측에 붙는다.

전구, 삼각형, 노란색, ..... 화살표


가지가지 모양이다.

색깔이 옅은 색이라 짙은 적색을 띄는 오류(error)와는 한눈에 구별이 든다. 그리고 나둬도 별 문제 없는 그러나 없는 편이 좀더 나으리라. 그 중에 한 가지를 열어봤다. 아래와 같이 긴 글이다. 설명이다. 영어로. 린트(Lint)에 관한 내용이라 차후에도 참고가 필요하다.


Call requires API level 5 (current min is 3):







Posted by 코드버무려
Android 안드로이드2014. 12. 4. 01:58

이클립스 단축키

안드로이드 AVD 단축키

Eclipse shortcut key

android avd shortcut key

안드로이드 에물레이터 단축키

android emulator shortcut key

Android Virtual Device shortcut key

android editor shortcut key









안드로이드 에디터 단축키

이클립스 단축키



[Ctrl + Shift + F] 들여쓰기 indent

[Alt + Shift + S] 소스를 자동으로 생성


[Ctrl + Shift + /] 드래그(Drag)해서 선택된 반전 구간을 블럭주석("{   }", "<!--   -->") 처리 

[Ctrl + Shift + \] 드래그(Drag)해서 선택된 반전 구간을 블럭 주석 해제


[Ctrl + /] 커서가 놓인 줄(Line) 앞머리에 주석("//")표시 켜고 끈다. 

[Ctrl + /] 앞머리 주석 표시 토글


[Ctrl + Space] 선택 가능한 키워드, 메서드, 상수를 드롭다운 메뉴로 불러준다.

[Ctrl + Shift + O] 자동으로 패키지를 임포트(import) 

[Ctrl + Shift + S] 수정한 파일을 한번에 저장(save)

[Ctrl + B] 프로젝트 빌드

[Ctrl + F11] 프로젝트 실행




안드로이드 엘물레이터 단축키

Android Virtual Device

[F2]                     왼쪽 소프트 메뉴

[Shift + F2]             오른쪽 소프트 메뉴

[Home]                 홈 버튼

[F6]                    트랙볼 모드 켜고 끔. 트랙볼 모드 토글

[F7]                    전원 버튼

[F8]                     셀(3G, LTE, CDMA)  네트워크 사용 켜고 끔, 네트워크 사용 토글

[Ctrl + F11]             에물레이터 화면을 이전 형태로 회전. (예, 수직모드, 수평모드)

[Ctrl + F12]             에물레이터 화면을 다음 형태로 회전. (예, portrait, landscape)

[Alt + Enter]            전체화면 토글. 전체화면 켜고끔




http://developer.android.com/tools/help/emulator.html







Posted by 코드버무려
php2014. 12. 4. 01:58

php 세션 로그인 과정


[start.php]

<?php
  require_once(__DIR__."/cfg.php");
  ini_set("display_errors", "1");

session_save_path('./sss');
session_start();



  $isIn = isset($_SESSION['isIn']) ? $_SESSION['isIn'] : false;
  echo $isIn."<br>";
  
  // exit;
  
  if($isIn === true) {
        echo "<div>You already logined.</div>";
        echo "<a href='./normal.php'>Click here to next page.</a>";
        // header('Location: ./normal.php');
		exit;
  } else {
	  
  }
?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    </head>
    <body>
        <form action="login_act.php" method="POST">
			<label>ID: </label><input type="text" name="id" />
            <label>password: </label><input type="text" name="pwd" /> 
			<input type="submit" />
        </form>
    </body>
</html>
</html>


[login_act.php]

<?php require_once(__DIR__."/cfg.php"); ini_set("display_errors", "1"); session_save_path('./sss'); session_start(); if(!empty($_POST['id']) && !empty($_POST['pwd'])){ if($_POST['id'] == $ss_id && $_POST['pwd'] == $ss_pw){ $_SESSION['isIn'] = true; $_SESSION['loginName'] = $ss_ln; $_SESSION['loginTime'] = time(); ini_set("session.cache_expire", 20); ini_set("session.gc_maxlifetime", 20); ini_set("session.gc_probability ", 100); ini_set("session.gc_divisor ", 100); header('Location: ./normal.php'); } } echo 'Can not log in.<br><br>'; echo '<a href="./start.php">Go to start page</a>'; ?>


[normal.php]

<?php ini_set("display_errors", "1"); session_save_path('./sss'); session_start(); ini_set("session.cache_expire", 20); ini_set("session.gc_maxlifetime", 20); ini_set("session.gc_probability ", 100); ini_set("session.gc_divisor ", 100); if(!isset($_SESSION['loginName'])){ header('Location: ./start.php'); } ?> <html> <body> <?php echo $_SESSION['isIn'];?><br /> Welcome. <?php echo $_SESSION['loginName'];?>!<br /> Login timestamp is <?php echo $_SESSION['loginTime'];?>!<br /> Login date is <?php echo date("Y-m-d h:i:s", $_SESSION['loginTime']);?>!<br /><br /> session_name is <?php echo session_name();?>!<br /> <a href="./logout_act.php">Logout</a> </body> </html>


[logout_act.php]

<?php ini_set("display_errors", "1"); session_save_path('./sss'); session_start(); session_destroy(); header('Location: ./start.php'); ?>


그리고 같은 폴더에 sss폴더를 만들어 준다.




'php' 카테고리의 다른 글

소소한 php 팁 tip  (0) 2016.12.03
php session 세션 로그인  (0) 2014.11.29
Posted by 코드버무려