Reputation: 65
I am able to load the splash screen but after 3 seconds the app crashes.I want to load the Main Activity after the splash screen.Also I found that the same topic was discussed earlier in stack over flow but it didn't helped me.
Please help me solve the issues.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a2.attemp2" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashScreen"
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=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.a2.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
SplashScreen.java
package com.example.a2.attemp2;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
public class SplashScreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// //Remove title bar
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//
// //Remove notification bar
// // this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//
// //set content view AFTER ABOVE sequence (to avoid crash)
// this.setContentView(R.layout.splash);
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
MainActivity.java
package com.example.a2.attemp2;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@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);
}
}
I had recently started another project with same code with different package com.example.jarvis.digin I assure you that there is no compilation errors.
EVENT LOG
10-17 21:46:20.887 7359-7359/com.example.jarvis.digin E/Trace: error opening trace file: No such file or directory (2)
10-17 21:46:21.347 7359-7359/com.example.jarvis.digin W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
10-17 21:46:21.347 7359-7359/com.example.jarvis.digin I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
10-17 21:46:21.347 7359-7359/com.example.jarvis.digin W/dalvikvm: VFY: unable to resolve interface method 17898: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
10-17 21:46:21.347 7359-7359/com.example.jarvis.digin D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
10-17 21:46:21.347 7359-7359/com.example.jarvis.digin I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
10-17 21:46:21.347 7359-7359/com.example.jarvis.digin W/dalvikvm: VFY: unable to resolve interface method 17902: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
10-17 21:46:21.357 7359-7359/com.example.jarvis.digin D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin D/AndroidRuntime: Shutting down VM
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x419a9300)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: FATAL EXCEPTION: main
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jarvis.digin/com.example.jarvis.digin.SplashScreen}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4745)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:311)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:280)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:254)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at com.example.jarvis.digin.SplashScreen.onCreate(SplashScreen.java:17)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5008)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4745)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-17 21:46:21.457 7359-7359/com.example.jarvis.digin E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 3606
Reputation: 65
This is the error message when running on the device
This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
The problem is clear from the message above.
I solved this by removing the following code from MainActivity.java
.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Hope this answer will help beginners when they choose blank template.
Upvotes: 0
Reputation: 2165
The error in your log was saying it was caused by:
IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I'd guess there is a problem with the theme you have specified in your AndroidManifest.xml. Try changing it to something like:
android:theme="@android:style/Theme.Holo"
Check out How to change app default theme to a different app theme?
Upvotes: 1