XML : unfortunately app has stopped in android studio [duplicate]

This question already has an answer here:

i created an app for converting a website into android app but after compilling, when it launches in emulator it gets force stop unfortunately app has stopped because of exceptions.

here are the coding

MainActivity.java

  package pheonix.developer.cbpgec;        import android.app.ActionBar;      import android.app.Activity;      import android.content.Intent;      import android.os.Bundle;      import android.view.Menu;      import android.view.MenuItem;      import android.view.View;      import android.webkit.WebSettings;      import android.webkit.WebView;      import android.widget.ShareActionProvider;          public class MainActivity extends Activity {            private WebView mWebView;            @Override          protected void onCreate(Bundle savedInstanceState) {              super.onCreate(savedInstanceState);              setContentView(R.layout.activity_main);                mWebView = (WebView) findViewById(R.id.activity_main_webview);              WebSettings webSettings = mWebView.getSettings();              webSettings.setJavaScriptEnabled(true);              mWebView.loadUrl("http://gecdelhi.ac.in/");              mWebView.setWebViewClient(new pheonix.developer.cbpgec.MyAppWebViewClient(){                  @Override                  public void onPageFinished(WebView view, String url) {                      //hide loading image                      findViewById(R.id.progressBar1).setVisibility(View.GONE);                      //show webview                      findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);                  }});              }            @Override          public void onBackPressed() {              if(mWebView.canGoBack()) {                  mWebView.goBack();              } else {                  super.onBackPressed();              }          }              private ShareActionProvider mShareActionProvider;          @Override          public boolean onCreateOptionsMenu(Menu menu) {                /** Inflating the current activity's menu with res/menu/items.xml */              getMenuInflater().inflate(R.menu.menu_main, menu);                /** Getting the actionprovider associated with the menu item whose id is share */              mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider();                /** Setting a share intent */              mShareActionProvider.setShareIntent(getDefaultShareIntent());                return super.onCreateOptionsMenu(menu);            }            /** Returns a share intent */          private Intent getDefaultShareIntent(){              Intent intent = new Intent(Intent.ACTION_SEND);              intent.setType("text/plain");              intent.putExtra(Intent.EXTRA_SUBJECT, "Android Application");              intent.putExtra(Intent.EXTRA_TEXT," CBPGEC");              return intent;          }    

MyAppWebViewClient.java

  package pheonix.developer.cbpgec;    import android.content.Intent;  import android.net.Uri;  import android.webkit.WebView;  import android.webkit.WebViewClient;      public class MyAppWebViewClient extends WebViewClient {        @Override      public boolean shouldOverrideUrlLoading(WebView view, String url) {          if(Uri.parse(url).getHost().endsWith("gecdelhi.ac.in")) {              return false;          }            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));          view.getContext().startActivity(intent);          return true;      }  }    

Splash.java

  package pheonix.developer.cbpgec;    import android.annotation.SuppressLint;  import android.annotation.TargetApi;  import android.app.ActionBar;  import android.app.Activity;  import android.content.Intent;  import android.os.Build;  import android.os.Bundle;    @SuppressLint("NewApi")  public class Splash extends Activity {        @TargetApi(Build.VERSION_CODES.HONEYCOMB)      @SuppressLint("NewApi")      @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_splash);            ActionBar actionBar = getActionBar();          actionBar.hide();            Thread t =new Thread(){              public void run(){                  try{                      sleep(10000);                  }catch(InterruptedException e){                      e.printStackTrace();                  }finally{                      Intent i =new Intent(Splash.this,MainActivity.class);                      startActivity(i);                  }              }          };          t.start();      }      @Override      public void onPause(){          super.onPause();          finish();      }    }    

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"      tools:context=".MainActivity"      android:orientation="vertical">        <ProgressBar          android:id="@+id/progressBar1"          style="?android:attr/progressBarStyleSmall"          android:layout_width="wrap_content"          android:layout_height="match_parent"          android:layout_centerHorizontal="true"          android:indeterminate="false"          android:layout_gravity="center" />        <WebView          android:id="@+id/activity_main_webview"          android:layout_width="match_parent"          android:layout_height="match_parent"          android:visibility="gone"/>  </LinearLayout>    

activity_splash.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:background="@mipmap/vert_loading"  tools:context=".Splash" >    

menu_main.xml

  <menu xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">  <item      android:id="@+id/share"      android:title="@string/share"      android:showAsAction="ifRoom"      android:actionProviderClass="android.widget.ShareActionProvider"/>    

getting error in this area of code of Handler.java

      private static void handleCallback(Message message) {      message.callback.run();  }    final MessageQueue mQueue;  final Looper mLooper;  final Callback mCallback;  final boolean mAsynchronous;  IMessenger mMessenger;    private static final class BlockingRunnable implements Runnable {      private final Runnable mTask;      private boolean mDone;        public BlockingRunnable(Runnable task) {          mTask = task;      }        @Override      public void run() {          try {              mTask.run();          } finally {              synchronized (this) {                  mDone = true;                  notifyAll();              }          }      }    

also in this area

    public void dispatchMessage(Message msg) {      if (msg.callback != null) {          handleCallback(msg);      } else {          if (mCallback != null) {              if (mCallback.handleMessage(msg)) {                  return;              }          }          handleMessage(msg);      }  }    

getting exception in this area

              Printer logging = me.mLogging;          if (logging != null) {              logging.println(">>>>> Dispatching to " + msg.target + " " +                      msg.callback + ": " + msg.what);          }            msg.target.dispatchMessage(msg);            if (logging != null) {              logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);          }            // Make sure that during the course of dispatching the          // identity of the thread wasn't corrupted.          final long newIdent = Binder.clearCallingIdentity();          if (ident != newIdent) {              Log.wtf(TAG, "Thread identity changed from 0x"                      + Long.toHexString(ident) + " to 0x"                      + Long.toHexString(newIdent) + " while dispatching to "                      + msg.target.getClass().getName() + " "                      + msg.callback + " what=" + msg.what);          }            msg.recycleUnchecked();      }  }    

these are all exception details from logcat

      01-14 17:05:30.758    2984-2984/pheonix.developer.cbpgec E/AndroidRuntime﹕ FATAL EXCEPTION: main      Process: pheonix.developer.cbpgec, PID: 2984      java.lang.NullPointerException: Attempt to invoke interface method 'android.view.ActionProvider android.view.MenuItem.getActionProvider()' on a null object reference              at pheonix.developer.cbpgec.MainActivity.onCreateOptionsMenu(MainActivity.java:58)              at android.app.Activity.onCreatePanelMenu(Activity.java:2846)              at com.android.internal.policy.PhoneWindow.preparePanel(PhoneWindow.java:567)              at com.android.internal.policy.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:939)              at com.android.internal.policy.PhoneWindow$1.run(PhoneWindow.java:271)              at android.os.Handler.handleCallback(Handler.java:739)              at android.os.Handler.dispatchMessage(Handler.java:95)              at android.os.Looper.loop(Looper.java:148)              at android.app.ActivityThread.main(ActivityThread.java:5417)              at java.lang.reflect.Method.invoke(Native Method)              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  01-14 17:05:34.534    2984-2984/? I/Process﹕ Sending signal. PID: 2984 SIG: 9    

No comments:

Post a Comment