无法处理我的模拟器上的CheckData按钮

时间:2012-05-10 09:14:43

标签: android

当我点击模拟器上的CheckData按钮时显示

> error:  android.content.ActivityNotFoundException: Unable to find
> explicit activity class {app.login/app.login.DatabaseSample}; have you
> declared this activity in your AndroidManifest.xml?

但我在android mnaifest.xml中声明为

 package="app.login"<application
        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"            android:name=".LoginappActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".SaveData"> </activity>
        <activity android:name=".CheckData"></activity>
        <activity android:name=".DatabaseSample"> </activity>

    </application>

这是我的CheckData.java文件

public class CheckData extends ListActivity  {     
    TextView selection;
    public int idToModify; 
    DataManipulator dm;

    List<String[]> names1 =null ;
    String[] stg1;
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.check);
          dm = new DataManipulator(this);
          names1 = dm.selectAll();

        stg1=new String[names1.size()]; 

        String stg;

        for (String[] name : names1) {stg = name[1];
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(   
                this,android.R.layout.simple_list_item_1,stg1);
        this.setListAdapter(adapter);
        selection=(TextView)findViewById(R.id.selection);

    }      

    public void onListItemClick(ListView parent, View v, int position, long id) {
        selection.setText(stg1[position]);
    }
}

Logcat是

05-10 12:42:03.292: E/AndroidRuntime(606): FATAL EXCEPTION: main
05-10 12:42:03.292: E/AndroidRuntime(606): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.login/app.login.DatabaseSample}: java.lang.NullPointerException
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.os.Looper.loop(Looper.java:137)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-10 12:42:03.292: E/AndroidRuntime(606):  at java.lang.reflect.Method.invokeNative(Native Method)
05-10 12:42:03.292: E/AndroidRuntime(606):  at java.lang.reflect.Method.invoke(Method.java:511)
05-10 12:42:03.292: E/AndroidRuntime(606):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-10 12:42:03.292: E/AndroidRuntime(606):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-10 12:42:03.292: E/AndroidRuntime(606):  at dalvik.system.NativeStart.main(Native Method)
05-10 12:42:03.292: E/AndroidRuntime(606): Caused by: java.lang.NullPointerException
05-10 12:42:03.292: E/AndroidRuntime(606):  at app.login.DatabaseSample.onCreate(DatabaseSample.java:16)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.Activity.performCreate(Activity.java:4465)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-10 12:42:03.292: E/AndroidRuntime(606):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-10 12:42:03.292: E/AndroidRuntime(606):  ... 11 more
不幸的是,在模拟器上

显示loginapp已停止

这是我的DatabaseSample.java文件

public class DatabaseSample extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        View button1Click = findViewById(R.id.Button01add);
        button1Click.setOnClickListener(this);
        View button2Click = findViewById(R.id.Button01home);
        button2Click.setOnClickListener(this);        

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){

        case R.id.Button01add:
            Intent i = new Intent(this, SaveData.class);  
            startActivity(i);
            break;
        case R.id.Button01home:
            Intent i1 = new Intent(this, CheckData.class);  
            startActivity(i1);
            break;

        }
    }
}

1 个答案:

答案 0 :(得分:2)

在你的Logcat中,这显示DatabaseSample活动,这意味着你正在尝试打开DatabaseSample,而未在Manifest中声明,

另一方面,你说你的意图是打开CheckData活动。

如果您在Activity的{​​{1}}内打开正确的onClick(),请检查一下。

似乎您正在从一个样本开发项目,其中ButtonDatabaseSample,在进行更改时,您从清单中删除了Activity而没有从Java代码中删除,这就是为什么它没有给你任何编译时错误。