2014-11-01 8 views
0

내 문제는 내가 안드로이드 에뮬레이터에서 응용 프로그램을 실행할 때 응용 프로그램이 시작되지만 로그인 후 응용 프로그램이 빠르게 충돌하고 팝업을 표시합니다 : "불행히도, 중지되었습니다." 코드를 살펴본 결과 인터넷에서 철저히 검색했습니다. 예, 저는 안드로이드 개발에 초보자입니다. LogCat에서 생성 된 오류를 살펴 보았지만 문제점을 알지 못하고받은 오류를 기반으로 오류를 찾을 수 있습니다.안드로이드 - RuntimeException - ClassCastException

11-01 08:09:37.650: W/dalvikvm(2382): threadid=1: thread exiting with uncaught exception (group=0xb0d02b20) 
11-01 08:09:37.650: E/AndroidRuntime(2382): FATAL EXCEPTION: main 
11-01 08:09:37.650: E/AndroidRuntime(2382): Process: com.pozs.myappz, PID: 2382 
11-01 08:09:37.650: E/AndroidRuntime(2382): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pozs.myappz/com.pozs.myappz.Tabbedmaincontroller}: java.lang.ClassCastException: com.handmark.pulltorefresh.library.PullToRefreshGridView$InternalGridViewSDK9 cannot be cast to com.penq.utils.LoadMoreGrid 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.os.Handler.dispatchMessage(Handler.java:102) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.os.Looper.loop(Looper.java:136) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at java.lang.reflect.Method.invoke(Method.java:515) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at dalvik.system.NativeStart.main(Native Method) 
11-01 08:09:37.650: E/AndroidRuntime(2382): Caused by: java.lang.ClassCastException: com.handmark.pulltorefresh.library.PullToRefreshGridView$InternalGridViewSDK9 cannot be cast to com.penq.utils.LoadMoreGrid 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at com.pozs.myappz.GridFragment.onCreateView(GridFragment.java:70) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.Activity.performStart(Activity.java:5241) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168) 
11-01 08:09:37.650: E/AndroidRuntime(2382):  ... 11 more 

다음은 GridFragment.java입니다 :

package com.pozs.myappz; 

import java.util.ArrayList; 

<...other import here deleted...> 

import android.widget.GridView; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.handmark.pulltorefresh.library.PullToRefreshBase; 
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; 
import com.handmark.pulltorefresh.library.PullToRefreshGridView; 
import com.penq.utils.LoadMoreGrid; 
import com.penq.utils.LoadMoreGrid.OnLoadMoreListener; 
import com.pozs.Vo.FeedsVo; 
import com.pozs.peak.adapter.GridAdapter; 
import com.pozs.peak.utils.CommonUtils; 

public class GridFragment extends Fragment { 
public static ArrayList<FeedsVo> abcd; 

private GridAdapter ga; 
private String m_urlResp, m_userIdVal; 
private Bundle m_bundle; 
private String profileName, imageUrl, m_hearts, m_likes, m_ImageID, 
     m_videoUrl, m_swebLinkUrl; 
private ProgressDialog pDlg; 
private Context m_context; 
private Boolean m_resultStatus, m_isHeartbyMe = false, 
     m_isLikebyMe = false,isDone=false; 
private TextView m_tvNoData, m_tvTitle; 
    int pageval = 1; 
private PullToRefreshGridView mPullRefreshGridView; 
private LoadMoreGrid mGridView; 
private ImageView m_ivFollower; 

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.feedpage, container, false); 
    m_context = GridFragment.this.getActivity(); 
    abcd = new ArrayList<FeedsVo>(); 
    pDlg = new ProgressDialog(m_context); 

    m_bundle = this.getArguments(); 
    m_userIdVal = m_bundle.getString("userId"); 

    m_tvNoData = (TextView) v.findViewById(R.id.tv_nodata); 
    m_tvTitle = (TextView) v.findViewById(R.id.fd_tvTitle); 

    mPullRefreshGridView = (PullToRefreshGridView) v 
      .findViewById(R.id.feedgrid); 
    mGridView = (LoadMoreGrid) mPullRefreshGridView.getRefreshableView(); <--Line 70 as it is indicated in logcat 
    m_ivFollower = (ImageView) v.findViewById(R.id.fd_ivFollow); 

    Typeface font = Typeface.createFromAsset(m_context.getAssets(), 
      "helvetica.ttf"); 
    m_tvTitle.setTypeface(font); 
    ga = new GridAdapter(abcd, getActivity()); 

    mGridView.setOnLoadMoreListener(new OnLoadMoreListener() { 

     public void onLoadMore() { 
      feedtask Feed = new feedtask(); 
      Feed.execute(); 

     } 
    }); 

<...other codes here deleted...>   

    if (myappz.m_FeedsScreen == "" || myappz.m_FeedsScreen == null) { 
      pageval = 1; 
      feedtask Feed = new feedtask(); 
      Feed.execute(); 
      mGridView.setAdapter(ga); 
      abcd.clear(); 

      Log.e("GridFragment", "Resume Called"); 

     myappz.m_sFollowerId = null; 
     } 
    } 

} 

(가) 위, 내가 여기서 뭔가를 놓친 확실히, 너무 나에게 좋아 보인다 여기

는 로그 캣입니다. 어떤 도움을 주셔서 감사합니다.

감사합니다.

+0

mPullRefreshGridView.getRefreshableView()를 LoadMoreGrid로 형변환 할 수 없습니다. –

+0

감사합니다. 아마도 다른 유형 때문일 수 있습니다. – KeLaM

답변

0

이 예외는 응용 프로그램 코드가 특정 개체를 인스턴스가 아닌 클래스로 캐스팅하려고했음을 나타 내기 위해 사용됩니다.

예를 들어, Integer 개체는 String 개체에 캐스팅 될 수 없습니다. 귀하의 경우

당신은 ... 허용되지 않습니다 LoadMoreGridmPullRefreshGridView 캐스팅하려고

, 다른 클래스에 클래스의 객체를 캐스팅 새로운 유형의 부모 클래스 중 하나에 속해 있는지 확인하려고 .