2016-08-18 7 views
0

私はとcrashlyticsは、ログの下を示しているボタンを押すと、アプリケーションがクラッシュしつつあるjava.lang.UnsupportedOperationExceptionが:色に変換できません:タイプ= 0x2のを唯一のAPIレベルで19

>Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.shmoti_v4/com.example.android.shmoti_v4.MainActivities.Movies_Home}: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
      at android.app.ActivityThread.access$900(ActivityThread.java:175) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:146) 
      at android.app.ActivityThread.main(ActivityThread.java:5602) 
      at java.lang.reflect.Method.invokeNative(Method.java) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
      at dalvik.system.NativeStart.main(NativeStart.java) 
    Caused by java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 
      at android.content.res.TypedArray.getColor(TypedArray.java:327) 
      at android.widget.TextView.<init>(TextView.java:1003) 
      at android.widget.TextView.<init>(TextView.java:908) 
      at android.widget.TextView.<init>(TextView.java:904) 
      at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:750) 
      at com.example.android.shmoti_v4.MainActivities.Movies_Home.onCreate(Movies_Home.java:74) 
      at android.app.Activity.performCreate(Activity.java:5451) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
      at android.app.ActivityThread.access$900(ActivityThread.java:175) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:146) 
      at android.app.ActivityThread.main(ActivityThread.java:5602) 
      at java.lang.reflect.Method.invokeNative(Method.java) 
      at java.lang.reflect.Method.invoke(Methenter code hereod.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
      at dalvik.system.NativeStart.main(NativeStart.java)`enter code here` 


Styles.xml file 


<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> 
     <!-- Customize your theme here. --> 

     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

    <style name="CustomTheme" parent="MaterialDrawerTheme"> 
    <!-- ...and here we setting appcompat’s color theming attrs --> 
    <item name="colorPrimary">@color/material_drawer_primary</item> 
    <item name="colorPrimaryDark">@color/shmotiColor</item> 
    <item name="colorAccent">@color/material_drawer_accent</item> 

    <!-- MaterialDrawer specific values --> 
    <item name="material_drawer_background">@color/material_drawer_dark_background</item> 
    <item name="material_drawer_primary_text">@color/material_drawer_dark_primary_text</item> 
    <item name="material_drawer_primary_icon">@color/material_drawer_dark_primary_icon</item> 
    <item name="material_drawer_secondary_text">@color/material_drawer_dark_secondary_text</item> 
    <item name="material_drawer_hint_text">@color/material_drawer_dark_hint_text</item> 
    <item name="material_drawer_divider">@color/material_drawer_dark_divider</item> 
    <item name="material_drawer_selected">@color/material_drawer_dark_selected</item> 
    <item name="material_drawer_selected_text">@color/shmotiColor</item> 
    <item name="material_drawer_header_selection_text">@color/material_drawer_dark_header_selection_text</item> 
    </style> 

    <!--Alert Dialog Box Theme--> 
    <style name="AlertDialogCustom" parent="Theme.AppCompat.Dialog.Alert"> 
     <item name="android:background">@color/colorMaterialDark</item> 
     <item name="android:textColor">@color/shmotiColor</item> 
     <item name="colorAccent">@color/shmotiColor</item> 
    </style> 



</resources> 


//Movies_Home.java file is as below// 

pleseは以下のコードを見つけて、アプリがAPIレベル19

//Movies_Home.javaファイルに墜落なっている理由を私に知らせてくださいすることは以下の通りです。// pleseは、以下のコードを見つけて、私を聞かせてくださいアプリはAPIレベルに墜落なっている理由を知っている19

package com.example.android.shmoti_v4.MainActivities; 

import android.app.ActivityOptions; 
import android.content.Context; 
import android.content.Intent; 
import android.graphics.Bitmap; 
import android.os.Bundle; 
import android.support.v4.view.ViewPager; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.LayoutInflater; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.ProgressBar; 
import android.widget.TextView; 
import android.widget.Toast; 

//import com.example.android.shmoti_v3.Utils.NodalClass; 
import com.example.android.shmoti_v4.Utils.SlidingTabLayout; 
import com.example.android.shmoti_v4.Utils.ViewPagerAdapter; 
import com.example.android.shmoti_v4.R; 
import com.google.gson.Gson; 
import com.nostra13.universalimageloader.core.DisplayImageOptions; 
import com.nostra13.universalimageloader.core.ImageLoader; 
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 
import com.nostra13.universalimageloader.core.assist.FailReason; 
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; 

import java.util.List; 

/** 

*/ 
public class Movies_Home extends AppCompatActivity { 

    // Declaring Your View and Variables 

    Toolbar toolbar; 
    ViewPager pager; 
    ViewPagerAdapter adapter; 
    SlidingTabLayout tabs; 
    CharSequence Titles[] = {"Current Running", "Upcoming"}; 
    int Numboftabs = 2; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.activity_movies); 

//  //ImageLoaderOptions 
//  DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() 
//    .cacheInMemory(true) 
//    .cacheOnDisk(true) 
//    .build(); 
//  ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) 
//    .defaultDisplayImageOptions(defaultOptions) 
//    .build(); 
//  ImageLoader.getInstance().init(config); // Do it on Application start 


     // Creating The Toolbar and setting it as the Toolbar for the activity 

     toolbar = (Toolbar) findViewById(R.id.toolbar_main); 
     toolbar.setTitle("Movies"); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayShowTitleEnabled(true); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 


     // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs. 
     adapter = new ViewPagerAdapter(getSupportFragmentManager(), Titles, Numboftabs); 

     // Assigning ViewPager View and setting the adapter 
     pager = (ViewPager) findViewById(R.id.movies_pager); 
     pager.setAdapter(adapter); 


     // Assiging the Sliding Tab Layout View 
     tabs = (SlidingTabLayout) findViewById(R.id.movie_tabs); 
     tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width 

     //Setting Custom Color for the Scroll bar indicator of the Tab View 
     tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { 
      @Override 
      public int getIndicatorColor(int position) { 
       return getResources().getColor(R.color.shmotiColor); 
      } 
     }); 

     // Setting the ViewPager For the SlidingTabsLayout 
     tabs.setViewPager(pager); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case android.R.id.home: 
       onBackPressed(); 
     } 
     return true; 
    } 


} 

// @Override 
// public boolean onCreateOptionsMenu(Menu menu) { 
//  // Inflate the menu; this adds items to the action bar if it is present. 
//  getMenuInflater().inflate(R.menu.menu_main, menu); 
//  return true; 
// } 
// 
+0

'com.example.android.shmoti_v4.MainActivities'クラスを投稿できますか? – Soham

+0

ファイルを追加しました –

+0

'activity_movies'も投稿できますか? – Soham

答えて

1

getResources()GETCOLOR(R.color.shmotiColor)。メソッドは推奨されません。

最善のアプローチを使用することであるように見えます:

ContextCompat.getColor(文脈、R.color.color_name)

これはマシュマロ2パラメータ法または事前マシュマロ方法を選択します適切に。

関連する問題