在Android中单击文本视图时获取“android:resources not found exception”

时间:2013-05-05 01:07:39

标签: android sqlite exception onclick textview

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

这是logcat:

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. [固定]我的主要麻烦在于崩溃。代码似乎工作正常,它显示了带有正确变量的textview(从SQLite数据库中提取的变量,并通过bundle&#39s的附加功能在活动之间发送)。但是当你在这个布局中单击屏幕的任何一点时,程序会抛出一个android.content.res.Resources $ NotFoundException:资源ID#0x0
    我尝试了很多变化(大多数都在这里评论,在我尝试变种的代码下面),但是任何一个似乎都对代码的行为有任何不同。
    将模拟器的API版本从10更改为16后,似乎修复了异常。
  3. 我还试图将调用者简化为:

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

    但两者,警告和异常仍在发生。

    Thanx适合你的时间!

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

1 个答案:

答案 0 :(得分:-1)

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