我是应用程序开发的新手,我正在使用标签导航应用程序,我的应用程序工作正常,直到我尝试删除模板附带的Foward操作按钮。当我尝试运行我的应用程序并在调试它告诉我主要的FATAL异常后,我立即崩溃。无法启动活动组件信息。如果有人能找到我的错误,我将不胜感激。
我是否应该将我的webview代码放在选项卡1的java类中?我目前在主要活动中有它。我还在调试时添加了错误
MainActivity.java
package com.example.edgar.multiversecorpcomics;
import android.support.design.widget.TabLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "https://www.previewsworld.com/NewReleases?cat=1";
WebView view = (WebView) this.findViewById(R.id.webview);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
//returning the current tabs
switch (position) {
case 0:
tab1 tab1 = new tab1();
return tab1;
case 1:
tab2 tab2 = new tab2();
return tab2;
case 2:
tab3 tab3 = new tab3();
return tab3;
default:
return null;
}
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Weekly";
case 1:
return "Videos";
case 2:
return "Subscribers";
}
return null;
}
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.edgar.multiversecorpcomics.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior=""/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.CoordinatorLayout>
生病包括我的第一个标签,因为我正在努力尝试 当这一切都出错时设置一个webview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/Container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.design.widget.CoordinatorLayout>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</WebView>
</RelativeLayout>
调试错误
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.edgar.multiversecorpcomics, PID: 5460
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class webview
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class webview
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.webview" on path: DexPathList[[zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/base.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.edgar.multiversecorpcomics-oGAyzVox825VJ3WIzvxEsw==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:703)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.edgar.multiversecorpcomics.tab1.onCreateView(tab1.java:19)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2239)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1332)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2034)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:651)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1239)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1087)
E / AndroidRuntime:在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1613) 在android.view.View.measure(View.java:22071) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602) 在android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:713) 在android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90) 在android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1389) 在android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:783) 在android.view.View.measure(View.java:22071) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) 在android.view.View.measure(View.java:22071) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602) 在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514) 在android.widget.LinearLayout.measureVertical(LinearLayout.java:806) 在android.widget.LinearLayout.onMeasure(LinearLayout.java:685) 在android.view.View.measure(View.java:22071) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 在android.view.View.measure(View.java:22071) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602) 在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514) 在android.widget.LinearLayout.measureVertical(LinearLayout.java:806) 在android.widget.LinearLayout.onMeasure(LinearLayout.java:685) 在android.view.View.measure(View.java:22071) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 在com.android.internal.policy.DecorView.onMeasure(DecorView.java:724) 在android.view.View.measure(View.java:22071) 在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2422) 在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1504) 在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761) 在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392) 在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6752) 在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:911) 在android.view.Choreographer.doCallbacks(Choreographer.java:723) 在android.view.Choreographer.doFrame(Choreographer.java:658) 在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:897) 在android.os.Handler.handleCallback(Handler.java:790) 在android.os.Handler.dispatchMessage(Handler.java:99) 在android.os.Looper.loop(Looper.java:164) 在android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 断开与目标VM的连接,地址:&#39; localhost:8600&#39;,transport:&#39; socket&#39;