Reputation: 1591
i have made a simple android for splash demo ,in that two activities are there but after splash screen program stopped running...please help me for it..
my code:
splash.java
package com.esp.therisemethod.ui;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.esp.therisemethod.R;
import com.esp.therisemethod.util.Log;
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread splashThread = new Thread() {
public void run() {
try {
sleep(2000);
} catch (InterruptedException e) {
Log.error(this.getClass() + "::: OnCreate Thread :::", e);
}
Intent intent = null;
intent = new Intent(SplashActivity.this, Registration.class);
startActivity(intent);
finish();
}
};
splashThread.start();
}
}
registration.java
package com.esp.therisemethod.ui;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.esp.therisemethod.R;
import com.esp.therisemethod.uc.Header;
public class Registration extends Activity implements OnClickListener{
Button bt_login,bt_Reg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
bt_login =(Button)findViewById(R.id.bt_login);
bt_Reg=(Button)findViewById(R.id.bt_reg);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bt_login:
break;
case R.id.bt_reg:
break;
}
}
}
Logcat
06-26 06:09:22.635: E/Trace(2371): error opening trace file: No such file or directory (2)
06-26 06:09:23.055: D/dalvikvm(2371): GC_FOR_ALLOC freed 34K, 7% free 2408K/2588K, paused 45ms, total 51ms
06-26 06:09:23.096: I/dalvikvm-heap(2371): Grow heap (frag case) to 5.264MB for 2908176-byte allocation
06-26 06:09:23.155: D/dalvikvm(2371): GC_FOR_ALLOC freed 1K, 4% free 5247K/5432K, paused 50ms, total 50ms
06-26 06:09:23.225: D/dalvikvm(2371): GC_CONCURRENT freed <1K, 4% free 5246K/5432K, paused 9ms+15ms, total 74ms
06-26 06:09:23.597: D/dalvikvm(2371): GC_FOR_ALLOC freed <1K, 4% free 5246K/5432K, paused 30ms, total 30ms
06-26 06:09:23.615: I/dalvikvm-heap(2371): Grow heap (frag case) to 6.497MB for 1292972-byte allocation
06-26 06:09:23.755: D/dalvikvm(2371): GC_CONCURRENT freed 0K, 3% free 6509K/6696K, paused 74ms+15ms, total 142ms
06-26 06:09:24.025: D/gralloc_goldfish(2371): Emulator without GPU emulation detected.
06-26 06:09:26.375: D/AndroidRuntime(2371): Shutting down VM
06-26 06:09:26.395: W/dalvikvm(2371): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-26 06:09:26.905: E/AndroidRuntime(2371): FATAL EXCEPTION: main
06-26 06:09:26.905: E/AndroidRuntime(2371): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.esp.therisemethod/com.esp.therisemethod.ui.Registration}: android.view.InflateException: Binary XML file line #7: Error inflating class com.esp.therisemethod.uc.Header
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.os.Looper.loop(Looper.java:137)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-26 06:09:26.905: E/AndroidRuntime(2371): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371): at java.lang.reflect.Method.invoke(Method.java:511)
06-26 06:09:26.905: E/AndroidRuntime(2371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-26 06:09:26.905: E/AndroidRuntime(2371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-26 06:09:26.905: E/AndroidRuntime(2371): at dalvik.system.NativeStart.main(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.esp.therisemethod.uc.Header
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-26 06:09:26.905: E/AndroidRuntime(2371): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.Activity.setContentView(Activity.java:1881)
06-26 06:09:26.905: E/AndroidRuntime(2371): at com.esp.therisemethod.ui.Registration.onCreate(Registration.java:19)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.Activity.performCreate(Activity.java:5104)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-26 06:09:26.905: E/AndroidRuntime(2371): ... 11 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: java.lang.reflect.InvocationTargetException
06-26 06:09:26.905: E/AndroidRuntime(2371): at java.lang.reflect.Constructor.constructNative(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-26 06:09:26.905: E/AndroidRuntime(2371): ... 22 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class com.esp.therisemethod.uc.EspTextView
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-26 06:09:26.905: E/AndroidRuntime(2371): at com.esp.therisemethod.uc.Header.<init>(Header.java:21)
06-26 06:09:26.905: E/AndroidRuntime(2371): ... 25 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: java.lang.reflect.InvocationTargetException
06-26 06:09:26.905: E/AndroidRuntime(2371): at java.lang.reflect.Constructor.constructNative(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-26 06:09:26.905: E/AndroidRuntime(2371): ... 31 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: java.lang.RuntimeException: native typeface cannot be made
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.graphics.Typeface.<init>(Typeface.java:175)
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.graphics.Typeface.createFromAsset(Typeface.java:149)
06-26 06:09:26.905: E/AndroidRuntime(2371): at com.esp.therisemethod.util.Utils.getFont(Utils.java:389)
06-26 06:09:26.905: E/AndroidRuntime(2371): at com.esp.therisemethod.uc.EspTextView.<init>(EspTextView.java:23)
06-26 06:09:26.905: E/AndroidRuntime(2371): ... 34 more
please help me...thanx in advance
Upvotes: 4
Views: 3734
Reputation: 679
see this
Thread mythread = new Thread() {
public void run() {
try {
sleep(5000);
} catch (Exception e) {
} finally {
Intent intent = new Intent(Splash.this,
next.class);
startActivity(intent);
finish();
}
}
};
mythread.start();
Upvotes: 1
Reputation: 15515
You can try this way too..
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized (this) {
// wait 2 sec
wait(2000);
}
} catch (InterruptedException e) {
// Exception handling
} finally {
finish();
// start a new activity
Intent i = new Intent(SplashActivity.this, Registration.class);
startActivity(i);
// stop();
}
}
};
Upvotes: 1
Reputation: 2351
have you add your registration.java file in android manifest file. If not then add this code in manifest file
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Registration"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
</application>
Upvotes: 2
Reputation: 12733
as per your logcat, its says that error is occured in your xml file.. just look at your xml file on that specific line number..
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.esp.therisemethod.uc.Header
06-26 06:09:26.905: E/AndroidRuntime(2371): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
Upvotes: 3
Reputation: 1526
Following line of your log says that there is some error in the xml file you are inflating. Please look into it.
06-26 06:09:26.905: E/AndroidRuntime(2371): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.esp.therisemethod/com.esp.therisemethod.ui.Registration}:
android.view.InflateException: Binary XML file line #7: Error inflating class
com.esp.therisemethod.uc.Header
Upvotes: 2
Reputation: 2108
Use this as your SplashActivity... It worked in my case
public class SplashActivity extends Activity {
Intent intent;
//Called when activity if first called
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
intent = new Intent(this, HomeActivity.class);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
startActivity(intent);
finish();
}
}, 2000);
}
Upvotes: 5
Reputation: 7626
Place Intent out of thread as below:
Thread splashThread = new Thread() {
public void run() {
try {
sleep(2000);
} catch (InterruptedException e) {
Log.error(this.getClass() + "::: OnCreate Thread :::", e);
}
}
};
splashThread.start();
Intent intent = null;
intent = new Intent(SplashActivity.this, Registration.class);
startActivity(intent);
finish();
Upvotes: 2
Reputation: 54672
Although I highly discourage about the setup of your current splash screen but to make it working in the first activity do something like this
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(SplashActivity.this, Registration.class);
startActivity(intent);
finish();
}
},2000);
Upvotes: 3