0

我试图在文本视图中显示一些我从 SQLite 数据库中提取的变量。它可以正常工作并显示信息,但是当它加载 logcati 单击 textview 时,它会崩溃并引发异常。

这是日志:

05-04 19:25:32.456: I/AtaquesAdapter(466): OPening DataBase Connection....
05-04 19:25:34.625: W/ResourceType(466): Too many attribute references, stopped at: 0x010102c5
05-04 19:25:34.625: W/ResourceType(466): Too many attribute references, stopped at: 0x010102c6
05-04 19:25:34.625: W/ResourceType(466): Too many attribute references, stopped at: 0x010102c7
05-04 19:25:34.635: W/ResourceType(466): Too many attribute references, stopped at: 0x010102c5
05-04 19:25:34.635: W/ResourceType(466): Too many attribute references, stopped at: 0x010102c6
05-04 19:25:34.635: W/ResourceType(466): Too many attribute references, stopped at: 0x010102c7
05-04 19:25:36.566: W/ResourceType(466): No package identifier when getting value for resource number 0x00000000
05-04 19:25:36.566: D/AndroidRuntime(466): Shutting down VM
05-04 19:25:36.566: W/dalvikvm(466): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-04 19:25:36.596: E/AndroidRuntime(466): FATAL EXCEPTION: main
05-04 19:25:36.596: E/AndroidRuntime(466): android.content.res.Resources$NotFoundException: Resource ID #0x0
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.content.res.Resources.getValue(Resources.java:892)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.content.res.Resources.getDrawable(Resources.java:580)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.widget.TextView$HandleView.setOrientation(TextView.java:7801)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.widget.TextView$HandleView.<init>(TextView.java:7770)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.widget.TextView$InsertionPointCursorController.<init>(TextView.java:8006)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.widget.TextView.getInsertionController(TextView.java:8351)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.widget.TextView.onTouchEvent(TextView.java:6829)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.view.View.dispatchTouchEvent(View.java:3885)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
05-04 19:25:36.596: E/AndroidRuntime(466):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
05-04 19:25:36.596: E/AndroidRuntime(466):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
05-04 19:25:36.596: E/AndroidRuntime(466):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.os.Looper.loop(Looper.java:130)
05-04 19:25:36.596: E/AndroidRuntime(466):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-04 19:25:36.596: E/AndroidRuntime(466):  at java.lang.reflect.Method.invokeNative(Native Method)
05-04 19:25:36.596: E/AndroidRuntime(466):  at java.lang.reflect.Method.invoke(Method.java:507)
05-04 19:25:36.596: E/AndroidRuntime(466):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-04 19:25:36.596: E/AndroidRuntime(466):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-04 19:25:36.596: E/AndroidRuntime(466):  at dalvik.system.NativeStart.main(Native Method)

这是xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ataque_description_text"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:longClickable="false"
    android:padding="16dp"
    android:textSize="20sp" >
</TextView>

我尝试使用和不使用这些句子:

 android:clickable="false"  
 android:focusable="false"  
 android:focusableInTouchMode="false"  
 android:longClickable="false"  

这是有问题的代码:

public class AtaqueDescription extends Activity implements OnClickListener {
long ataque_id;
String ataque_nombre;
String ataque_dano;
String ataque_tipo;
String ataque_velocidad;

CharSequence description;

public static TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 // AT THIS POINT THE APP THROWS THE WARNINGS FOR THE FIRST TIME
        setContentView(R.layout.ataques_description);
 // AT THIS POINT THE APP THROWS THE WARNINGS AGAIN
        Bundle extras = getIntent().getExtras();

        ataque_id = extras.getLong(DBHelper.COLUMNA_ID);
        ataque_nombre = extras.getString(DBHelper.COLUMNA_NOMBRE);
        ataque_dano = extras.getString(DBHelper.COLUMNA_DANO);
        ataque_tipo = extras.getString(DBHelper.COLUMNA_TIPO);
        ataque_velocidad = extras.getString(DBHelper.COLUMNA_VELOCIDAD);

        description = ataque_nombre + " con id: " + ataque_id + ", con tipo: " 
            + ataque_tipo + ", con daño: " + ataque_dano + ", con velocidad: " 
            + ataque_velocidad;
        tv = (TextView)findViewById(R.id.ataque_description_text);

        tv.setText(description.toString());

        tv.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();           
        }
        });
}

public void onClick(View v) {
    finish();
}
}

我尝试使用和不使用这些句子:

.toString()       [in  tv.setText(description.toString());]

 tv.setOnClickListener(new OnClickListener() {  
  public void onClick(View v) {  
   finish();            
  }  
 });  

 public void onClick(View v) {  
   finish();
 }

这是调用有问题的代码的代码:

public class Ataques extends ListActivity {

@SuppressWarnings("unused")
private static final String TAG = "Ataques";

AtaquesAdapter attTable;
ListView attListView;
Cursor c;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.ataques_list);

    attTable = new AtaquesAdapter();
    attTable.open(getApplicationContext());

    c = attTable.getAllAtaques();

    startManagingCursor(c);

    if (c != null) {
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                R.layout.ataques_row, c,
                new String[] { c.getColumnName(1) },
                new int[] { R.id.ataque });
        setListAdapter(adapter);
    }
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    c.moveToPosition(position);

    Intent i = new Intent(this, AtaqueDescription.class);
    i.putExtra(DBHelper.COLUMNA_ID, id);
    i.putExtra(DBHelper.COLUMNA_NOMBRE, c.getString(c.getColumnIndexOrThrow(DBHelper.COLUMNA_NOMBRE)));
    i.putExtra(DBHelper.COLUMNA_DANO, c.getString(c.getColumnIndexOrThrow(DBHelper.COLUMNA_DANO)));
    i.putExtra(DBHelper.COLUMNA_TIPO,   c.getString(c.getColumnIndexOrThrow(DBHelper.COLUMNA_TIPO)));
    i.putExtra(DBHelper.COLUMNA_VELOCIDAD,  c.getString(c.getColumnIndexOrThrow(DBHelper.COLUMNA_VELOCIDAD)));
    startActivity(i);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    c.close();
    attTable.close();
}

}

更详细的解释:

  1. 如您所见,我也有一些警告问题。两次抛出相同的 3 个警告。我已经在代码中标记了程序抛出它们的位置。
  2. [已修复] 我的主要问题是崩溃。代码似乎工作正常,它显示了带有正确变量的文本视图(从 SQLite 数据库中提取的变量并通过捆绑的附加功能在活动之间发送)。但是,当您单击此布局中屏幕的任何点时,程序会抛出 android.content.res.Resources$NotFoundException: Resource ID #0x0
    我尝试了许多变体(其中大部分都在此处注释,在我所在的代码下方尝试过 thouse 变体),但任何 thouse 似乎都对代码的行为有任何影响。
    将模拟器的 API 版本从 10 更改为 16 后,该异常似乎已修复。

我还试图将调用者简化为:

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
        Intent i = new Intent(this, AtaqueDescription.class);
        startActivity(i);
    }
}

以及有问题的代码:

public class AtaqueDescription extends Activity implements OnClickListener {
public static TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.ataques_description);
        tv = (TextView)findViewById(R.id.ataque_description_text);    
        tv.setText("hello");
    }
}

但是,警告和异常仍然在发生。

谢谢你们的时间!

编辑:在将模拟器的 API 版本从 10 更改为 16 后,该异常似乎已修复。
但警告仍然存在,如果有人能帮助我,我将不胜感激。

4

1 回答 1

-1

问题是由我使用的模拟器引起的,api版本为10而不是16。警告仍未解决。感谢大家对评论的帮助。

于 2013-05-06T11:46:23.297 回答