0

我有一个扩展为 BaseAdapter 的适配器类,它通过意图启动另一个活动。另一个活动给了我错误:

10-10 23:58:57.171: E/AndroidRuntime(3651): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.migdinny.passman/com.migdinny.passman.DataActivity}: java.lang.NullPointerException

...

10-10 23:58:57.171: E/AndroidRuntime(3651): Caused by: java.lang.NullPointerException
10-10 23:58:57.171: E/AndroidRuntime(3651):     at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
10-10 23:58:57.171: E/AndroidRuntime(3651):     at com.migdinny.passman.DataActivity.onCreate(DataActivity.java:20)

这是代码:

开始新活动的代码(这是在一个新的监听器中)

            @Override
        public void onClick(View view) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(context, DataActivity.class);
            intent.putExtra("category", category);
            context.startActivity(intent);
        }

此代码是由上述代码启动的新活动

public class DataActivity extends ActionBarActivity {

String category;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); // i've tried this line on all places and it doesnt fix the problem, after the setcontentview, before, etc
    Intent intent = getIntent(); // this works

    category = intent.getExtras().getString("category"); // this exists 

    setContentView(R.layout.activity_data); // THIS IS THE LINE 20 OF DATA ACTIVITY and of course that the activity_data layout exists. the eclipse does not warn me anything.

}
........

编辑:

这是activity_data.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
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="com.migdinny.passman.DataActivity" >

<TextView
    android:id="@+id/test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
/>
</RelativeLayout>

onClick 上使用的类别变量:

final String category = list.get(position).getCatname(); // on the beginning of getView method and i think the error is not here
4

1 回答 1

0

你有任何自定义主题吗?我记得在某个地方读过一个与问题相关并且与思想有关的人,如果您尝试将其删除以查看它是否相关(值得一试)

于 2014-10-11T20:53:33.847 回答