Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
活动和android清单_Android - Fatal编程技术网

活动和android清单

活动和android清单,android,Android,我创建了一个活动,它将我的所有活动保存在一个列表中,并在android清单中声明它们。但我一直收到一个错误“找不到类异常”。不知道该怎么办。下面是代码和android清单 package com.activityexample.cookbook; import android.app.ListActivity; import android.app.SearchManager; import android.content.Intent; import android.net.Uri; imp

我创建了一个活动,它将我的所有活动保存在一个列表中,并在android清单中声明它们。但我一直收到一个错误“找不到类异常”。不知道该怎么办。下面是代码和android清单

package com.activityexample.cookbook;

import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class ExtendsListActivity extends ListActivity implements OnItemClickListener{
    static final String[] Possible_Choices = new String[]{
        "Open Website Example",
        "Open Contacts",
        "Open Dialer",
        "Search Google Example",
        "Start Voice Command"
    };

final String searchTerms="supeman";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,Possible_Choices));
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        getListView().setTextFilterEnabled(true);
        getListView().setOnItemClickListener(this);
        //getListView().setOnItemClickListener(new OnItemClickListener() {
    //  });
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        switch (arg2){
        case 0:
            startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com/")));
            break;
        case 1:
            startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("content://contacts/people/")));
            break;

        case 2:
            startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("tel://08160212611/")));
            break;

        case 3:
            Intent i = new Intent(Intent.ACTION_WEB_SEARCH);
            i.putExtra(SearchManager.QUERY, searchTerms);
            startActivity(i);
            break;
        case 4:
            startActivity(new Intent(Intent.ACTION_VOICE_COMMAND));
            break;
            default: break;
        }

    }





}




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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:maxSdkVersion="19" android:name="android.permission.READ_CONTACTS"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".TheMenu"
            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=".ActivityEx"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.activityexample.cookbook.ActivityEx" />
                <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
        </activity>

        <activity
            android:name=".ExtendsListActivity"
            android:label="@string/app_name" >
        </activity>

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>
package com.activityexample.cookbook;
导入android.app.ListActivity;
导入android.app.SearchManager;
导入android.content.Intent;
导入android.net.Uri;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.ArrayAdapter;
导入android.widget.ListAdapter;
导入android.widget.ListView;
公共类ExtendListActivity扩展ListActivity实现了一个新的ListListener{
静态最终字符串[]可能的_选项=新字符串[]{
“开放网站示例”,
“开放联系人”,
“开放拨号器”,
“搜索谷歌示例”,
“启动语音命令”
};
最终字符串searchTerms=“supeman”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setListAdapter(新的ArrayAdapter(这个,android.R.layout.simple_list_item_1,可能的_选项));
getListView().setChoiceMode(ListView.CHOICE\u MODE\u MULTIPLE);
getListView().setTextFilterEnabled(true);
getListView().setOnItemClickListener(此);
//getListView().setOnItemClickListener(新的OnItemClickListener()){
//  });
}
@凌驾
公共视图单击(AdapterView arg0、视图arg1、整型arg2、长型arg3){
//TODO自动生成的方法存根
开关(arg2){
案例0:
startActivity(新的意图(Intent.ACTION\u视图,Uri.parse()http://www.google.com/")));
打破
案例1:
startActivity(新的意图(Intent.ACTION\u视图,Uri.parse()content://contacts/people/")));
打破
案例2:
startActivity(新的意图(Intent.ACTION\u视图,Uri.parse()tel://08160212611/")));
打破
案例3:
意向i=新意向(意向、行动、网络搜索);
i、 putExtra(SearchManager.QUERY,searchTerms);
星触觉(i);
打破
案例4:
startActivity(新意图(意图、动作、声音、命令));
打破
默认:中断;
}
}
}

在没有看到具体错误的情况下,看起来这不是您期望的错误。看起来Android正试图在功能表中启动您的“主要”活动,但您尚未创建该活动。如果你没有,不要申报。然后您可能应该修改清单,以使ExtendListActivity成为主要功能:

<activity
     android:name=".ExtendsListActivity"
     android:label="@string/app_name" >
     <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />  
     </intent-filter>
</activity>

如果未在清单中声明活动,将出现下一个错误:

找不到[活动名称]。您是否在您的文档中声明了该活动 安卓清单


java.lang.ClassNotFoundException
通常发生在您缺少jar文件,或者在XML文件中为自定义视图声明了错误的包名时,比如guy。

请发布您的日志