我的应用程序一直在崩溃

时间:2016-06-29 14:01:01

标签: android

我正在进行关于udacity的android开发课程,但我的应用程序一直在崩溃。

主要活动片段

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

public MainActivityFragment() {
}

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

    String[] data = {
            "Mon 6/23 - Sunny - 31/17",
            "Tue 6/24 - Foggy - 21/8",
            "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11",
            "Fri 6/27 - Foggy - 21/10",
            "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18",
            "Sun 6/29 - Sunny - 20/7"
    };
    List<String> weekForecast = new ArrayList<String>(Arrays.asList(data));
    ArrayAdapter<String> mForecatAddapter = new ArrayAdapter<String>(getActivity(),
            R.layout.list_item_forecast, R.id.list_item_forecast_textview, weekForecast);


    ListView listView =  (ListView) rootView.findViewById(R.id.list_item_forecast_textview);
    listView.setAdapter(mForecatAddapter);

    return rootView;
}
}

主要活动

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


}

@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);
}
}

fragment_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
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"
tools:context="finalsunshine.sunshine.MainActivityFragment"
tools:showIn="@layout/activity_main">

<ListView
    android:id="@+id/list_item_forecast_textview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

content_main.xml

<fragment 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/fragment"
android:name="finalsunshine.sunshine.MainActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:layout="@layout/fragment_main" />

list_item_forecast.xml

<?xml version="1.0" encoding="utf-8"?>
<textview xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:id="@+id/list_item_forecast_textview">
</textview>

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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="finalsunshine.sunshine.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

android manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="finalsunshine.sunshine">

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

有人可以告诉我问题在哪里吗?

06-29 19:26:58.474 20172-20172/? I/art: Late-enabling -Xcheck:jni
06-29 19:26:58.589 20172-20172/finalsunshine.sunshine W/ActivityThread: Application finalsunshine.sunshine can be debugged on port 8100...
06-29 19:26:58.826 20172-20172/finalsunshine.sunshine W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
06-29 19:26:58.910 20172-20198/finalsunshine.sunshine D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-29 19:26:58.925 20172-20172/finalsunshine.sunshine D/Atlas: Validating map...
06-29 19:26:59.014 20172-20198/finalsunshine.sunshine I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016_msm8610_LA.BF.1.1.1_RB1__release_AU ()
                                                                    OpenGL ES Shader Compiler Version: E031.25.03.00
                                                                    Build Date: 02/11/15 Wed
                                                                    Local Branch: 
                                                                    Remote Branch: quic/LA.BF.1.1.1_rb1.10
                                                                    Local Patches: NONE
                                                                    Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016 + 62ca4eb + acd831d + 9f8b442 + e027a02 + cba30ba + 53c303a + a649d79 + 23e16f8 + 5e97da7 + cbd2a44 + 33d072a + 7aacf06 + 72b33e7 + 28f6f60 + b4c13d8 +  NOTHING
06-29 19:26:59.015 20172-20198/finalsunshine.sunshine I/OpenGLRenderer: Initialized EGL, version 1.4
06-29 19:26:59.069 20172-20198/finalsunshine.sunshine D/OpenGLRenderer: Enabling debug mode 0
06-29 19:26:59.108 20172-20172/finalsunshine.sunshine D/AndroidRuntime: Shutting down VM
06-29 19:26:59.121 20172-20172/finalsunshine.sunshine E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: finalsunshine.sunshine, PID: 20172
                                                                        android.view.InflateException: Binary XML file line #2: Error inflating class textview
                                                                            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                                                                            at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:371)
                                                                            at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
                                                                            at android.widget.AbsListView.obtainView(AbsListView.java:2347)
                                                                            at android.widget.ListView.makeAndAddView(ListView.java:1864)
                                                                            at android.widget.ListView.fillDown(ListView.java:698)
                                                                            at android.widget.ListView.fillFromTop(ListView.java:759)
                                                                            at android.widget.ListView.layoutChildren(ListView.java:1673)
                                                                            at android.widget.AbsListView.onLayout(AbsListView.java:2151)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                            at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122)
                                                                            at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                            at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1170)
                                                                            at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:814)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                            at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                                                                            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                                                                            at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                            at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                                                                            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                                                                            at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                            at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                            at android.view.View.layout(View.java:15689)
                                                                            at android.view.ViewGroup.layout(ViewGroup.java:5040)
                                                                            at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2116)
                                                                            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1873)
                                                                            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1084)
                                                                            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5990)
                                                                            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
                                                                            at android.view.Choreographer.doCallbacks(Choreographer.java:580)
                                                                            at android.view.Choreographer.doFrame(Choreographer.java:550)
                                                                            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
                                                                            at android.os.Handler.handleCallback(Handler.java:739)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                            at android.os.Looper.loop(Looper.java:135)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5343)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
                                                                        Caused

1 个答案:

答案 0 :(得分:1)

list_item_forecast.xml文件中的

textview应为TextView

我在你的ErrorLog中看到它。你应该尝试阅读它并理解错误 - 每次写这里都会容易得多。