나는이 오류가 onCreateView 슈퍼에서 메서드를 구현하지 않습니다 방법은 무시하거나 슈퍼에서 메소드를 구현하지 않습니다오류 : 방법은 무시하거나
내 코드 :
공용 클래스 MainActivity가 조각을 {확장
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
final ListView list = (ListView) rootView.findViewById(android.R.id.list);
final List<Map<String, Object>> contacts = retrieveContacts(getActivity().getContentResolver());
if (contacts != null)
{
final SimpleAdapter adapter = new SimpleAdapter(getActivity(), contacts, R.layout.activity_main, new String[] { "name", "photo" }, new int[] { R.id.name, R.id.photo });
adapter.setViewBinder(new SimpleAdapter.ViewBinder()
{
@Override
public boolean setViewValue(View view, Object data, String textRepresentation)
{
if ((view instanceof ImageView) & (data instanceof Bitmap))
{
final ImageView image = (ImageView) view;
final Bitmap photo = (Bitmap) data;
image.setImageBitmap(photo);
return true;
}
return false;
}
});
list.setAdapter(adapter);
}
return rootView;
}
private Bitmap getPhoto(ContentResolver contentResolver, long contactId)
{
Bitmap photo = null;
final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
final Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
final Cursor cursor = contentResolver.query(photoUri, new String[] { ContactsContract.Contacts.Photo.DATA15 }, null, null, null);
if (cursor == null)
{
Log.e("getPhoto", "Cannot retrieve the photo of the contact with id '" + contactId + "'");
return null;
}
if (cursor.moveToFirst() == true)
{
final byte[] data = cursor.getBlob(0);
if (data != null)
{
photo = BitmapFactory.decodeStream(new ByteArrayInputStream(data));
}
}
if (cursor.isClosed() == false)
{
cursor.close();
}
return photo;
}
private List<Map<String, Object>> retrieveContacts(ContentResolver contentResolver)
{
final List<Map<String, Object>> contacts = new ArrayList<Map<String, Object>>();
final Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, new String[] { ContactsContract.Data.DISPLAY_NAME,
ContactsContract.Data._ID, ContactsContract.Contacts.HAS_PHONE_NUMBER }, null, null, null);
if (cursor == null)
{
Log.e("retrieveContacts", "Cannot retrieve the contacts");
return null;
}
if (cursor.moveToFirst() == true)
{
do
{
final long id = Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Data._ID)));
final String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
final int hasPhoneNumber = cursor.getInt(cursor.getColumnIndex(ContactsContract.Data.HAS_PHONE_NUMBER));
if (hasPhoneNumber > 0)
{
final Bitmap photo = getPhoto(contentResolver, id);
final Map<String, Object> contact = new HashMap<String, Object>();
contact.put("name", name);
contact.put("photo", photo);
contacts.add(contact);
}
}
while (cursor.moveToNext() == true);
}
if (cursor.isClosed() == false)
{
cursor.close();
}
return contacts;
}
}
로그 캣 :
06-06 12 : 04 : 42.579 3924-3924/net.lelandaislaposte.steven.contact E/AndroidRuntime : 치명적인 예외 : 주 프로세스 : net.lelandaislaposte.steven.contact, PID : 3924 java.lang.RuntimeException : Unable 활동을 인스턴스화하려면 ComponentInfo {net.lelandaislaposte.steven.contact/net.lelandaislaposte.steven.contact.MainActivity} : java.lang.ClassCastException : net.lelandaislaposte.steven.contact.MainActivity를 android.app.Activity로 캐스팅 할 수 없습니다. at android.app.ActivityThread.performLaunchActivity 로이드에서 android.app.ActivityThread.-wrap11 (ActivityThread.java) 에서 android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2476)에서 (ActivityThread.java:2327) .app.ActivityThread $ H.handleMessage (ActivityThread.java:1344) android.os.Handler.dispatchMessage (Handler.java:102)에서 at android.os.Looper.loop (Looper.java:148) at android .App.ActivityThread.main (ActivityThread.java:5417) at java.lang.reflect.Method.invoke (기본 메소드) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616) 발생 원인 : java.lang.ClassCastException : net.lelandaislaposte.steven.contact.MainActivity를 android.app.Activity로 캐스팅 할 수 없습니다. at android.app.Instrumentati on.newActivity (Instrumentation.java:1067) android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2317)에서 android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2476)에서 android.app.ActivityThread에서 . -wrap11 (ActivityThread.java) android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1344) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:148) android.app.ActivityThread.main (ActivityThread.java:5417) at java.lang.reflect.Method.invoke (기본 메소드)com.android.internal.os.ZygoteInit.main에서 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:726) 에서 1,363,210 (ZygoteInit.java:616)
나도 몰라 그게 어디서 오는거야. 슈퍼 방법은 공개로
그것은, 사진과 숫돌
감사의하지만, 더 새로운 오류 : java.lang.ClassCastException가 :에 의한 net.lelandaislaposte.steven.contact.MainActivity이 캐스트 할 수없는 android.app.Activity –
@StevenLnds이 오류가 발생한 행을 알 수 있습니까 – user5894647
@StevenLnds logcat이 classcastexception이 발생한 위치를 알려줍니다. 예외가 발생한 위치를 알려주면 쉽게 알 수 있습니다. – user5894647