0
似乎所有的東西好,我的代碼是正確的,但如果午餐應用得到這個消息:無法啓動活動ComponentInfo,並從該行給出的錯誤:webView.findViewById(R.id.webi);
無法啓動活動ComponentInfo的WebView
這是我的活動:
public class MainActivity extends AppCompatActivity {
public WebView webView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
webView.findViewById(R.id.webi);
String sag="google.com";
webView.loadUrl(sag);
}
}
XML佈局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="@+id/webi"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</LinearLayout>
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.erfan.myapplication">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
爲什麼呢?
不敢相信這樣做的錯誤...感謝任何方式。在幾分鐘內接受你的答案 – erfan