2016-06-06 2 views
-1

나는이 오류가 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)

나도 몰라 그게 어디서 오는거야. 슈퍼 방법은 공개로

그것은, 사진과 숫돌

답변

0

onCreate 방법을 공개 확인에 저장된 연락처의 이름을 반환해야합니다, 당신은 약한 액세스 한정자 그것을 무시할 수 없습니다.

onCreateView (
0

는) 당신이 AppCompatActivity 클래스있는 방법 onCreateView (LayoutInflater에서의 인플레이터, 뷰 그룹 용기, 번들 savedInstanceState)이 없다 AppCompatActivity 의 서브 클래스를 생성 AppCompatActivity 즉 확장하는 활동에 조각 클래스

하는 방법입니다

그래서 당신은 당신이 오류가 발생하는 이유는 슈퍼 타입을 무시하지 방법을 말하는 그 AppComptrActivity

귀하의 경우 상위 클래스에서 merhod을 ovveriding되지 않습니다

+0

감사의하지만, 더 새로운 오류 : java.lang.ClassCastException가 :에 의한 net.lelandaislaposte.steven.contact.MainActivity이 캐스트 할 수없는 android.app.Activity –

+0

@StevenLnds이 오류가 발생한 행을 알 수 있습니까 – user5894647

+0

@StevenLnds logcat이 classcastexception이 발생한 위치를 알려줍니다. 예외가 발생한 위치를 알려주면 쉽게 알 수 있습니다. – user5894647

0

당신은 당신의 활동 클래스의 메소드 아래 cverride 수 있습니다

@Override 
public View onCreateView(String name, Context context, AttributeSet attrs) { 
    return super.onCreateView(name, context, attrs); 
} 

@Override 
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { 
    return super.onCreateView(parent, name, context, attrs); 
} 
관련 문제