I have an ImageView
in my Fragment
, on which am setting an onClick Listener
.
public class TutorialFragment extends Fragment {
private TutorialAdapter tutorialAdapter;
private TutorialFragment tutorialFragment;
private SplashActivity splashActivity;
private RelativeLayout firstPageRelativeLayout,secondPageRelativeLayout,thirdPageRelativeLayout;
private ImageView backgroundImageView,facebookLoginButton,dekkohLogoImageView;
private ProgressDialogHandler progressDialogHandler;
private AlertDialogHandler alertDialogHandler;
private TextView firstPageTextView,secondPageTextView,thirdPageTextView,facebookPrivacyText,facebookDescriptionText;
@Override
public View onCreateView(LayoutInflater layoutInflater,ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(layoutInflater,container,savedInstanceState);
tutorialFragment=this;
splashActivity = (SplashActivity) getActivity();
View v = layoutInflater.inflate(R.layout.tutorial_fragment,container,false);
firstPageRelativeLayout = (RelativeLayout) v.findViewById(R.id.firstScreenRelativeLayout);
secondPageRelativeLayout = (RelativeLayout) v.findViewById(R.id.secondScreenRelativeLayout);
thirdPageRelativeLayout = (RelativeLayout) v.findViewById(R.id.thirdScreenRelativeLayout);
backgroundImageView = (ImageView) v.findViewById(R.id.tutorialImageView);
facebookLoginButton = (ImageView) v.findViewById(R.id.facebook_login_button);
dekkohLogoImageView = (ImageView) v.findViewById(R.id.dekkohLogoImage);
firstPageTextView = (TextView) v.findViewById(R.id.firstPageTextView);
secondPageTextView = (TextView) v.findViewById(R.id.secondPageTextView);
thirdPageTextView = (TextView) v.findViewById(R.id.thirdPageTextView);
facebookPrivacyText = (TextView) v.findViewById(R.id.facebookPrivacyText);
facebookDescriptionText = (TextView) v.findViewById(R.id.facebookDescriptionText);
int currentIndex = (int) this.getArguments().getSerializable("tutorial");
switch (currentIndex){
case 0:
firstPageRelativeLayout.setVisibility(View.VISIBLE);
secondPageRelativeLayout.setVisibility(View.GONE);
thirdPageRelativeLayout.setVisibility(View.GONE);
Picasso.with(splashActivity).load(R.drawable.tutorial_1).priority(Picasso.Priority.HIGH).fit().into(backgroundImageView);
Picasso.with(splashActivity).load(R.drawable.dekkoh_logo_tutorial).priority(Picasso.Priority.HIGH).fit().into(dekkohLogoImageView);
break;
case 1:
firstPageRelativeLayout.setVisibility(View.GONE);
secondPageRelativeLayout.setVisibility(View.VISIBLE);
thirdPageRelativeLayout.setVisibility(View.GONE);
Picasso.with(splashActivity).load(R.drawable.tutorial_2).priority(Picasso.Priority.HIGH).fit().into(backgroundImageView);
break;
case 2:
firstPageRelativeLayout.setVisibility(View.GONE);
secondPageRelativeLayout.setVisibility(View.GONE);
thirdPageRelativeLayout.setVisibility(View.VISIBLE);
Picasso.with(splashActivity).load(R.drawable.tutorial_3).priority(Picasso.Priority.HIGH).fit().into(backgroundImageView);
Picasso.with(splashActivity).load(R.drawable.fb_login_btn).fit().into(facebookLoginButton);
break;
}
final ArrayList<String> permissions = new ArrayList<String>();
progressDialogHandler = ProgressDialogHandler.getInstance();
alertDialogHandler = AlertDialogHandler.getInstance();
facebookLoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// setting facebook permission
permissions.add("email");
// permissions.add("user_location");
permissions.add("user_friends");
progressDialogHandler.showCustomProgressDialog(splashActivity);
final JSONObject jb = new JSONObject();
Session.openActiveSession(splashActivity, true,
permissions, new Session.StatusCallback() {
@SuppressWarnings("deprecation")
@Override
public void call(final Session session,
SessionState state, Exception exception) {
if (session.isOpened()) {
Request.executeMeRequestAsync(
session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(
GraphUser user,
Response response) {
if (user != null) {
String emaila = user
.asMap()
.get("email")
.toString();
String userId = user
.getId();
String name1 = user
.getName();
try {
jb.put("provider",
"Facebook");
jb.put("user_id",
userId.toString());
String token = session
.getAccessToken()
.toString();
jb.put("token",
token);
Log.d("f b login ",
jb.toString());
// clear seesion
// details and
// close
session.closeAndClearTokenInformation();
new LoginTheUser(
token,
user.getId())
.execute();
} catch (JSONException e) {
// Toast.makeText(getApplicationContext(),
// e.getLocalizedMessage(),
// Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
} else {
progressDialogHandler
.dismissCustomProgressDialog(splashActivity);
alertDialogHandler
.showToast(
splashActivity,
"Facebook Login Failed!");
}
}
});
} else {
}
}
});
}
});
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(),"fonts/SortsMillGoudy-Regular.ttf");
firstPageTextView.setTypeface(typeface);
secondPageTextView.setTypeface(typeface);
thirdPageTextView.setTypeface(typeface);
facebookDescriptionText.setTypeface(typeface);
facebookPrivacyText.setTypeface(typeface);
return v;
}
This is running fine on Nexus, oneplus but I get the following error on some devices.
java.lang.NoClassDefFoundError: com.myapp.fragments.TutorialFragment$1
at com.myapp.fragments.TutorialFragment.onCreateView(TutorialFragment.java:135)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
The $1 signifies an Inner class, which is the onclicklistener
. If I comment out the onclicklistener
code, the Activity and the Fragment
launch fine. Why is this? What is the issue?
It seems that your app reach the limitation of 65K methods, which is quite famous limitation of Android.
Ref: https://developer.android.com/tools/building/multidex.html#dev-build
You can follow the solution in above link. Or in short:
If you have your Application class (you extends class Application), override attachBaseContext() in that class and call Multidex.install(this)
otherwise add this to your Manifest:
android:name="android.support.multidex.MultiDexApplication"
inside <application>
tag.
Please reply here if it solves your problem. It solves mine actually.