java - Issue when compiling android application -


good evening. taking course in android , having issues compiling app.

i following this tutorial. have earlier set requestqueue requests.

this mainactivity.java file:

package com.ticketapp.emailaddresss.ticketapp;  import android.content.intent; import android.net.uri; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.button; import android.widget.textview;  import com.android.volley.request; import com.android.volley.requestqueue; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.toolbox.stringrequest; import com.facebook.accesstoken;  import com.facebook.graphrequest; import com.facebook.graphresponse; import com.facebook.httpmethod; import com.facebook.login.loginmanager; import com.facebook.share.model.sharehashtag; import com.facebook.share.model.sharelinkcontent; import com.facebook.share.widget.sharedialog;  import java.util.arraylist; import java.util.list;  public class mainactivity extends appcompatactivity {      button button;     textview textview;     string server_url = "https://www.idg.se/";     requestqueue requestqueue;      private sharedialog sharedialog;     private string name, surname, imageurl;     private string tag = "mainactivity";      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          button = (button) findviewbyid(r.id.bm);         textview = (textview) findviewbyid(r.id.txt);          bundle inbundle = getintent().getextras();         name = inbundle.getstring("name");         surname = inbundle.getstring("surname");         imageurl = inbundle.getstring("imageurl");          textview nameview = (textview) findviewbyid(r.id.nameandsurname);         nameview.settext("" + name + " " + surname);         button.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 stringrequest stringrequest = new stringrequest(request.method.post, server_url, new response.listener<string>() {                     @override                     public void onresponse(string response) {                     textview.settext(response);                     //requestqueue.stop();                     }                 }, new response.errorlistener() {                     @override                     public void onerrorresponse(volleyerror error) {                         textview.settext("something went wrong");                         error.printstacktrace();                         //requestqueue.stop();                     }                 });                 //requestqueue.add(stringrequest);                 singletonrequestqueue.getminstance(getapplicationcontext()).addrequestqueue(stringrequest);             }         });     }      private void share() {         sharedialog = new sharedialog(this);         list<string> taggeduserids = new arraylist<string>();         taggeduserids.add("{user_id}");         taggeduserids.add("{user_id}");         taggeduserids.add("{user_id}");          sharelinkcontent content = new sharelinkcontent.builder()                 .setcontenturl(uri.parse("http://www.sitepoint.com"))                 .setcontenttitle("this content title")                 .setcontentdescription("this description")                 .setsharehashtag(new sharehashtag.builder().sethashtag("#sitepoint").build())                 .setpeopleids(taggeduserids)                 .setplaceid("{place_id}")                 .build();          sharedialog.show(content);     }      private void getposts() {         new graphrequest(accesstoken.getcurrentaccesstoken(), "/me/posts", null, httpmethod.get, new graphrequest.callback() {             public void oncompleted(graphresponse response) {                 log.e(tag, response.tostring());             }         }).executeasync();     }      private void logout() {         loginmanager.getinstance().logout();         intent login = new intent(mainactivity.this, loginactivity.class);         startactivity(login);         finish();     }      //@override     public void onclick(view view) {         switch (view.getid()) {             case r.id.share:                 share();                 break;              case r.id.getposts:                 getposts();                 break;              case r.id.logout:                 logout();                 break;         }     } } 

loginactivity.java

package com.ticketapp.emailaddress.ticketapp;  import android.content.intent; import android.graphics.color; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log;  import com.facebook.accesstokentracker; import com.facebook.callbackmanager; import com.facebook.facebookcallback; import com.facebook.facebookexception; import com.facebook.graphrequest; import com.facebook.graphresponse; import com.facebook.profiletracker; import com.facebook.login.loginresult; import com.facebook.login.widget.loginbutton;  import org.json.jsonexception; import org.json.jsonobject;  import java.net.malformedurlexception; import java.net.url;  public class loginactivity extends appcompatactivity {      private callbackmanager callbackmanager;     private accesstokentracker accesstokentracker;     private profiletracker profiletracker;     private loginbutton loginbutton;     private string firstname,lastname, email,birthday,gender;     private url profilepicture;     private string userid;     private string tag = "loginactivity";      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          // facebooksdk.sdkinitialize(this);         //facebooksdk.sdkinitialize(getapplicationcontext());          setcontentview(r.layout.activity_login);         callbackmanager = callbackmanager.factory.create();          loginbutton = (loginbutton) findviewbyid(r.id.login_button);         loginbutton.setheight(100);         loginbutton.settextcolor(color.white);         loginbutton.setcompounddrawableswithintrinsicbounds(null, null, null, null);         loginbutton.setcompounddrawablepadding(0);          loginbutton.setreadpermissions("email", "user_birthday","user_posts");         loginbutton.registercallback(callbackmanager, callback);     }      facebookcallback<loginresult> callback = new facebookcallback<loginresult>() {         @override         public void onsuccess(loginresult loginresult) {             graphrequest request = graphrequest.newmerequest(loginresult.getaccesstoken(), new graphrequest.graphjsonobjectcallback() {                 @override                 public void oncompleted(jsonobject object, graphresponse response) {                     log.e(tag,object.tostring());                     log.e(tag,response.tostring());                      try {                         userid = object.getstring("id");                         profilepicture = new url("https://graph.facebook.com/" + userid + "/picture?width=500&height=500");                         if(object.has("first_name"))                             firstname = object.getstring("first_name");                         if(object.has("last_name"))                             lastname = object.getstring("last_name");                         if (object.has("email"))                             email = object.getstring("email");                         if (object.has("birthday"))                             birthday = object.getstring("birthday");                         if (object.has("gender"))                             gender = object.getstring("gender");                          intent main = new intent(loginactivity.this,mainactivity.class);                         main.putextra("name",firstname);                         main.putextra("surname",lastname);                         main.putextra("imageurl",profilepicture.tostring());                         startactivity(main);                         finish();                     } catch (jsonexception e) {                         e.printstacktrace();                     } catch (malformedurlexception e) {                         e.printstacktrace();                     }                 }             });             //here put requested fields returned jsonobject             bundle parameters = new bundle();             parameters.putstring("fields", "id, first_name, last_name, email, birthday, gender");             request.setparameters(parameters);             request.executeasync();         }          @override         public void oncancel() {         }          @override         public void onerror(facebookexception e) {             e.printstacktrace();         }     };      @override     protected void onactivityresult(int requestcode, int responsecode, intent intent) {         super.onactivityresult(requestcode, responsecode, intent);         callbackmanager.onactivityresult(requestcode, responsecode, intent);     } } 

singletonrequestqueue.java

package com.ticketapp.emailaddress.ticketapp;  import android.content.context;  import com.android.volley.request; import com.android.volley.requestqueue; import com.android.volley.toolbox.volley;  import java.lang.ref.referencequeue;  /**  * created adde on 2017-09-11.  */  public class singletonrequestqueue {     private     static singletonrequestqueue minstance;     private requestqueue requestqueue;     private static context mctx;       private singletonrequestqueue(context context){          mctx = context;         requestqueue = getrequestqueue();     }      public requestqueue getrequestqueue(){          if(requestqueue == null){             requestqueue = volley.newrequestqueue(mctx.getapplicationcontext());         }         return requestqueue;     }     public static synchronized singletonrequestqueue getminstance(context context) {         if(minstance == null){             minstance = new singletonrequestqueue(context);         }         return minstance;     }      public<t> void addrequestqueue(request<t> request){         requestqueue.add(request);     } } 

build.gradle (module)

apply plugin: 'com.android.application'  android {     compilesdkversion 26     buildtoolsversion "26.0.1"     defaultconfig {         applicationid "com.ticketapp.myname.ticketapp"         minsdkversion 15         targetsdkversion 26         versioncode 1         versionname "1.0"         testinstrumentationrunner "android.support.test.runner.androidjunitrunner"     }     buildtypes {         release {             minifyenabled false             proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'         }     } }  dependencies {     //fb sdk     compile filetree(include: ['*.jar'], dir: 'libs')     androidtestcompile('com.android.support.test.espresso:espresso-core:2.2.2', {         exclude group: 'com.android.support', module: 'support-annotations'     })     compile 'com.android.support:appcompat-v7:26.+'      // compile 'com.android.support:design:26.0.1'     // compile 'com.android.support:appcompat-v7:26.0.1'      // compile 'com.android.support:multidex:1.0.1'     // firebase      // volley     // compile 'com.android.volley:volley:1.0.0'      compile 'com.facebook.android:facebook-android-sdk:[4,5)'     compile 'com.android.support.constraint:constraint-layout:1.0.2'     compile 'com.google.firebase:firebase-auth:11.2.2'     compile 'com.mcxiaoke.volley:library:1.0.19'     //compile "com.google.android.gms:play-services-location:11.2.2"      testcompile 'junit:junit:4.12' }  // add bottom of file apply plugin: 'com.google.gms.google-services' 

build.gradle (app)

// top-level build file can add configuration options common sub-projects/modules.  buildscript {     repositories {         jcenter()          //fb sdk         mavencentral()     }     dependencies {         classpath 'com.android.tools.build:gradle:2.3.3'          // note: not place application dependencies here; belong         // in individual module build.gradle files         // add line         classpath 'com.google.gms:google-services:3.1.0'     } }  allprojects {     repositories {          jcenter()          //fb sdk         maven {             url "https://maven.google.com" // google's maven repository         }     } }  task clean(type: delete) {     delete rootproject.builddir } 

logcat message

e/androidruntime: fatal exception: main process: com.ticketapp.myname.ticketapp, pid: 9650 java.lang.runtimeexception: unable start activity   componentinfo{com.ticketapp.myname.ticketapp/com.ticketapp.myname.ticketapp.mainactivity}: android.view.inflateexception: binary xml file line #14: binary xml file line #14: error inflating class com.facebook.login.widget.loginbutton @ android.app.activitythread.performlaunchactivity(activitythread.java:2817) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2892) @ android.app.activitythread.-wrap11(unknown source:0) @ android.app.activitythread$h.handlemessage(activitythread.java:1593) @ android.os.handler.dispatchmessage(handler.java:105) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6541) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)  caused by: android.view.inflateexception: binary xml file line #14: binary xml file line #14: error inflating class com.facebook.login.widget.loginbutton caused by: android.view.inflateexception: binary xml file line #14: error inflating class com.facebook.login.widget.loginbutton caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.constructor.newinstance0(native method) @ java.lang.reflect.constructor.newinstance(constructor.java:334) @ android.view.layoutinflater.createview(layoutinflater.java:647) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:790) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:730) @ android.view.layoutinflater.rinflate(layoutinflater.java:863) @ android.view.layoutinflater.rinflatechildren(layoutinflater.java:824) @ android.view.layoutinflater.inflate(layoutinflater.java:515) @ android.view.layoutinflater.inflate(layoutinflater.java:423) @ android.view.layoutinflater.inflate(layoutinflater.java:374) @ android.support.v7.app.appcompatdelegateimplv9.setcontentview(appcompatdelegateimplv9.java:292) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:140) @ com.ticketapp.myname.ticketapp.mainactivity.oncreate(mainactivity.java:49) @ android.app.activity.performcreate(activity.java:6975) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1213) @ android.app.activitythread.performlaunchactivity(activitythread.java:2770) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2892) @ android.app.activitythread.-wrap11(unknown source:0) @ android.app.activitythread$h.handlemessage(activitythread.java:1593) @ android.os.handler.dispatchmessage(handler.java:105) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6541) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)  caused by: sdk has not been initialized, make sure call facebooksdk.sdkinitialize() first. @ com.facebook.internal.validate.sdkinitialized(validate.java:145) @ com.facebook.accesstokentracker.<init>(accesstokentracker.java:55) @ com.facebook.login.widget.loginbutton$2.<init>(loginbutton.java:581) @ com.facebook.login.widget.loginbutton.configurebutton(loginbutton.java:581) @ com.facebook.facebookbuttonbase.<init>(facebookbuttonbase.java:64) @ com.facebook.login.widget.loginbutton.<init>(loginbutton.java:210) @ java.lang.reflect.constructor.newinstance0(native method)  @ java.lang.reflect.constructor.newinstance(constructor.java:334)  @ android.view.layoutinflater.createview(layoutinflater.java:647)  @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:790)  @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:730)  @ android.view.layoutinflater.rinflate(layoutinflater.java:863)  @ android.view.layoutinflater.rinflatechildren(layoutinflater.java:824)  @ android.view.layoutinflater.inflate(layoutinflater.java:515)  @ android.view.layoutinflater.inflate(layoutinflater.java:423)  @ android.view.layoutinflater.inflate(layoutinflater.java:374)  @ android.support.v7.app.appcompatdelegateimplv9.setcontentview(appcompatdelegateimplv9.java:292)  @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:140)  @ com.ticketapp.myname.ticketapp.mainactivity.oncreate(mainactivity.java:49)  @ android.app.activity.performcreate(activity.java:6975)  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1213)  @ android.app.activitythread.performlaunchactivity(activitythread.java:2770)  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2892)  @ android.app.activitythread.-wrap11(unknown source:0)  @ android.app.activitythread$h.handlemessage(activitythread.java:1593)  @ android.os.handler.dispatchmessage(handler.java:105)  @ android.os.looper.loop(looper.java:164)  @ android.app.activitythread.main(activitythread.java:6541)  @ java.lang.reflect.method.invoke(native method)  @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240)  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)  

manifest

<?xml version="1.0" encoding="utf-8"?> 

<uses-permission android:name="android.permission.internet" />  <activity     android:name="com.facebook.customtabactivity"     android:exported="true">     <intent-filter>         <action android:name="android.intent.action.view" />          <category android:name="android.intent.category.default" />         <category android:name="android.intent.category.browsable" />          <data android:scheme="@string/fb_login_protocol_scheme" />     </intent-filter> </activity>  <application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:roundicon="@mipmap/ic_launcher_round"     android:supportsrtl="true"     android:theme="@style/apptheme">     <meta-data         android:name="com.facebook.sdk.applicationid"         android:value="secretokrn" />      <activity         android:name="com.facebook.facebookactivity"         android:configchanges="keyboard|keyboardhidden|screenlayout|screensize|orientation"         android:label="@string/app_name"         android:screenorientation="portrait" />       <activity android:name=".mainactivity">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>      <provider         android:name="com.facebook.facebookcontentprovider"         android:authorities="com.facebook.app.facebookcontentprovidersecrettoken"         android:exported="true" />      <activity android:name=".loginactivity"></activity> </application> 

strings.xml

<resources>     <string name="app_name">ticketapp</string>     <string name="facebook_app_id">secrettoken</string>     <string name="fb_login_protocol_scheme">fbsecrettoken</string>     <string name="app_id">$app_id_here</string>     <string name="sharecontent">share content</string>     <string name="posts">posts</string>     <string name="logout">logout</string>     <string name="hello">hello</string> </resources> 

i hope have included enough replicating or solving without testing.

updated catlog.

09-12 15:13:21.988 5675-5675/com.ticketapp.myname.ticketapp e/androidruntime: fatal exception: main process: com.ticketapp.myname.ticketapp, pid: 5675 java.lang.runtimeexception: unable start activity  componentinfo{com.ticketapp.myname.ticketapp/com.ticketapp.myname.ticketapp.mainactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'java.lang.string android.os.bundle.getstring(java.lang.string)' on null object reference @ android.app.activitythread.performlaunchactivity(activitythread.java:2817) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2892) @ android.app.activitythread.-wrap11(unknown source:0) @ android.app.activitythread$h.handlemessage(activitythread.java:1593) @ android.os.handler.dispatchmessage(handler.java:105) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6541) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'java.lang.string android.os.bundle.getstring(java.lang.string)' on null object reference @ com.ticketapp.myname.ticketapp.mainactivity.oncreate(mainactivity.java:76) @ android.app.activity.performcreate(activity.java:6975) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1213) @ android.app.activitythread.performlaunchactivity(activitythread.java:2770) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2892)  @ android.app.activitythread.-wrap11(unknown source:0)  @ android.app.activitythread$h.handlemessage(activitythread.java:1593)  @ android.os.handler.dispatchmessage(handler.java:105)  @ android.os.looper.loop(looper.java:164)  @ android.app.activitythread.main(activitythread.java:6541)  @ java.lang.reflect.method.invoke(native method)  @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240)  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)  

ok guys! new update! apparently there issue in code put try , catch , application worked. unfortunately when u log in nothing displays @ moment. changed in mainactivity.java

try {     name = inbundle.getstring("name");     surname = inbundle.getstring("surname");     imageurl = inbundle.getstring("imageurl");     textview nameview = (textview) findviewbyid(r.id.nameandsurname);     nameview.settext("" + name + " " + surname); } catch (exception e){     log.e("error on setcontent", e.getmessage()); } 

in mainactivity, have this:

bundle inbundle = getintent().getextras();     name = inbundle.getstring("name");     surname = inbundle.getstring("surname");     imageurl = inbundle.getstring("imageurl"); 

but first time load it, inbundle null. should check if null before running getstring on it:

bundle inbundle = getintent().getextras(); if(inbundle!=null){     name = inbundle.getstring("name");     surname = inbundle.getstring("surname");     imageurl = inbundle.getstring("imageurl"); } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -