0

我正在尝试构建一个活动,其中列表视图中的每个列表项都会打开一个新活动。但是每次我运行该应用程序时,它都会被迫关闭。请帮助guyzz。我为此努力了很长时间!这是布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="C++ PROGRAMS" 
    android:textStyle="bold"
    android:textSize="25sp" />
<ListView
  android:id="@android:id/list"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >

这是java类:

public class Second_listview extends ListActivity{
  static final String[] type = new String[]{

    "Array", "Strings" 

 };

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

    setContentView(R.layout.second_listview);

    // setting up list view

    setListAdapter (new ArrayAdapter<String>(this, android.R.id.list, type));
    ListView list = getListView();
    list.setTextFilterEnabled(true);
    list.setOnItemClickListener(new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

            //linking each list item to start a new activity

            switch(arg2)

            {
              case 1 : Intent myIntent1 = new Intent(view.getContext(), Array_list.class);
                       startActivityForResult(myIntent1, 0);
                       break;
              case 2 : Intent myIntent2 = new Intent(view.getContext(), String_list.class);
                       startActivityForResult(myIntent2, 0);
                       break;

            }

        }



    });
}

}

这是日志猫:

01-19 13:26:03.123: E/AndroidRuntime(1323): FATAL EXCEPTION: Thread-132
01-19 13:26:03.123: E/AndroidRuntime(1323): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.c_progams.CLEARSCREEN }
01-19 13:26:03.123: E/AndroidRuntime(1323):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
01-19 13:26:03.123: E/AndroidRuntime(1323):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-19 13:26:03.123: E/AndroidRuntime(1323):     at android.app.Activity.startActivityForResult(Activity.java:3370)
01-19 13:26:03.123: E/AndroidRuntime(1323):     at android.app.Activity.startActivityForResult(Activity.java:3331)
01-19 13:26:03.123: E/AndroidRuntime(1323):     at android.app.Activity.startActivity(Activity.java:3566)
01-19 13:26:03.123: E/AndroidRuntime(1323):     at android.app.Activity.startActivity(Activity.java:3534)
01-19 13:26:03.123: E/AndroidRuntime(1323):     at com.example.c_progams.First_screen$1.run(First_screen.java:27)

这是清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.c_progams"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.example.c_progams.First_screen"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <activity
        android:name="com.example.c_progams.Second_listview"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.SECOND_LISTVIEW" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

 <activity
        android:name="com.example.c_progams.Array_list"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.ARRAY_LIST" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>


   <activity
        android:name="com.example.c_progams.String_list"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.STRING_LIST" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>



</application>


</manifest>
4

3 回答 3

0

包名称不遵循驼峰式大小写或下划线或连字符。

更改您的包裹名称,例如

package="com.example.cprogams"

参考 :

命名约定

包名称验证

谢谢

于 2013-01-19T14:15:19.660 回答
0

这是正确的代码...

Java Code :

public class Sample extends ListActivity {
static final String[] type = new String[] { "Array", "Strings" };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView list = getListView();
    setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, type));
    list.setTextFilterEnabled(true);
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int arg2, long arg3) {
            switch (arg2) {
            case 1:
                Intent myIntent1 = new Intent(view.getContext(), Array_list.class);
                startActivityForResult(myIntent1, 0);
                break;
            case 2:
                Intent myIntent2 = new Intent(view.getContext(), String_list.class);
                startActivityForResult(myIntent2, 0);
                break;

            }

        }

    });
}

}

在你的 AndroidManifest.xml 中添加这两行<Application> TAG

<application android:theme="@style/AppTheme" android:label="@string/app_name" android:icon="@drawable/ic_launcher"> 

于 2013-01-19T14:11:45.723 回答
0

编辑:忽略我,这是在您使用清单进行编辑之前完成的。

看起来您尚未在AndroidManifest.xml.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.package.name">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Activity1" android:label="@string/app_name"></activity>
        <activity android:name=".Activity2"></activity>
    </application>
    <uses-sdk android:minSdkVersion="4" />
</manifest>
于 2013-01-19T14:12:58.293 回答