1

我整晚都在努力寻找并修复这个错误。我不确定到底是什么导致了这个错误,但是当我尝试运行这个类时我的应用程序崩溃了。我认为这可能与 ListView 或数组有关。

我的 Java 文件:

package com.example.ispoke;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class AustralianAnimalsMenu extends ListActivity{

String AusAnimalItm[] = {"Aus Animal 1", "Aus Animal 2", "Aus Animal 3", "Aus      Animal 4", "Aus Animal 5"}; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_australiananimalsmenu);

    setListAdapter(new ArrayAdapter<String>(AustralianAnimalsMenu.this, android.R.layout.activity_list_item, AusAnimalItm));        
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub

    super.onListItemClick(l, v, position, id);
    String selection = AusAnimalItm[position];
    try{            
    Class<?> ourClass =  Class.forName("com.example.ispoke." + selection);
    Intent ourIntent = new Intent(AustralianAnimalsMenu.this, ourClass);
    startActivity(ourIntent);       
    }catch(ClassNotFoundException ell){
        ell.printStackTrace();
    }
}

}

我的 xml 文件:

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

        <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView1"
        android:text="Done"
        android:textSize="10sp" />

        <TextView
        android:id="@+id/textView1"
        android:layout_width="271dp"
        android:layout_height="31dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:gravity="center_horizontal"
        android:text="Australian Animals"
        android:textSize="25sp" />
</RelativeLayout>

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="369dp"
    android:layout_weight="1.06" >
</ListView>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="34dp"
    android:gravity="bottom"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Edit"
        android:textSize="15sp" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Delete"
        android:textSize="15sp" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="+"
        android:textSize="20sp" />
</RelativeLayout>

错误堆栈:

Thread [<1> main] (Suspended (exception IllegalStateException)) 
<VM does not provide monitor information>   
ListView.layoutChildren() line: 1662    
ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1147  
ListView(View).layout(int, int, int, int) line: 7035    
LinearLayout.setChildFrame(View, int, int, int, int) line: 1249 
LinearLayout.layoutVertical() line: 1125    
LinearLayout.onLayout(boolean, int, int, int, int) line: 1042   
LinearLayout(View).layout(int, int, int, int) line: 7035    
FrameLayout.onLayout(boolean, int, int, int, int) line: 333 
FrameLayout(View).layout(int, int, int, int) line: 7035 
LinearLayout.setChildFrame(View, int, int, int, int) line: 1249 
LinearLayout.layoutVertical() line: 1125    
LinearLayout.onLayout(boolean, int, int, int, int) line: 1042   
LinearLayout(View).layout(int, int, int, int) line: 7035    
PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333  
PhoneWindow$DecorView(View).layout(int, int, int, int) line: 7035   
ViewRoot.performTraversals() line: 1045 
ViewRoot.handleMessage(Message) line: 1727  
ViewRoot(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 4627    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line:  
    not available [native method]
    Method.invoke(Object, Object...) line: 521

    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    ZygoteInit.main(String[]) line: 626 
    NativeStart.main(String[]) line: not available [native method]  
4

0 回答 0