Error during calling the fragment - android

Hi every one I have created a fragment class and included in my project.Now the problem is the classes which i have included fragment is not working and it get stops unfortunately.It shows error like this.
09-12 10:26:31.066 7892-7892/com.sentientit.theiWedplanner E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.sentientit.theiWedplanner, PID: 7892
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sentientit.theiWedplanner/com.sentientit.theiWedplanner.Frontpage}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5323)
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:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
at android.app.Activity.setContentView(Activity.java:1948)
at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
at android.app.Activity.performCreate(Activity.java:5343)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2323)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5323)
            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:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.sentientit.theiWedplanner.Fragadmob: make sure class name exists, is public, and has an empty constructor that is public
at android.app.Fragment.instantiate(Fragment.java:597)
at android.app.Fragment.instantiate(Fragment.java:561)
at android.app.Activity.onCreateView(Activity.java:4841)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
            at android.app.Activity.setContentView(Activity.java:1948)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5343)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2323)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5323)
            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:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sentientit.theiWedplanner.Fragadmob" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.sentientit.theiWedplanner-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.sentientit.theiWedplanner-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Fragment.instantiate(Fragment.java:583)
            at android.app.Fragment.instantiate(Fragment.java:561)
            at android.app.Activity.onCreateView(Activity.java:4841)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
            at android.app.Activity.setContentView(Activity.java:1948)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5343)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2323)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5323)
            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:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)
fragment xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adview153613"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/aagr_background2" >
<ImageView
android:id="#+id/addviewimage"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:src="#drawable/adview1536132" />
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="-------------"
/>
<ImageView
android:id="#+id/addviewimage1"
android:layout_width="#dimen/fwh"
android:layout_height="#dimen/fwh"
android:layout_alignParentRight="true"
android:layout_marginRight="23dp"
android:src="#drawable/close" />
</RelativeLayout>
fragment java file
package com.sentientit.theiWedplanner;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class Fragadmob extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragadmob, container, false);
//Admob
RelativeLayout gonad=(RelativeLayout)rootView.findViewById(R.id.adview153613);
ImageView addviewimage=(ImageView)rootView.findViewById(R.id.addviewimage);
ImageView inap=(ImageView)rootView.findViewById(R.id.addviewimage1);
// AdView adView = new AdView(getActivity());
AdView adView = (AdView)rootView.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);
addviewimage.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/developer?id=SentientIT+America,+LLC"));
startActivity(viewIntent);
}
});
inap.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(),Inapp.class);
startActivity(intent);
}
});
if(addviewimage.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
addviewimage.getLayoutParams().height = 30;
// code to do for Portrait Mode
}
return rootView;
}
}
gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.sentientit.theiWedplanner"
minSdkVersion 9
targetSdkVersion 21
versionCode 13
versionName "11.0"
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile 'joda-time:joda-time:2.4'
compile files('libs/bugsense-3.6.1.jar')
compile files('libs/core.jar')
compile files('libs/MtUtils.jar')
compile files('libs/socialauth-android-3.2.jar')
compile files('libs/universal-image-loader-1.6.1-with-src.jar')
compile files('libs/zxingjar-1.1.jar')
compile 'com.google.android.gms:play-services:7.5.0'
compile files('libs/ksoap2.jar')
compile 'com.android.support:multidex:1.0.1'
compile files('libs/twitter4j.jar')
}
Please give me the possible solution to solve it friends
Thank you in advance
error during validation of xml
Error:(8, 55) cvc-elt.1: Cannot find the declaration of element 'RelativeLayout'.
Error:(1, 56) s4s-elt-schema-ns: The namespace of element 'x' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
Error:(1, 56) s4s-elt-invalid: Element 'x' is not a valid element in a schema document.
Error:(1, 56) schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
class loads fragment file
package com.sentientit.theiWedplanner;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import com.bugsense.trace.BugSenseHandler;
import com.google.android.gms.ads.AdView;
public class Frontpage extends FragmentActivity {
/** Called when the activity is first created. */
SharedPreferences sharedPreferences;
#Override
public void onStart() {
super.onStart();
// The rest of your onStart() code.
// // EasyTracker.getInstance(this).activityStart(this); // Add this method.
}
#Override
public void onStop() {
super.onStop();
// The rest of your onStop() code.
// EasyTracker.getInstance(this).activityStop(this); // Add this method.
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); BugSenseHandler.initAndStartSession(this, "68640bea");
//requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.front);
// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.main1);
//TextView ctitle=(TextView)findViewById(R.id.customtitlebar);
//ctitle.setText("Resources");
AdView adview=(AdView)findViewById(R.id.ad);
if(GlobalClass.adm){
adview.setVisibility(View.GONE);
}
RelativeLayout clic =(RelativeLayout)findViewById(R.id.fron);
clic.setOnClickListener(new OnClickListener() {
//#Override
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent=new Intent(Frontpage.this,welcomeuser1.class);
//Intent intent=new Intent(Frontpage.this,ZXingJarDemoActivity.class);
startActivity(intent);
finish();
}
});
}
}

Watch out for this log message
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
You are having some problem with the xml view file . and most probably in line no 11 . you can try removing
xmlns:ads="http://schemas.android.com/apk/res-auto"
from adview.The namespace is declared in the root element .Also the fill_parent is depreciated . use match_parent

Related

Launching on 19 api gives an error res/drawable file missing

So I'm creating an app. And It gives me two following errors:
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp E/VdcInflateDelegate﹕ Exception while inflating <vector>
org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
at android.support.graphics.drawable.VectorDrawableCompat.updateStateFromTypedArray(VectorDrawableCompat.java:717)
at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:654)
at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:617)
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:745)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:365)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
at com.teamlukas.motivationapp.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp D/AndroidRuntime﹕ Shutting down VM
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d10e48)
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.teamlukas.motivationapp, PID: 9717
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.teamlukas.motivationapp/com.teamlukas.motivationapp.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
at android.content.res.Resources.loadDrawable(Resources.java:2136)
at android.content.res.Resources.getDrawable(Resources.java:715)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
at com.teamlukas.motivationapp.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            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:790)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2132)
            at android.content.res.Resources.getDrawable(Resources.java:715)
            at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
            at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
            at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
            at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
            at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
            at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
            at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
            at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
            at com.teamlukas.motivationapp.MainActivity.onCreate(MainActivity.java:15)
            at android.app.Activity.performCreate(Activity.java:5275)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            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:790)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
            at dalvik.system.NativeStart.main(Native Method)
It works on api 23, but when it's api 19, it gives me this crash. Any ideas to fix the error? I've never faced this error before so I don't know what to do. By the way, MainActivity code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Quote.class);
startActivity(intent);
}
});
Button settings = (Button) findViewById(R.id.button3);
settings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent setting = new Intent(getApplicationContext(), Settings.class);
startActivity(setting);
}
});
}
#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;
}
#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_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Gradle app module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "com.teamlukas.motivationapp"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:support-v4:25.0.0'
}
This shouldn't be a big issue to solve, try to do the following:
Method 1:
add the android:design in gradle
compile 'com.android.support:design:x.x.x.x'
replace the x.x.x.x with your available api tools.
Method 2:
Inside the activity that uses the vector add the following static code
static
{
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Method 3:
if you using gradle 1.5 use the following method
defaultConfig {
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
Method 4:
This method will work despite the gradle version you will be using
If targeting prelollipop devices use a selector directly from your imageview
1) app:srcCompat="#drawable/my_vector_drawable"
2) This will be the code for your selector :
name this: selector_my_vector_drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/my_vector_drawable" />
</selector>
3) The pass the selector
for TextView :
<TextView
android:gravity="center_vertical"
android:drawableLeft="#drawable/selector_my_vector_drawable"
android:drawableStart="#drawable/selector_my_vector_drawable"
android:drawableRight="#drawable/selector_my_vector_drawable"
android:drawableEnd="#drawable/selector_my_vector_drawable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/This will work" />
Method 5:
Learn about vectors here
Vectors
What is your min sdk. If you mentioned min sdk 20 that time it will crash. Ping me your min sdk with gradle file.

android.view.InflateException: Binary XML file line #2: Error inflating class andorid.support.v7.widget.Toolbar

Hi I trying material design thing but I got the above error. Here is my log cat:
Process: course.examples.healthcare_application, PID: 19653
java.lang.RuntimeException: Unable to start activity ComponentInfo{course.examples.healthcare_application/course.examples.healthcare_application.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class andorid.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class andorid.support.v7.widget.Toolbar
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:904)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at course.examples.healthcare_application.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5951)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.ClassNotFoundException: Didn't find class "andorid.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/data/app/course.examples.healthcare_application-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:578)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
            at android.view.LayoutInflater.parseInclude(LayoutInflater.java:904)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at course.examples.healthcare_application.MainActivity.onCreate(MainActivity.java:15)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5951)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Suppressed: java.lang.ClassNotFoundException: andorid.support.v7.widget.Toolbar
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 24 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<andorid.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#DDD">
</andorid.support.v7.widget.Toolbar>
acitivity_main.xml
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="course.examples.healthcare_application.MainActivity">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<TextView
android:layout_below="#+id/app_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
MainActivity
package course.examples.healthcare_application;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar= (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
}
#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;
}
#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_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Please help. I had looked at other posts but it doesn't solve my problem. And I am new to material design. Don't quite understand the error.
andorid.support.v7.widget.Toolbar
to
android.support.v7.widget.Toolbar
<?xml version="1.0" encoding="utf-8"?>
<andorid.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#DDD">
</andorid.support.v7.widget.Toolbar>
Misspelled android

Simple facebook login test app will not launch

I'm making an app that needs to login with facebook and then start maps. It crashes instantly on my phone with "has unfortunaly stopped working". It seems to be the facebook SDK widget button that I use for login, but I cant figure out how to fix it
09-15 22:06:32.890 10289-10289/com.example.nan.spymap E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.nan.spymap, PID: 10289
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nan.spymap/com.example.nan.spymap.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class com.facebook.login.widget.LoginButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.facebook.login.widget.LoginButton
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at android.app.Activity.setContentView(Activity.java:2145)
at com.example.nan.spymap.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
            at android.app.Activity.setContentView(Activity.java:2145)
            at com.example.nan.spymap.MainActivity.onCreate(MainActivity.java:28)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
at com.facebook.internal.Validate.sdkInitialized(Validate.java:136)
at com.facebook.AccessTokenTracker.<init>(AccessTokenTracker.java:55)
at com.facebook.login.widget.LoginButton$2.<init>(LoginButton.java:561)
at com.facebook.login.widget.LoginButton.configureButton(LoginButton.java:561)
at com.facebook.FacebookButtonBase.<init>(FacebookButtonBase.java:66)
at com.facebook.login.widget.LoginButton.<init>(LoginButton.java:200)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
            at android.app.Activity.setContentView(Activity.java:2145)
            at com.example.nan.spymap.MainActivity.onCreate(MainActivity.java:28)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
My manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nan.spymap" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />
</application>
</manifest>
My activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/info"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="18sp"
/>
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
My MainActivity.java
package com.example.nan.spymap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
public class MainActivity extends Activity {
private CallbackManager callbackManager;
private TextView info;
private LoginButton loginButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
info = (TextView)findViewById(R.id.info);
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
info.setText("User ID: " +
loginResult.getAccessToken().getUserId() + "\n" +
"Auth Token: " + loginResult.getAccessToken().getToken());
}
#Override
public void onCancel() {
info.setText("Login attempt cancelled.");
}
#Override
public void onError(FacebookException e) {
info.setText("Login attempt failed.");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
My gradle build
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.nan.spymap"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories { mavenCentral() }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
}
it says what's wrong in the stack trace:
Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
The initialization is done AFTER the layout xml is loaded (in setContentView() ).
Initialize the SDK before or in your Application class.

android.view.InflateException: Binary XML file line #24: Error inflating class fragment

I have an activity which has 2 buttons. The fragment in my activity would change on button click. But I am facing issue as -- android.view.InflateException: Binary XML file line #24: Error inflating class fragment .
Below is my code-
activity_main.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:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="selectFrag"
android:text="Select Fragment 1" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="selectFrag"
android:text="Select Fragment 2" />
<fragment
android:id="#+id/fragment_place"
android:name="com.example.rahul.fragmentdemo.FragmentOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragment_one" />
</LinearLayout>
MainActivity.java
package com.example.rahul.fragmentdemo;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void selectFrag(View view) {
Fragment fr = null;
if (view == findViewById(R.id.button2)) {
fr = new FragmentTwo();
} else {
fr = new FragmentOne();
}
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.fragment_place, fr);
fragmentTransaction.commit();
}
}
FragmentOne.java
package com.example.rahul.fragmentdemo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FragmentOne extends Fragment {
public FragmentOne() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
Log.i("Fragment Demo", "Fragment_One onCreate()");
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_one, container, false);
return view;
}
}
fragment_one.xml
<FrameLayout 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" tools:context="com.example.rahul.fragmentdemo.FragmentOne">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="#+id/tvFragment_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is Fragment 1" />
</FrameLayout>
similar to FragmentOne.java and fragment_two.xml, my code has FragmentTwo.java and fragment_two.xml respectively.
I get exception as--
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rahul.fragmentdemo/com.example.rahul.fragmentdemo.MainActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2144)
at com.example.rahul.fragmentdemo.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.support.v4.app.SuperNotCalledException: Fragment FragmentOne{3fdec5ae #0 id=0x7f0c0051} did not call through to super.onCreate()
at android.support.v4.app.Fragment.performCreate(Fragment.java:1768)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:917)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
            at android.app.Activity.setContentView(Activity.java:2144)
            at com.example.rahul.fragmentdemo.MainActivity.onCreate(MainActivity.java:18)
            at android.app.Activity.performCreate(Activity.java:5937)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
-- where MainActivity.java:18 refers to
setContentView(R.layout.activity_main);
As the error log says, there is missing super.onCreate in FragmentOne.java:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("Fragment Demo", "Fragment_One onCreate()");
}

Error inflating class RecyclerView

So my code simply makes a list of CardViews using RecyclerView. Upon running my code i kept getting a weird error claiming there was an error in my xml. After tinkering for a while i found out that in my layout file if i change <RecyclerView> to <android.support.v7.widget.RecyclerView> everything would work just fine. Why is this happening? My activity.
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import java.util.ArrayList;
public class CardListActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_list);
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.cardList);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
ArrayList<String> list = new ArrayList<>();
for(int i = 0; i < 20; i++) {list.add("Item " + i);}
CardListAdapter cardListAdapter = new CardListAdapter(list);
recyclerView.setAdapter(cardListAdapter);
}
}
My Adapter
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
public class CardListAdapter extends RecyclerView.Adapter<CardListAdapter.CardListViewHolder> {
private List<String> list;
public CardListAdapter(List<String> list) {
this.list = list;
}
#Override
public CardListViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_layout,viewGroup,false);
return new CardListViewHolder(v);
}
#Override
public void onBindViewHolder(CardListViewHolder cardListViewHolder, int i) {
String s = list.get(i);
cardListViewHolder.title.setText(s);
}
#Override
public int getItemCount() {
return list.size();
}
public static class CardListViewHolder extends RecyclerView.ViewHolder {
TextView title;
public CardListViewHolder(View itemView) {
super(itemView);
title = (TextView)itemView.findViewById(R.id.title);
}
}
}
My layout file, note, changing <RecyclerView> to <android.support.v7.widget.RecyclerView> fixes the error.
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".CardListActivity">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/cardList">
</RecyclerView>
When i run with <RecyclerView> i get this error, .
`Process: com.liquidink.lollipopmaterialui, PID: 7317
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liquidink.lollipopmaterialui/com.liquidink.lollipopmaterialui.CardListActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class RecyclerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class RecyclerView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.liquidink.lollipopmaterialui.CardListActivity.onCreate(CardListActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.RecyclerView" on path: DexPathList[[zip file "/data/app/com.liquidink.lollipopmaterialui-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:665)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:65)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.liquidink.lollipopmaterialui.CardListActivity.onCreate(CardListActivity.java:18)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Suppressed: java.lang.ClassNotFoundException: android.view.RecyclerView
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 26 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
`
You should add the RecyclerView in the XML in this way:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/cardList">
</android.support.v7.widget.RecyclerView>
Hope it helps!
RecyclerView is not included in base Android framework, only widgets in base Android framework (like ListView, GridView etc) can be specified in layout without full namespace. RecyclerView is part of recyclerview-v7 support library.
I meet this problem today.
And solved it.
first step:keep the support-libs you used are same version
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
second step:you should add recyclerView to your proguard files
-keep class android.support.v7.widget.** {*;}
// I`ve just keep all widgets
Make sure to include before you add RecyclerView to your XML
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
If you created RecyclerView in your XML before adding these dependencies, to make it work you should remove (comment) your recycler view, build project without it and then add it back. Otherwise it still shows Inflate exception in binary XML line #n.
Check reference in build.gradle
In your layout xml file be, write your RecyclerView component's name as a whole with its package like that android.support.v7.widget.RecyclerViewnot like RecyclerView
now ready to lunch. Good trails

Categories

Resources