2017-03-20 4 views
0

항목을 누르면 조각을 실행하려고하는데 응용 프로그램이 충돌합니다.항목에서 프래그먼트를 시작할 수 없습니다.

활동 자바 :

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.RelativeLayout; 
import android.widget.FrameLayout; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentTransaction; 


public class AccountActivity extends AppCompatActivity { 

    private String carrierName; 


    private RelativeLayout lcb; 
    private RelativeLayout layoutBalanceLoad; 
    private RelativeLayout layoutCreditShare; 
    private RelativeLayout layoutCreditBarrow; 
    private FrameLayout dashboardProgressBar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_account); 


     lcb = (RelativeLayout) findViewById(R.id.layout_balance_check); 
     layoutBalanceLoad = (RelativeLayout) findViewById(R.id.layout_balance_load); 
     layoutCreditShare = (RelativeLayout) findViewById(R.id.layout_credit_share); 
     layoutCreditBarrow = (RelativeLayout) findViewById(R.id.layout_credit_barrow); 
     dashboardProgressBar = (FrameLayout) findViewById(R.id.dashboard_progress_bar); 


    } 

    public void checkBalance(View view) { 

      Fragment fragment = new CheckBalance(); 
      FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
      transaction.replace(R.id.fragment_container, fragment).commitAllowingStateLoss(); 


    } 
} 

활동 XML :

<?xml version="1.0" encoding="utf-8" ?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@id/layout_dashboard_parent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ScrollView 
     android:id="@id/main_scroll_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <LinearLayout 
      android:orientation="vertical" 
      android:id="@id/layout_dashboard_scroll_container" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <FrameLayout 
       android:id="@id/dashboard_alert_section" 
       android:visibility="gone" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <include layout="@layout/dashboard_feature_tip_item" /> 
      </FrameLayout> 

      <LinearLayout 
       android:id="@id/main_control_layout" 
       android:layout_width="fill_parent" 
       android:layout_height="611dp"> 

       <LinearLayout 
        android:id="@id/layout_main" 
        style="@style/CardView.Dark" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/c_dashboard_btn_quick_clean_color" 
        android:gravity="bottom" 
        android:orientation="vertical"> 

        <RelativeLayout 
         android:id="@+id/layout_balance_check" 
         android:layout_width="fill_parent" 
         android:layout_height="@dimen/dashboard_feature_layout_height_usa" 
         android:layout_marginBottom="6.0dip" 
         android:layout_marginEnd="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginLeft="@dimen/dashboard_feature_start_margin_usa" 
         android:layout_marginRight="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginStart="@dimen/dashboard_feature_start_margin_usa" 
         android:layout_marginTop="@dimen/dashboard_feature_top_margin_usa" 
         android:layout_weight="1.0" 
         android:background="@color/battery_charging_icon_color" 
         android:elevation="@dimen/dashboard_feature_bg_elevation" 
         android:onClick="checkBalance" 
         android:theme="@style/Base.Theme.AppCompat" 
         tools:targetApi="lollipop"> 

         <include layout="@layout/sub_layout_account_cb" /> 

        </RelativeLayout> 

        <RelativeLayout 
         android:id="@+id/layout_balance_load" 
         android:layout_width="fill_parent" 
         android:layout_height="@dimen/dashboard_feature_layout_height_usa" 
         android:layout_marginBottom="6.0dip" 
         android:layout_marginEnd="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginLeft="@dimen/dashboard_feature_start_margin_usa" 
         android:layout_marginRight="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginStart="@dimen/dashboard_feature_start_margin_usa" 
         android:layout_weight="1.0" 
         android:background="@color/white" 
         android:clickable="true" 
         android:elevation="@dimen/dashboard_feature_bg_elevation" 
         android:focusable="true" 
         tools:targetApi="lollipop"> 

         <include layout="@layout/sub_layout_account_lb" /> 

         <View 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" 
          android:background="?android:selectableItemBackground" 
          android:duplicateParentState="true" /> 
        </RelativeLayout> 

        <RelativeLayout 
         android:id="@+id/layout_credit_share" 
         android:layout_width="fill_parent" 
         android:layout_height="@dimen/dashboard_feature_layout_height_usa" 
         android:layout_marginBottom="6.0dip" 
         android:layout_marginEnd="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginLeft="@dimen/dashboard_feature_start_margin_usa" 
         android:layout_marginRight="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginStart="@dimen/dashboard_feature_start_margin_usa" 
         android:layout_weight="1.0" 
         android:background="@color/white" 
         android:clickable="true" 
         android:elevation="@dimen/dashboard_feature_bg_elevation" 
         android:focusable="true" 
         tools:targetApi="lollipop"> 

         <include layout="@layout/sub_layout_account_sc" /> 

         <View 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" 
          android:background="?android:selectableItemBackground" 
          android:duplicateParentState="true" /> 
        </RelativeLayout> 

        <RelativeLayout 
         android:id="@+id/layout_credit_barrow" 
         android:layout_width="fill_parent" 
         android:layout_height="@dimen/dashboard_feature_layout_height_usa" 
         android:layout_marginBottom="6.0dip" 
         android:layout_marginEnd="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginLeft="@dimen/dashboard_feature_start_margin_usa" 
         android:layout_marginRight="@dimen/dashboard_feature_end_margin_usa" 
         android:layout_marginStart="@dimen/dashboard_feature_start_margin_usa" 
         android:background="@color/white" 
         android:clickable="true" 
         android:elevation="@dimen/dashboard_feature_bg_elevation" 
         android:focusable="true" 
         android:visibility="visible" 
         tools:targetApi="lollipop"> 

         <include layout="@layout/sub_layout_account_bc" /> 

         <View 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" 
          android:background="?android:selectableItemBackground" 
          android:duplicateParentState="true" /> 
        </RelativeLayout> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="10dip" 
     android:layout_gravity="bottom" 
     android:elevation="5dp" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     tools:targetApi="lollipop" /> 

    <FrameLayout 
     android:id="@+id/fragment_container" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

    </FrameLayout> 


</RelativeLayout> 

조각 자바 :

import android.support.v4.app.Fragment; 
import android.view.View; 
import android.view.LayoutInflater; 
import android.view.ViewGroup; 
import android.os.Bundle; 
import android.widget.LinearLayout; 
import android.support.constraint.ConstraintLayout; 
import android.widget.TextView; 
import android.widget.Button; 

public class CheckBalance extends Fragment implements View.OnClickListener { 

    private LinearLayout africellCbInt; 
    private ConstraintLayout africellCbBalanceWrapper; 
    private TextView africellCbDialogMsg; 
    private TextView textView; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     return inflater.inflate(R.layout.custom_africell_cb, null); 
    } 

    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 

     africellCbInt = (LinearLayout) view.findViewById(R.id.africell_cb_int); 
     africellCbDialogMsg = (TextView) view.findViewById(R.id.africell_cb_dialog_msg); 
     view.findViewById(R.id.button_africell_cb_1).setOnClickListener(this); 
     textView = (TextView) view.findViewById(R.id.textView); 
     view.findViewById(R.id.button_africell_cb_2).setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View view) { 
     switch (view.getId()) { 
      case R.id.button_africell_cb_1: 
       //bla bla bla 
       break; 
      case R.id.button_africell_cb_2: 
       //bla bla bla 
       break; 
     } 
    } 
} 

조각의 XML :

내 코드입니다
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/africell_cb_int" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/c_main_back_ground_color" 
    android:orientation="vertical" 
    android:padding="10.0dip" 
    android:weightSum="1.0"> 


    <LinearLayout 
     android:layout_width="344dp" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/africell_cb_dialog_msg" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top|center" 
      android:layout_marginBottom="50dp" 
      android:layout_marginEnd="8dp" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="1" 
      android:gravity="top|center" 
      android:text="@string/africell_cb_dialog_msg" 
      android:textAppearance="@style/TextAppearance.AppCompat.Display1" 
      android:textSize="18sp" 
      android:textStyle="bold" 
      app:layout_constraintBottom_toTopOf="@+id/button_africell_cb_1" 
      app:layout_constraintHorizontal_bias="0.507" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent" 
      app:layout_constraintVertical_bias="0.486" /> 
    </LinearLayout> 

    <Button 
     android:id="@+id/button_africell_cb_1" 
     style="@style/Widget.AppCompat.Button.Borderless.Colored" 
     android:layout_width="328dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:background="@color/c_dashboard_btn_quick_clean_color" 
     android:elevation="6dp" 
     android:onClick="mainBalance" 
     android:text="@string/africell_cb_1" 
     android:textColor="@color/action_button_color" 
     android:visibility="visible" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     tools:layout_editor_absoluteY="39dp" 
     tools:targetApi="lollipop" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="5dip" 
     android:layout_marginBottom="2dip" 
     android:layout_marginTop="2dip" 
     android:background="@color/white" 
     android:text="TextView" 
     tools:ignore="HardcodedText" /> 

    <Button 
     android:id="@+id/button_africell_cb_2" 
     style="@style/Widget.AppCompat.Button.Borderless.Colored" 
     android:layout_width="327dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:background="@color/c_dashboard_btn_quick_clean_color" 
     android:elevation="9dp" 
     android:text="@string/africell_cb_2" 
     android:textColor="@color/action_button_color" 
     android:visibility="visible" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     tools:targetApi="lollipop" /> 


</LinearLayout> 

제발, 누군가 잘못된 정보를 말해 줄 수 있습니까? 나는 뭔가를 놓치고 있지만 알아 내지 못한다는 것을 알고있다.

편집 : 로그 캣 :

03-20 23:41:40.768 17618-17618/com.esqmo.apps.mosungiplus E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: com.esqmo.apps.mosungiplus, PID: 17618 
                      java.lang.IllegalArgumentException: Expected receiver of type com.esqmo.apps.mosungiplus.AccountActivity, but got android.view.ContextThemeWrapper 
                       at java.lang.reflect.Method.invoke(Native Method) 
                       at android.view.View$DeclaredOnClickListener.onClick(View.java:4735) 
                       at android.view.View.performClick(View.java:5697) 
                       at android.view.View$PerformClick.run(View.java:22526) 
                       at android.os.Handler.handleCallback(Handler.java:739) 
                       at android.os.Handler.dispatchMessage(Handler.java:95) 
                       at android.os.Looper.loop(Looper.java:158) 
                       at android.app.ActivityThread.main(ActivityThread.java:7224) 
                       at java.lang.reflect.Method.invoke(Native Method) 
                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
03-20 23:41:40.798 855-17790/? E/android.os.Debug: ro.product_ship = true 
03-20 23:41:40.798 855-17790/? E/android.os.Debug: ro.debug_level = 0x4f4c 
03-20 23:41:40.798 855-17790/? E/android.os.Debug: sys.mobilecare.preload = false 
03-20 23:41:52.718 855-1676/? E/LocSvc_ApiV02: I/<--- void globalRespCb(locClientHandleType, uint32_t, locClientRespIndUnionType, void*) line 131 QMI_LOC_INJECT_POSITION_REQ_V02 
03-20 23:41:55.648 327-1200/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'LABEL' not found 
03-20 23:41:55.648 327-1200/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'TIME_NS' not found 
03-20 23:41:55.648 327-1200/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'UID' not found 
03-20 23:41:55.958 1549-1590/? E/ContactsProvider_EventLog: Flush buffer to file cnt : 10 size : 4Kb duration : 203ms lastUpdatedAfter : 180640ms 
03-20 23:42:04.158 855-1597/? E/Watchdog: [email protected] 2468 [03-20 23:42:04.161] 
03-20 23:42:23.948 327-1200/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'LABEL' not found 
03-20 23:42:23.948 327-1200/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'TIME_NS' not found 
03-20 23:42:23.948 327-1200/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'UID' not found 
03-20 23:42:32.398 18642-18642/? E/Zygote: v2 
03-20 23:42:32.408 18642-18642/? E/Zygote: accessInfo : 0 
03-20 23:42:34.158 855-1597/? E/Watchdog: [email protected] 2469 [03-20 23:42:34.163] 

이 오류가 정확히 무엇입니까? 처음에는

, XML 코드에서android:onClick="checkBalance"을 제거

java.lang.IllegalArgumentException: Expected receiver of type com.esqmo.apps.mosungiplus.AccountActivity, but got android.view.ContextThemeWrapper at java.lang.reflect.Method.invoke(Native Method) at android.view.View$DeclaredOnClickListener.onClick(View.java:4735) 
+0

당신이 직면하고있는 어떤 오류? 친절하게 logcat를 추가하십시오. – tahsinRupam

+0

@ tahsinRupam 수정 사항을 확인해 주셔서 감사합니다. –

+0

xml에서 click 이벤트를 정의하는 대신'setOnClickListener()'메소드를 사용하여 java에서 시도하십시오. 참조 [this] (http://stackoverflow.com/questions/32088184/run-android-app-error-fatal-exception-main-process-pid-14099) –

답변

1

당신의 RelativeLayoutin onCreate이 시간에 onClicklistener을 설정하십시오. 그런 다음 다음과 같이 수행으로

Fragment fragment = new CheckBalance(); 
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
transaction.replace(R.id.fragment_container, fragment).commitAllowingStateLoss(); 

:

FragmentManager fm; 

다음, 은 당신의 코드를 아래 교체 :

lcb.setOnClickListener(new View.OnClickListener(){   
      @Override 
      public void onClick(View view) { 
       Fragment fragment = new CheckBalance(); 
       FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
       transaction.replace(R.id.fragment_container, fragment).commitAllowingStateLoss(); 
      }     
     }); 

먼저 전 세계적으로 FragmentManager를 선언, 다시 버튼을 눌러에서 조각을 제거하려면 이 :

Fragment fragment = new CheckBalance(); 
fm = getSupportFragmentManager(); 
FragmentTransaction ft = fm.beginTransaction(); 
ft.addToBackStack("Your Fragment Tag"); 
ft.add(R.id.fragment_container, fragment); 
ft.commit(); 

마지막으로, 무시 활동에 onBackPressed()은 :

@Override 
public void onBackPressed() { 
    if (fm.getBackStackEntryCount() > 0) 
     fm.popBackStackImmediate(); 
    else super.onBackPressed(); 
} 
+0

항상 동일합니다. 프래그먼트가 시작되지 않습니다. –

+0

xml에서 android : onClick = "checkBalance"를 제거 했습니까? – tahsinRupam

+0

그래도 오류가 남아있다. –

관련 문제