亲爱的兄弟,你好我发布错误和xml文件代码解决方案,当我运行项目这个错误时,请帮助请帮助请告诉我30秒后开始其他活动。提前谢谢
错误
09-12 15:04:19.491:E / AndroidRuntime(696):致命异常:主要09-12 15:04:19.491:E / AndroidRuntime(696):java.lang.RuntimeException: 无法开始活动 ComponentInfo {awsome.zero360jokes / superjokes.WelcomeActivity}: java.lang.NullPointerException 09-12 15:04:19.491: E / AndroidRuntime(696):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 09-12 15:04:19.491:E / AndroidRuntime(696):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 09-12 15:04:19.491:E / AndroidRuntime(696):at android.app.ActivityThread.access $ 1500(ActivityThread.java:117)09-12 15:04:19.491:E / AndroidRuntime(696):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931) 09-12 15:04:19.491:E / AndroidRuntime(696):at android.os.Handler.dispatchMessage(Handler.java:99)09-12 15:04:19.491:E / AndroidRuntime(696):at android.os.Looper.loop(Looper.java:123)09-12 15:04:19.491: E / AndroidRuntime(696):at android.app.ActivityThread.main(ActivityThread.java:3683)09-12 15:04:19.491:E / AndroidRuntime(696):at java.lang.reflect.Method.invokeNative(Native Method)09-12 15:04:19.491:E / AndroidRuntime(696):at java.lang.reflect.Method.invoke(Method.java:507)09-12 15:04:19.491: E / AndroidRuntime(696):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839) 09-12 15:04:19.491:E / AndroidRuntime(696):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)09-12 15:04:19.491:E / AndroidRuntime(696):at dalvik.system.NativeStart.main(Native Method)09-12 15:04:19.491: E / AndroidRuntime(696):引起:java.lang.NullPointerException 09-12 15:04:19.491:E / AndroidRuntime(696):at superjokes.WelcomeActivity.onCreate(WelcomeActivity.java:44)09-12 15:04:19.491:E / AndroidRuntime(696):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 09-12 15:04:19.491:E / AndroidRuntime(696):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 09-12 15:04:19.491:E / AndroidRuntime(696):... 11更多
码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0FFFF"
android:orientation="vertical" >
<!-- <LinearLayout
android:background="#F0FFFF"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
-->
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:layout_marginTop="0dp"
android:layout_weight="0.5">
<ImageView
android:id="@+id/icon"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_marginTop="15dp"
android:src="@drawable/superjokesbig" />
</LinearLayout>
<!-- <LinearLayout
android:layout_width="match_parent"
android:layout_height="111dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:textColor="@color/Black"
android:layout_width="match_parent"
android:text="Welcome to SUPER JOKES"
android:layout_height="wrap_content"
android:padding="2dp"
android:shadowColor="@color/TransparentGrey"
android:shadowDx="3"
android:shadowDy="-3"
android:textSize="25dp"
android:shadowRadius="1.5"
android:gravity="center"
/>
<TextView
android:textColor="@color/Black"
android:layout_width="match_parent"
android:text="Here you can enjoy alot after reading funny jokes in different languages :D"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="15dp"
android:gravity="center"
/>
</LinearLayout> -->
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:id="@+id/loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/loader"
/>
<!-- <Button
android:id="@+id/welcomeBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#DC143C"
android:textColor="#FFF8DC"
android:textSize="20dp"
android:text="CONTINUE"
android:textStyle="italic"
/> -->
<!--
<ProgressBar
android:id="@+id/p_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
-->
</LinearLayout>
<!-- <LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
>
<TextView
android:id="@+id/poweredby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Powered by zero360.net"
android:gravity="center"
android:textSize="15dp"
android:textStyle="bold"
/>
</LinearLayout> -->
<!-- </LinearLayout>
--></LinearLayout>
主要活动代码
package superjokes; import java.util.zip.Inflater; import awsome.zero360jokes.R; import android.support.v7.app.ActionBarActivity; importandroid.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.os.SystemClock; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.Button; import android.widget.ProgressBar; import android.widget.Toast;
public class WelcomeActivity extends ActionBarActivity {
> Boolean isInternetPresent = false;
> ConnectionDetector cd;
> WebView wv1;
>
> Context context;
> protected void onCreate(Bundle
> savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity_welcome);
>
> final Intent intent=new Intent(this,Jokecatagory.class);
> cd =new ConnectionDetector(getApplicationContext());
> enterForJoke.setOnClickListener(new OnClickListener(){
>
>
>
> @Override
> public void onClick(View v) {
>
> isInternetPresent = cd.isConnectingToInternet();
> System.out.println("Connection"+isInternetPresent);
> // check for Internet status
> if (isInternetPresent) {
> startActivity(intent);
> //Toast.makeText(getApplicationContext(),"You are connected to the internet.", Toast.LENGTH_SHORT).show();
> } else {
> Toast.makeText(getApplicationContext(),"Internet Connection NOt Available !", Toast.LENGTH_SHORT).show();
> } }
>
> });//end of the On Click Listner
> } }
答案 0 :(得分:0)
您可以使用此代码将您的活动暂停30秒,并在30秒后开始新活动
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread timer=new Thread()
{
public void run(){
try{
sleep(5000);
}
catch(InterruptedException e){
e.printStackTrace();
}
finally{
Intent inn=new Intent(MainActivity.this,your.class);
startActivity(inn);
}
}
};
timer.start();
}
}