2016-03-26 7 views
0

MainActivityにリンクされた2つのフラグメントがあります。 2番目のFragmentには、Saturationbar付きのColorPicker Wheelがあり、ColorPickerのrgb値をメインアクティビティに送信します。 MainActivityにRGB値を送信せずに、ログの猫がちょうどこの警告を表示:フラグメントとアクティビティの間でデータを送信するとアプリケーションがクラッシュする

W/ResourceType: Skipping entry 0x1050089 in package table 0 because it is not complex! 
W/ResourceType: Skipping entry 0x1050089 in package table 0 because it is not complex! 
W/ResourceType: Skipping entry 0x1050089 in package table 0 because it is not complex! 
D/dalvikvm: GC_FOR_ALLOC freed 1399K, 10% free 30330K/33479K, paused 19ms, total 21ms 
D/dalvikvm: GC_FOR_ALLOC freed 135K, 10% free 30465K/33479K, paused 20ms, total 20ms 
I/dalvikvm-heap: Grow heap (frag case) to 32.381MB for 1441296-byte allocation 
D/dalvikvm: GC_FOR_ALLOC freed <1K, 9% free 31873K/34887K, paused 34ms, total 34ms 
D/dalvikvm: GC_FOR_ALLOC freed <1K, 9% free 31873K/34887K, paused 19ms, total 19ms 
I/dalvikvm-heap: Grow heap (frag case) to 35.476MB for 3244816-byte allocation 
D/dalvikvm: GC_CONCURRENT freed 0K, 8% free 35041K/38087K, paused 2ms+2ms, total 26ms 
D/dalvikvm: GC_FOR_ALLOC freed 1471K, 9% free 34803K/38087K, paused 17ms, total 17ms 
I/dalvikvm-heap: Grow heap (frag case) to 37.493MB for 2359312-byte allocation 
D/dalvikvm: GC_CONCURRENT freed <1K, 9% free 37107K/40455K, paused 2ms+21ms, total 46ms 
W/ResourceType: Skipping entry 0x1050089 in package table 0 because it is not complex! 
W/ResourceType: Skipping entry 0x1050089 in package table 0 because it is not complex! 

を私はすでに結果なしで、R.javaファイルに0x01050089を見つけることを試みました。

私のFragmentクラスにMainActivityにrgb値を送るためにIntent Codeを添付すると、2フラグメントを選択するとlogcatに次のエラーが発生し、アプリケーションがクラッシュします。 ColorPickerので

E/dalvikvm-heap: Out of memory on a 3244816-byte allocation. 
I/dalvikvm: "main" prio=5 tid=1 RUNNABLE 
I/dalvikvm: | group="main" sCount=0 dsCount=0 obj=0x41063508 self=0x40e5ab08 
I/dalvikvm: | sysTid=6777 nice=0 sched=0/0 cgrp=apps handle=1074536240 
I/dalvikvm: | schedstat=(2552959394 1319248728 5243) utm=210 stm=44 core=1 
I/dalvikvm:  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
I/dalvikvm:  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:625) 
I/dalvikvm:  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:478) 
I/dalvikvm:  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781) 
I/dalvikvm:  at android.content.res.Resources.loadDrawable(Resources.java:1963) 
I/dalvikvm:  at android.content.res.Resources.getDrawable(Resources.java:672) 
I/dalvikvm:  at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48) 
I/dalvikvm:  at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374) 
I/dalvikvm:  at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44) 
I/dalvikvm:  at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323) 
I/dalvikvm:  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180) 
I/dalvikvm:  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173) 
I/dalvikvm:  at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421) 
I/dalvikvm:  at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:505) 
I/dalvikvm:  at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:436) 
I/dalvikvm:  at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:112) 
I/dalvikvm:  at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:241) 
I/dalvikvm:  at android.support.design.widget.NavigationView.<init>(NavigationView.java:169) 
I/dalvikvm:  at android.support.design.widget.NavigationView.<init>(NavigationView.java:95) 
I/dalvikvm:  at java.lang.reflect.Constructor.constructNative(Native Method) 
I/dalvikvm:  at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
I/dalvikvm:  at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
I/dalvikvm:  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
I/dalvikvm:  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
I/dalvikvm:  at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
I/dalvikvm:  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
I/dalvikvm:  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
I/dalvikvm:  at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
I/dalvikvm:  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
I/dalvikvm:  at com.example.christian.rapid_charge_quad_05.MainActivity.onCreate(MainActivity.java:63) 
I/dalvikvm:  at android.app.Activity.performCreate(Activity.java:5206) 
I/dalvikvm:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
I/dalvikvm:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074) 
I/dalvikvm:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135) 
I/dalvikvm:  at android.app.ActivityThread.access$700(ActivityThread.java:140) 
I/dalvikvm:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237) 
I/dalvikvm:  at android.os.Handler.dispatchMessage(Handler.java:99) 
I/dalvikvm:  at android.os.Looper.loop(Looper.java:137) 
I/dalvikvm:  at android.app.ActivityThread.main(ActivityThread.java:4921) 
I/dalvikvm:  at java.lang.reflect.Method.invokeNative(Native Method) 
I/dalvikvm:  at java.lang.reflect.Method.invoke(Method.java:511) 
I/dalvikvm:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027) 
I/dalvikvm:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) 
I/dalvikvm:  at dalvik.system.NativeStart.main(Native Method) 
A/libc: Fatal signal 11 (SIGSEGV) at 0x000006a0 (code=1), thread 6777 (_charge_quad_05) 

フラグメント2:

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View rootview = inflater.inflate(R.layout.fragment_beleuchtung, container, false); 

    return rootview; 
} 


@Override 
public void onActivityCreated(@Nullable Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 



    ColorPicker colorPicker = (ColorPicker)getActivity().findViewById(R.id.color_picker); 

    ValueBar valueBar = (ValueBar)getActivity().findViewById(R.id.valuebar); 


    colorPicker.addValueBar(valueBar); 
    colorPicker.getColor(); 

    colorPicker.setOldCenterColor(colorPicker.getColor()); 

    colorPicker.setOnColorChangedListener(this); 

    colorPicker.setShowOldCenterColor(false); 




} 

@Override 
public void onColorChanged(final int color) { 

    final int c; 

    final String[] colorrgb = new String[3]; 

    final TextView text = (TextView)getActivity().findViewById(R.id.Rot); 
    final TextView text2 = (TextView)getActivity().findViewById(R.id.Grün); 
    final TextView text3 = (TextView)getActivity().findViewById(R.id.Blau); 

    c = color; 

    new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      // text.setTextColor(Color.rgb(Color.red(c), Color.green(c), Color.blue(c))); 
      // text.setText("Rot" + Color.red(c)+",Blau"+Color.blue(c)+",Grün"+Color.green(c)); 

      text.setText(""+Color.red(c)); 
      text2.setText(""+Color.green(c)); 
      text3.setText(""+Color.blue(c)); 
      colorrgb[0] = String.valueOf(Color.red(c)); 
      colorrgb[1] = String.valueOf(Color.blue(c)); 
      colorrgb[2] = String.valueOf(Color.green(c)); 

     } 
    },2000); 

    Intent intent = new Intent(getActivity().getBaseContext(), MainActivity.class); 
    intent.putExtra("color",colorrgb); 
    getActivity().startActivity(intent); 



} 

    } 

MainActivityパートIカラー値を受け取る:Fragmentの活性を有するコミュニティに

 Intent intent = getIntent(); 
    if(intent.getStringExtra("color") != null) { 
     String[] color = intent.getStringArrayExtra("color"); 

    } 
+0

フラグメント2のこの部分で別のアクティビティを開始しています。 'Intent intent =新しいインテント(getActivity()。getBaseContext()、MainActivity.class);intent.putExtra( "color"、colorrgb); getActivity()。startActivity(intent); 'おそらく問題です。 –

答えて

0

は、あなたがコールバックを使用する必要があります。 Android Developer

でお勧めします。あなたのフラグメントで

public class YourActivity extends Activity implement OnColorChangeListener { 
    int[] colors; 
    public void onColorChangeListener(int[] colors) { 
     //copy array colors to this.colors and do anything with new color. 
    } 
} 

3):

1)を作成インタフェース

public interface OnColorChangeListener { 
    void onColorChangeListener(int[] colors); 
} 

2)YourActivityクラスであなたのフラグメントのホストになります。ただ、以下のように何かをする

public class FragmentA extends Fragment { 
    OnColorChangeListener mListener; 

    @Override 
    public void onAttach(Activity activity) { 
     super.onAttach(activity); 
     try { 
      mListener = (OnColorChangeListener) activity; 
     } catch (ClassCastException e) { 
      throw new ClassCastException(activity.toString() + " must implement OnColorChangeListener"); 
     } 
    } 
    @Override 
    public void onColorChanged(final int color) { 
     // i copy your code to demonstrate. 
     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       // text.setTextColor(Color.rgb(Color.red(c), Color.green(c), Color.blue(c))); 
       // text.setText("Rot" + Color.red(c)+",Blau"+Color.blue(c)+",Grün"+Color.green(c)); 

       text.setText(""+Color.red(c)); 
       text2.setText(""+Color.green(c)); 
       text3.setText(""+Color.blue(c)); 
       colorrgb[0] = String.valueOf(Color.red(c)); 
       colorrgb[1] = String.valueOf(Color.blue(c)); 
       colorrgb[2] = String.valueOf(Color.green(c)); 
       mListener.onColorChangeListener(colorrgb); 

      } 
     },2000); 

    } 
} 
関連する問題