(WebView)java.lang.runtimeexception无法启动活动

(WebView)java.lang.runtimeexception无法启动活动,java,android,android-webview,runtimeexception,Java,Android,Android Webview,Runtimeexception,我正在创建一个android应用程序,它使用webview打开一个网页,但在运行时我遇到了一个错误。这是移动js页面,我想在其中打开webview 日志目录: 06-19 00:44:25.756: I/Process(1130): Sending signal. PID: 1130 SIG: 9 06-19 00:46:45.136: D/AndroidRuntime(1156): Shutting down VM 06-19 00:46:45.136: W/dalvi

我正在创建一个android应用程序,它使用webview打开一个网页,但在运行时我遇到了一个错误。这是移动js页面,我想在其中打开webview

日志目录:

    06-19 00:44:25.756: I/Process(1130): Sending signal. PID: 1130 SIG: 9
    06-19 00:46:45.136: D/AndroidRuntime(1156): Shutting down VM
    06-19 00:46:45.136: W/dalvikvm(1156): threadid=1: thread exiting with uncaught exception (group=0xb4a48ba8)
    06-19 00:46:45.156: E/AndroidRuntime(1156): FATAL EXCEPTION: main
    06-19 00:46:45.156: E/AndroidRuntime(1156): Process: com.example.dynakodetechnologypvt.ltd, PID: 1156
    06-19 00:46:45.156: E/AndroidRuntime(1156): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dynakodetechnologypvt.ltd/com.example.dynakodetechnologypvt.ltd.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.os.Handler.dispatchMessage(Handler.java:102)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.os.Looper.loop(Looper.java:136)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.ActivityThread.main(ActivityThread.java:5017)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at java.lang.reflect.Method.invokeNative(Native Method)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at java.lang.reflect.Method.invoke(Method.java:515)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at dalvik.system.NativeStart.main(Native Method)
    06-19 00:46:45.156: E/AndroidRuntime(1156): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at com.example.dynakodetechnologypvt.ltd.MainActivity.onCreate(MainActivity.java:19)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.Activity.performCreate(Activity.java:5231)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
    06-19 00:46:45.156: E/AndroidRuntime(1156):     ... 11 more
主要活动

@SuppressLint("SetJavaScriptEnabled") 
public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
        String url = "http://www.google.com";

        WebView view =   (WebView) this.findViewById(R.id.webView1);
        view.getSettings().setJavaScriptEnabled(true);
        view.loadUrl(url);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}
Android清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dynakodetechnologypvt.ltd"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <activity
            android:name="com.example.dynakodetechnologypvt.ltd.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


如何解决此问题请帮助

操作活动
需要一个扩展自
主题的主题。AppCompat
,否则您的应用程序将因此错误而崩溃:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
因此,在清单文件中,使用带有MainActivity的新主题

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dynakodetechnologypvt.ltd"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <activity
            android:name="com.example.dynakodetechnologypvt.ltd.MainActivity"
            android:label="@string/app_name" 
            android:theme="@style/AppTheme.AppCompat"> //Add here
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
对于api 7-10,您需要使用相同的样式。它将位于res/values/styles.xml,但由于api级别尚不了解原始android actionbar样式项,因此我们应该使用支持库提供的一个。ActionBar Compat项的定义与原始android相同,但前面没有“android:”部分:

<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
    <!-- Setting values in the default namespace affects API levels 7-11 -->
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- Setting values in the default namespace affects API levels 7-11 -->
    <item name="background">@drawable/ab_custom_solid_styled</item>
    <item name="backgroundStacked">@drawable/ab_custom_stacked_solid_styled</item>
    <item name="backgroundSplit">@drawable/ab_custom_bottom_solid_styled</item>
</style>

@style/Widget.Styled.ActionBar
@可拉伸/ab_定制_实心_样式
@可拉伸/ab_定制_堆叠_实心_样式
@可拉伸/ab_定制_底部_实心_样式

有关更多信息,请参见

您是否检查了异常?您需要在此活动中使用Theme.AppCompat主题(或子代)。我正在更改主题的可能重复bt错误仍然是检查您导入的
ActionBarActivity
。它应该使用“支持库”`
<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
    <!-- Setting values in the default namespace affects API levels 7-11 -->
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- Setting values in the default namespace affects API levels 7-11 -->
    <item name="background">@drawable/ab_custom_solid_styled</item>
    <item name="backgroundStacked">@drawable/ab_custom_stacked_solid_styled</item>
    <item name="backgroundSplit">@drawable/ab_custom_bottom_solid_styled</item>
</style>