问题是,每当我尝试打开numberactivity文件时,应用都会停止工作并出现以下错误(我是初学者)
这是NumberActivity.java文件
package com.example.android.miwok;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class NumberActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_number);
ArrayList<word> words;
words = new ArrayList<word>();;
words.add(new word("one", "lutti"));
words.add(new word("two", "otiiko"));
words.add(new word("three", "tolookosu"));
words.add(new word("four", "oyyisa"));
words.add(new word("five", "massokka"));
words.add(new word("six", "temmokka"));
words.add(new word("seven", "kenekaku"));
words.add(new word("eight", "kawinta"));
words.add(new word("nine", "wo’e"));
words.add(new word("ten", "na’aacha"));
WordAdapter wordAdapter = new WordAdapter(this,words);
ListView listView = (ListView)findViewById(R.id.list);
listView.setAdapter(wordAdapter);
}
}
这是我用来创建自定义arrayadapter的WordAdapter文件
package com.example.android.miwok;
import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
public class WordAdapter extends ArrayAdapter<word> {
public WordAdapter(Activity context, ArrayList<word> wordadapter){
super(context,0,wordadapter);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return super.getView(position, convertView, parent);
}
}
enter code here
这是我无法理解问题所在的LogCat
08-14 09:03:39.816 11409-11409/com.example.android.miwok D/AndroidRuntime: Shutting down VM
08-14 09:03:39.817 11409-11409/com.example.android.miwok E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.miwok, PID: 11409
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2094)
at android.content.res.Resources.getLayout(Resources.java:1111)
at android.view.LayoutInflater.inflate(LayoutInflater.java:424)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:380)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:371)
at com.example.android.miwok.WordAdapter.getView(WordAdapter.java:21)
at android.widget.AbsListView.obtainView(AbsListView.java:2362)
at android.widget.ListView.makeAndAddView(ListView.java:1970)
at android.widget.ListView.fillDown(ListView.java:704)
at android.widget.ListView.fillFromTop(ListView.java:765)
at android.widget.ListView.layoutChildren(ListView.java:1744)
at android.widget.AbsListView.onLayout(AbsListView.java:2161)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:724)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2342)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2069)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
08-14 09:03:39.829 1752-2039/system_process W/ActivityManager: Force finishing activity com.example.android.miwok/.NumberActivity
08-14 09:03:39.842 1752-2039/system_process W/ActivityManager: Force finishing activity com.example.android.miwok/.MainActivity