2013-12-16 90 views
0

我結合holoeverywhere在我的應用程序viewpagerindicator,但我得到這個錯誤:的TextView無法投射到小部件

12-16 16:08:48.485: E/AndroidRuntime(12366): FATAL EXCEPTION: main 
12-16 16:08:48.485: E/AndroidRuntime(12366): 
java.lang.ClassCastException: android.widget.TextView cannot be cast 
to org.holoeverywhere.widget.TextView 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
com.smart.tangsel.viewpagerindicator.TestFragmentAdapter.instantiateItem(TestFragmentAdapter.java:101) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.support.v4.view.ViewPager.populate(ViewPager.java:982) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.support.v4.view.ViewPager.populate(ViewPager.java:914) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.View.measure(View.java:15193) 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
android.widget.LinearLayout.measureVertical(LinearLayout.java:833) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.widget.LinearLayout.onMeasure(LinearLayout.java:574) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.View.measure(View.java:15193) 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.View.measure(View.java:15193) 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.widget.LinearLayout.measureVertical(LinearLayout.java:681) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.widget.LinearLayout.onMeasure(LinearLayout.java:574) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.View.measure(View.java:15193) 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2217) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.view.View.measure(View.java:15193) 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4216) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.view.Choreographer.doCallbacks(Choreographer.java:555) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.Choreographer.doFrame(Choreographer.java:525) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
android.os.Handler.handleCallback(Handler.java:615) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.os.Handler.dispatchMessage(Handler.java:92) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
android.os.Looper.loop(Looper.java:137) 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
android.app.ActivityThread.main(ActivityThread.java:4794) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
java.lang.reflect.Method.invokeNative(Native Method) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
java.lang.reflect.Method.invoke(Method.java:511) 12-16 16:08:48.485: 
E/AndroidRuntime(12366): at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
12-16 16:08:48.485: E/AndroidRuntime(12366): at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 12-16 
16:08:48.485: E/AndroidRuntime(12366): at 
dalvik.system.NativeStart.main(Native Method) 

,這我的代碼:

package com.smart.tangsel.viewpagerindicator; 

import com.smart.tangsel.LoginActivity; 
import com.smart.tangsel.UserFunctions; 
import com.smart.tangsel.app.ContentActivity; 
import com.smart.tangsel.app.ContentCommentActivity; 
import com.smart.tangsel.app.DetailLaporanActivity; 
import com.smart.tangsel.app.SplashTangsel; 
import com.smart.tangsel.app.WelcomeActivity; 

import com.smart.tangsel.database_content.DatabaseHandler; 
import com.smart.tangsel.database_content.Setting_App; 
import com.smart.tangsel.R; 

import org.holoeverywhere.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.pm.PackageInfo; 
import android.content.pm.PackageManager.NameNotFoundException; 
import android.graphics.Color; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.os.Parcelable; 
import android.support.v4.view.PagerAdapter; 
import android.support.v4.view.ViewPager; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import org.holoeverywhere.widget.Button; 
import android.widget.ImageView; 
import android.widget.TabWidget; 
import org.holoeverywhere.widget.TextView; 

public class TestFragmentAdapter extends PagerAdapter { 

    private static String[] titles = new String[] { 
     "Mudah", 
     "Capture", 
     "Submit", 
     "Share", 
     "Mari berpartisipasi dalam Pembangunan Kota Tangerang Selatan melalui Smart Tangsel" 
    }; 

    private static String[] desc = new String[] { 
     "Hanya dengan 3 langkah mudah", 
     "Adukan temuan anda akan Kerusakan Fasilitas, Kemacetan dan Penyakit Masyarakat lainnya di kota Tangerang Selatan dengan sangat mudah.", 
     "Ketik langsung keluhan anda untuk Pemerintah Kota Tangerang Selatan.", 
     "Bagikan keluhan anda ke Social Media yang anda miliki.", 
     "" 
    }; 

    private static int[] images = new int[] { 
     R.drawable.startup1, 
     R.drawable.startup2, 
     R.drawable.startup3, 
     R.drawable.startup4, 
     R.drawable.smart_tangsel, 
    }; 

    private final Context context; 

    public TestFragmentAdapter(Context context) { 
     this.context = context; 
    } 

    UserFunctions userFunctions; 

    @Override 
    public boolean isViewFromObject(View v, Object o) { 
     // TODO Auto-generated method stub 
     return v.equals(o); 
    } 

    @Override 
    public String getPageTitle(int position) { 
     return titles[position]; 
    } 

    public String versi_app(Context context){ 
     PackageInfo pInfo = null; 
     try { 
      pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); 
     } catch (NameNotFoundException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 

    String version; 
    return version = pInfo.versionName; 
    } 

    @Override 
    public int getCount() { 
     return titles.length; 
    } 

    @Override 
    public Object instantiateItem(ViewGroup container, int position) { 
     View v = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) 
       .inflate(R.layout.info_update, null, false); 

     TextView title = (TextView)v.findViewById(R.id.title_update); 
     TextView desc_up = (TextView)v.findViewById(R.id.desc_up); 
     ImageView description = (ImageView) v.findViewById(R.id.img_update); 
     Button btn_start_app = (Button) v.findViewById(R.id.btn_start_app); 

     if(position==(getCount()-1)){ 
      btn_start_app.setVisibility(View.VISIBLE); 
      desc_up.setVisibility(View.GONE); 
      btn_start_app.setOnClickListener(new android.view.View.OnClickListener() 
      { 

       public void onClick(View v) 
       {     

        DatabaseHandler settingappDb = new DatabaseHandler(context);     
        Setting_App setting_app = new Setting_App("infoupdate",versi_app(context));   
        boolean stat= settingappDb.addsetting_app(setting_app); 

        if(stat){ 
         userFunctions = new UserFunctions(); 
         if(userFunctions.isUserLoggedIn(context)){ 
          context.startActivity(new Intent(context,SplashTangsel.class)); 
         } 
         else{ 
          context.startActivity(new Intent(context,LoginActivity.class)); 
         } 
        // ((Activity) context).overridePendingTransition (R.anim.push_left_in, R.anim.push_left_out); 
         ((Activity) context).finish(); 
        } 



       } 
      }); 
     } 

     desc_up.setText(desc[position]); 

     title.setText(titles[position]); 
     title.setShadowLayer(1,1,1, Color.WHITE); 

    // if(position==0)title.setText(titles[position]+versi_app(context)); 

     description.setImageResource(images[position]); 

     //This is very important 
     ((ViewPager) container).addView(v, 0); 

     return v; 
    } 

    @Override 
    public void destroyItem(View pager, int position, Object view) { 
     ((ViewPager) pager).removeView((View) view); 
    } 

    @Override 
    public void finishUpdate(View view) { 
    } 

    @Override 
    public void restoreState(Parcelable p, ClassLoader c) { 
    } 

    @Override 
    public Parcelable saveState() { 
     return null; 
    } 

    @Override 
    public void startUpdate(View view) { 
    } 


} 

當我點擊錯誤,似乎部分TextView title =(TextView)v.findViewById(R.id.title_update);

我該如何解決?

回答

0

取下進口

import org.holoeverywhere.widget.TextView; 

import android.widget.TextView; 
+0

thans你的答案,我會試試:) – bukanamay

2

通過對事物的外觀取代它,你在你的佈局文件中使用標準Android TextView不是自定義的org.holoeverywhere.widget.TextView

<org.holoeverywhere.widget.TextView 
    android:id="@+id/title_update" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
+0

thans你的答案,我會試試:) – bukanamay

0

確保你有進口org.holoeverywhere.widget.TextView。像這種

import android.app.Activity; 
import android.os.Bundle; 
import org.holoeverywhere.widget.TextView; 

public class MyActivity extends Activity { 
/** 
* Called when the activity is first created. 
*/ 

private TextView mTvShow; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mTvShow = (TextView) this.findViewById(R.layout.main); 
    mTvShow.setText("Hello"); 
    } 
} 


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
<org.holoeverywhere.widget.TextView 
     android:id="@+id/holo_tv_show" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello World, MyActivity"/> 
</LinearLayout>