아래 소스는 해당 리스트뷰 항목을 클릭했을때 알림이오게 테스트하려고
setOnItemClickListener으로 터치한 상황입니다 현재 RegistrationID는 프레퍼런스에 저장되어있는 상태입니다.
문제는 받아온 RegistrationID를 불러오는 부분이후 부터 에러가 발생하는거같은데 찾을수가 없습니다 ㅠㅠ
원래는
// 받아온 Registration ID를 불러온다.
Context context = null;
SharedPreferences shrdPref = PreferenceManager
.getDefaultSharedPreferences(context);
String registrationID = shrdPref.getString("registrationID", null);
이부분에 (context)대신 this가 들어가야하는데 에러가나서 제가 어쩔수없이 Context를 null로 만들어주고
넣어줘서 에러는 안나게했는데...실행시 리스트뷰 아이템을 선택하면 강제종료됩니다....도와주시면 감사하겠습니다..
어디가문제인지..
/////////////////////////////소스////////////////////////
case 4: // C2DM 에러를 잡자
// HTTP 통신을 하기 위해 두 변수를 선언한다.
URL url;
HttpURLConnection con;
// 받아온 Registration ID를 불러온다.
Context context = null;
SharedPreferences shrdPref = PreferenceManager
.getDefaultSharedPreferences(context);
String registrationID = shrdPref.getString("registrationID", null);
Toast.makeText(getApplicationContext(),
"프리퍼런스에서 불러온 키값은 " + registrationID + " 입니다", 3000)
.show();
shrdPref = null;
// 서버에 전송한 후 피드백을 받을 일이 있다면 아래 변수를 선언하자.
String receivedMessage = "";
try {
// 통신할 서버 주소를 적는다. 본 포스트에서는 PHP를 사용하니 php 경로를 적는다.
url = new URL("URL주소는 정확히 입력했어요!!!!!!!");
// 주소로 접속하여 접속 객체를 얻는다.
con = (HttpURLConnection) url.openConnection();
// 아래는 POST 통신을 하기 위한 설정이다.
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
// 아래는 POST 통신으로 서버에 전달할 값들을 나열하는 것이다.
// 우선 Registration ID를 넣자.
String postBody = "registrationID=" + registrationID;
// 그리고 추가적으로 서버에 전달할 값이 있다면 &와 함께 Key-Value로 넣는다.
// postBody += "&message=" + message;
// 위와 같이 하면 body는 registrationID=??????????&message=????
// 식이 될 것이다.
// 이제 서버로 전송하자.
OutputStreamWriter wr = new OutputStreamWriter(con
.getOutputStream());
wr.write(postBody);
// 전송이 완료되면 반드시 출력 접속을 끊는다.
wr.flush();
// 만약 서버 PHP에서 피드백을 준다면 아래 소스가 필요할 것이다.
BufferedReader rd = new BufferedReader(
new InputStreamReader(con.getInputStream(),
"UTF-8"));
String line = null;
while ((line = rd.readLine()) != null) {
receivedMessage += line;
}
line = null;
rd.close();
wr.close();
// 아래는 본인이 피드백 처리를 한 것이므로 무시해도 상관 없다.
if (receivedMessage.equals("complete")) {
handler.sendEmptyMessage(1);
} else {
handler.sendEmptyMessage(2);
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
// ///////////////////////////////////////////////////////////////////
break;
로그캣입니다..




NullPointerException 이네요..
context 값을 null로 했으니 위와 같은 에러가 뜬거죠..
private Context context = null; 로 선언하시고,, onCreate 에서 context = this로 값 세팅하시고 해보세요~