2017-01-31 3 views
-3

これは私がなぜ私のアプリは、Androidスタジオでクラッシュし続けるのでしょうか?(ヌルのOnCreate)

package com.example.jorgesalgado.singular20; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v4.view.PagerAdapter; 
import android.support.v4.view.ViewPager; 
import android.text.Html; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.Window; 
import android.view.WindowManager; 
import android.webkit.WebView; 
import android.widget.Button; 
import android.widget.LinearLayout; 
import android.widget.TextView; 





public class MainActivity extends Activity { 

// Used to load the 'native-lib' library on application startup. 
static { 
    System.loadLibrary("native-lib"); 
} 

private ViewPager viewPager; 
private ViewPagerAdapter viewPagerAdapter; 

private LinearLayout dotsLayout; 
private TextView[] dots; 
private int[] layouts; 
private Button btnNext; 
private WebView mWebView; 




@Nullable 
@Override 
protected void onCreate(Bundle savedInstanceState) { 

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 




    mWebView = (WebView) findViewById(R.id.mWebView); 
    mWebView.loadUrl("file:///android_asset/index.html"); 
    mWebView.getSettings().setJavaScriptEnabled(true); 



    viewPager = (ViewPager) findViewById(R.id.view_pager); 
    dotsLayout = (LinearLayout) findViewById(R.id.layoutDots); 

を持っており、これをやろうとしているすべてのIMがにあるエラー

01-30 17:08:39.607 12741-12741/? E/AndroidRuntime: FATAL EXCEPTION: main 
               Process:  com.example.jorgesalgado.singular20, PID: 12741 
               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jorgesalgado.singular20/com.example.jorgesalgado.singular20.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.loadUrl(java.lang.String)' on a null object reference 
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665) 
       ``         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                at android.os.Handler.dispatchMessage(Handler.java:102) 
                at android.os.Looper.loop(Looper.java:154) 
                at  android.app.ActivityThread.main(ActivityThread.java:6119) 
                at java.lang.reflect.Method.invoke(Native Method) 
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.loadUrl(java.lang.String)' on a null object reference 
                at com.example.jorgesalgado.singular20.MainActivity.onCreate(MainActivity.java:58) 
                at android.app.Activity.performCreate(Activity.java:6679) 
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)  
                at android.app.ActivityThread.-wrap12(ActivityThread.java)  
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)  
                at android.os.Handler.dispatchMessage(Handler.java:102)  
                at android.os.Looper.loop(Looper.java:154)  
                at android.app.ActivityThread.main(ActivityThread.java:6119)  
                at java.lang.reflect.Method.invoke(Native Method)  
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)  
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

である基本的なコードですindex.htmlを使用してアンドロイドスタジオでhtmlとjavascriptを使用できるようにします。あなたの誰かがこれを行う良い方法がありますか?もしそうなら、私を助けてください。ここ

は、XMLコード

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/bg_screen1"> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" 
    android:id="@+id/linearLayout"> 

</LinearLayout> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="textPersonName" 
    android:ems="10" 
    android:layout_above="@+id/textView2" 
    android:layout_alignLeft="@+id/textView2" 
    android:layout_alignStart="@+id/textView2" 
    android:layout_marginLeft="16dp" 
    android:layout_marginStart="16dp" 
    android:id="@+id/txtOutput" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Type in the topic" 
    android:textColor="@android:color/white" 
    android:textSize="@dimen/slide_title" 
    android:textStyle="bold" 
    android:id="@+id/textView2" 
    android:layout_above="@+id/textView" 
    android:layout_centerHorizontal="true" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="@dimen/desc_padding" 
    android:paddingRight="@dimen/desc_padding" 

    android:textAlignment="center" 
    android:textColor="@android:color/white" 
    android:textSize="@dimen/slide_desc" 
    android:id="@+id/textView" 
    android:layout_marginBottom="80dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="300dp" 
    android:layout_height="300dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="27dp" 
    android:id="@+id/mWebView" /> 

+0

tools:context=".MainActivityを追加activity_main'レイアウトを直接、または ''レイアウトに配置します。 –

+0

@Electric VoidあなたのXMLを投稿 –

+0

レイアウトのxmlを追加しますか? – W4R10CK

答えて

0

ある[更新] ` は` IDで `mWebView`は`していないように思わルートレイアウト

+0

私はすでにそれを試しました –

+0

これをあなたのルートレベルレイアウトに追加します 'tools:context ="。MainActivity "' –

関連する問題