2014-11-01 83 views
0

我的問題是,當我在android模擬器上運行我的應用程序時,應用程序啓動,但登錄後,應用程序迅速崩潰並顯示彈出窗口:「不幸的是,已停止。我已經瀏覽了代碼,並且已經在互聯網上徹底搜索了一個答案。是的,我是Android開發的新手。我查看了LogCat生成的錯誤,但根據收到的錯誤不知道問題以及在哪裏找到它。Android - RuntimeException - ClassCastException

這裏是logcat的:

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。 – 2014-11-01 14:13:23

+0

謝謝。也許是因爲不同的類型。 – KeLaM 2014-11-02 06:16:13

回答

0

此異常用於指示應用程序的代碼已嘗試將特定對象轉換爲不是實例的類。例如,Integer對象不能被鑄造到String對象。

你的情況

你想投mPullRefreshGridViewLoadMoreGrid,這是不允許的..

努力蒙上了類的一個對象到另一個類,確保新的類型屬於它的父類中的一個時。

相關問題