简体   繁体   English

无法在 Android 中启动 Activity 组件

[英]Can't start Activity components in Android

Dear brother how are you all i post the error and xml file code solution pls when i run project this error accured kindly help pls and kindly tell me start other activity after 30 seconds .亲爱的兄弟,你们好吗,我在运行项目时发布了错误和 xml 文件代码解决方案请帮助请帮助请告诉我在 30 秒后开始其他活动。 thanks in advance提前致谢

Error错误

09-12 15:04:19.491: E/AndroidRuntime(696): FATAL EXCEPTION: main 09-12 15:04:19.491: E/AndroidRuntime(696): java.lang.RuntimeException: Unable to start activity 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.jav 09-12 15:04:19.491: E/AndroidRuntime(696): 致命异常: main 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):在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 09-12 15:04:19.491:E/AndroidRuntime(696):在 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): 在 android.app.ActivityThread.main(ActivityThread.jav) a: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): Caused by: 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(6 a:3683) 09-12 15:04:19.491: E/AndroidRuntime(696): 在 java.lang.reflect.Method.invokeNative(Native Method) 09-12 15:04:19.491: E/AndroidRuntime(696):在 java.lang.reflect.Method.invoke(Method.java:507) 09-12 15:04:19.491: E/AndroidRuntime(696): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit. java:839) 09-12 15:04:19.491: E/AndroidRuntime(696): 在 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):在 superjokes.WelcomeActivity.onCreate(WelcomeActivity.java:44) 09-12 15:04:19.491:E/AndroidRuntime(696):在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) ) 09-12 15:04:19.491: E/AndroidRuntime(696): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 09-12 15:04:19.491: E/AndroidRuntime(6) 96): ... 11 more 96):……还有 11 个

code代码

<?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>

Main Activity code主要活动代码

 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
>           } }

You can use this code for sleep your activity for 30 second and after 30 second new activity start您可以使用此代码将您的活动睡眠 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();   
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM