私は電子商取引のWebサイトを作ったため、購入時にエラーが発生しました。では、ボタンとそのオープン・フラグメントをクリックすると、その解決策は何でしょうか。エラーが発生し、ワンクリックボタンからフラグメントを開くときにアプリケーションがクラッシュする
ItemDetails.java(これは、今すぐ購入し、ここでのコードで、私はまた、いくつかの断片コードを実装するが、その正常に動作しない)
public class ItemDetailsActivity extends AppCompatActivity {
int imagePosition;
String stringImageUri;
public static int notificationCountCart = 0;
TextView textViewshare, textViewmap;
private Fragment fragment;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
//Show cart layout based on items
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Get the notifications MenuItem and
// its LayerDrawable (layer-list)
MenuItem item = menu.findItem(R.id.action_cart);
NotificationCountSetClass.setAddToCart(ItemDetailsActivity.this, item, notificationCountCart);
// force the ActionBar to relayout its MenuItems.
// onCreateOptionsMenu(Menu) will be called again.
invalidateOptionsMenu();
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
startActivity(new Intent(ItemDetailsActivity.this, SearchResultActivity.class));
return true;
}else if (id == R.id.action_cart) {
/* NotificationCountSetClass.setAddToCart(MainActivity.this, item, notificationCount);
invalidateOptionsMenu();*/
startActivity(new Intent(ItemDetailsActivity.this, CartListActivity.class));
/* notificationCount=0;//clear notification count
invalidateOptionsMenu();*/
return true;
}else {
startActivity(new Intent(ItemDetailsActivity.this, EmptyActivity.class));
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_details);
SimpleDraweeView mImageView = (SimpleDraweeView)findViewById(R.id.image1);
TextView textViewAddToCart = (TextView)findViewById(R.id.text_action_bottom1);
TextView textViewBuyNow = (TextView)findViewById(R.id.text_action_bottom2);
textViewshare = (TextView) findViewById(R.id.text_action1);
textViewmap = (TextView) findViewById(R.id.text_action3);
TextView textViewBuyNowwithpayment = (TextView) findViewById(R.id.text_action_bottom2);
//Getting image uri from previous screen
if (getIntent() != null) {
stringImageUri = getIntent().getStringExtra(ImageListFragment.STRING_IMAGE_URI);
imagePosition = getIntent().getIntExtra(ImageListFragment.STRING_IMAGE_URI,0);
}
Uri uri = Uri.parse(stringImageUri);
mImageView.setImageURI(uri);
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ItemDetailsActivity.this, ViewPagerActivity.class);
intent.putExtra("position", imagePosition);
startActivity(intent);
}
});
textViewAddToCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ImageUrlUtils imageUrlUtils = new ImageUrlUtils();
imageUrlUtils.addCartListImageUri(stringImageUri);
Toast.makeText(ItemDetailsActivity.this, "Item added to cart.", Toast.LENGTH_SHORT).show();
MainActivity.notificationCountCart++;
NotificationCountSetClass.setNotifyCount(MainActivity.notificationCountCart);
}
});
textViewBuyNow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ImageUrlUtils imageUrlUtils = new ImageUrlUtils();
imageUrlUtils.addCartListImageUri(stringImageUri);
MainActivity.notificationCountCart++;
NotificationCountSetClass.setNotifyCount(MainActivity.notificationCountCart);
startActivity(new Intent(ItemDetailsActivity.this, CartListActivity.class));
}
});
// payment.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent i = new Intent(ItemDetailsActivity.this, PayPalCheckoutActivity.class);
// startActivity(i);
// }
// });
textViewBuyNowwithpayment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Fragment fragment = new PayPalCheckoutActivity();
// FragmentTransaction transaction = getFragmentManager().beginTransaction();
// transaction.replace(R.id.fragment_container,fragment);
// transaction.addToBackStack(null); // this will manage backstack
// transaction.commit();
FragmentManager fm = getSupportFragmentManager();
PayPalCheckoutActivity fragment = new PayPalCheckoutActivity();
fm.beginTransaction().replace(R.id.fragment_container,fragment).commit();
}
});
PaypalActivity.java支払いの統合がする(これは、javaファイルであります開始しかし、私のアプリは今、購入ボタンをクリックした後にクラッシュを取得)
public class PayPalCheckoutActivity extends Fragment implements View.OnClickListener {
private TextView textMessage = null;
private CitrusClient citrusClient = null;
private Button btnSignout = null;
private Button btnUserManagement = null;
private Button btnWalletPayment = null;
public boolean isUserLoggedIn = false;
public PayPalCheckoutActivity() {
}
public static PayPalCheckoutActivity newInstance() {
return new PayPalCheckoutActivity();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_ui, container, false);
textMessage = (TextView) rootView.findViewById(R.id.txt_message);
btnUserManagement = (Button) rootView.findViewById(R.id.btn_user_management);
btnWalletPayment = (Button) rootView.findViewById(R.id.btn_user_wallet);
btnSignout = (Button) rootView.findViewById(R.id.btn_logout);
btnSignout.setOnClickListener(this);
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
citrusClient = CitrusClient.getInstance(getActivity().getApplicationContext());
}
@Override
public void onClick(View v) {
citrusClient.signOut(new Callback<CitrusResponse>() {
@Override
public void success(CitrusResponse citrusResponse) {
((UIActivity) getActivity()).showSnackBar(citrusResponse.getMessage());
textMessage.setText("Please Sign In or Sign Up the user.");
btnSignout.setVisibility(View.GONE);
btnUserManagement.setVisibility(View.VISIBLE);
btnWalletPayment.setVisibility(View.GONE);
}
@Override
public void error(CitrusError error) {
((UIActivity) getActivity()).showSnackBar(error.getMessage());
}
});
}
@Override
public void onResume() {
super.onResume();
checkUserLogin();
}
void checkUserLogin() {
citrusClient.isUserSignedIn(new Callback<Boolean>() {
@Override
public void success(Boolean isUserLoggedIn) {
PayPalCheckoutActivity.this.isUserLoggedIn = isUserLoggedIn;
if (isUserLoggedIn) {
citrusClient.getProfileInfo(new Callback<CitrusUser>() {
@Override
public void success(CitrusUser citrusUser) {
textMessage.setText("Welcome " + citrusUser.getEmailId());
btnWalletPayment.setVisibility(View.VISIBLE);
btnUserManagement.setVisibility(View.GONE);
btnSignout.setVisibility(View.VISIBLE);
}
@Override
public void error(CitrusError error) {
textMessage.setText("Welcome Back");
btnWalletPayment.setVisibility(View.VISIBLE);
btnUserManagement.setVisibility(View.GONE);
btnSignout.setVisibility(View.VISIBLE);
}
});
} else {
textMessage.setText("Please Sign In or Sign Up the user.");
btnWalletPayment.setVisibility(View.GONE);
btnUserManagement.setVisibility(View.VISIBLE);
btnSignout.setVisibility(View.GONE);
}
}
@Override
public void error(CitrusError error) {
textMessage.setText(error.getMessage());
}
});
}
}
エラー
FATAL EXCEPTION: main
Process: com.allandroidprojects.ecomsample, PID: 6112
java.lang.IllegalArgumentException: No view found for id 0x7f0e0143 (com.allandroidprojects.ecomsample:id/fragment_container) for fragment PayPalCheckoutActivity{a633c04 #0 id=0x7f0e0143}
しますあなたが/置き換える使用
FrameLayout
その時間なしの断片を追加しようとする
fragment_ui.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"
android:orientation="vertical"
android:paddingBottom="@dimen/citrus_activity_vertical_margin"
android:paddingLeft="@dimen/citrus_activity_horizontal_margin"
android:background="@color/white"
android:paddingRight="@dimen/citrus_activity_horizontal_margin"
android:paddingTop="@dimen/citrus_activity_vertical_margin">
<TextView
android:id="@+id/txt_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/button_margin"
android:text="Please Sign In or Sign Up the user." />
<Button
android:id="@+id/btn_user_management"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/button_margin"
android:onClick="onUserManagementClicked"
android:text="User Management" />
<Button
android:id="@+id/btn_user_wallet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/button_margin"
android:onClick="onWalletPaymentClicked"
android:text="Wallet Payment"
android:visibility="gone" />
<Button
android:id="@+id/btn_logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/button_margin"
android:text="Logout" />
</LinearLayout>
activity_item_details.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/activity_item_details"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context="com.codeexpertise.eshop.product.ItemDetailsActivity">
<ScrollView android:id="@+id/scrollbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9.5"
android:scrollbars="none"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="200.0dp"
fresco:placeholderImage="@color/stay_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Denim Shirt"
android:textSize="16dp"
android:textColor="@color/gen_black"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Rs. 1,979"
android:textSize="20dp"
android:textColor="@color/gen_black"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FREE Delivery"
android:textSize="12dp"
android:layout_marginTop="4dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp">
<TextView android:id="@+id/text_ratings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/green_light"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="4.3 *"
android:textSize="12dp"
android:textColor="@color/gen_white"
android:textStyle="bold"/>
<TextView android:id="@+id/text_ratings_reviews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:text="50 ratings \u0026 15 reviews"
android:textSize="12dp"/>
</LinearLayout>/
<View android:layout_width="match_parent"
android:layout_height="@dimen/view_width_small"
android:background="@color/grey_light"
android:layout_marginTop="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:weightSum="3">
<LinearLayout android:id="@+id/layout_action1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_share_black_18dp"/>
<TextView android:id="@+id/text_action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:text="Share"
android:showAsAction="ifRoom"
android:textSize="12dp"
android:textColor="@color/gen_black"
android:gravity="left"
android:actionProviderClass=
"android.widget.ShareActionProvider"/>
</LinearLayout>
<View android:layout_width="@dimen/view_width_small"
android:layout_height="match_parent"
android:background="@color/grey_light"/>
<LinearLayout android:id="@+id/layout_action2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_filter_none_black_18dp"/>
<TextView android:id="@+id/text_action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:text="Similar"
android:textSize="12dp"
android:textColor="@color/gen_black"
android:gravity="left"/>
</LinearLayout>
<View android:layout_width="@dimen/view_width_small"
android:layout_height="match_parent"
android:background="@color/grey_light"/>
<LinearLayout android:id="@+id/layout_action3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_favorite_border_black_18dp"/>
<TextView android:id="@+id/text_action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_marginLeft="8dp"
android:text="Store Locator"
android:textSize="12dp"
android:textColor="@color/gen_black"
android:gravity="left"/>
</LinearLayout>
</LinearLayout>
<View android:layout_width="match_parent"
android:layout_height="@dimen/view_width_small"
android:background="@color/grey_light"
android:layout_marginTop="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details"
android:textSize="16dp"
android:textColor="@color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Regular fit, full sleeve"
android:textSize="12dp"
android:textColor="@color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Fabric: Cotton"
android:textSize="12dp"
android:textColor="@color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Pattern: printed"
android:textSize="12dp"
android:textColor="@color/gen_black"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="horizontal"
android:weightSum="2"
android:elevation="30dp"
android:background="@color/gen_black">
<TextView android:id="@+id/text_action_bottom1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/gen_white"
android:text="ADD TO CART"
android:textSize="14dp"
android:textColor="@color/gen_black"
android:textStyle="bold"
android:gravity="center"/>
<TextView android:id="@+id/text_action_bottom2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#4dc3ff"
android:text="BUY NOW"
android:textSize="14dp"
android:textColor="@color/gen_white"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
ここに「activity_item_details.xml」という単語を追加してください – Raja