当前位置: 首页 > 知识库问答 >
问题:

Android:丢失package语句;活动类不存在

柴亦
2023-03-14

我得到的信息是:缺少package语句。这是红色的:

这是一个简单的项目,

从自动完成文本视图中选择联系人

Launching application: com.example.chris.autocompletetextview/ContactWithAuto.
DEVICE SHELL COMMAND: am start -n "com.example.chris.autocompletetextview/ContactWithAuto" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
open: Permission denied
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.chris.autocompletetextview/ContactWithAuto }
Error type 3
Error: Activity class {com.example.chris.autocompletetextview/ContactWithAuto} does not exist.

下面是我的代码:

ContactWithAuto.java:

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.SimpleAdapter;

import com.example.chris.autocompletetextview.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class ContactWithAuto extends Activity {

    private ArrayList<Map<String, String>> mPeopleList;
    private SimpleAdapter mAdapter;
    private AutoCompleteTextView mTxtPhoneNo;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact_with_auto);
        mPeopleList = new ArrayList<Map<String, String>>();
        PopulatePeopleList();
        mTxtPhoneNo = (AutoCompleteTextView) findViewById(R.id.mmWhoNo);
        mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.custcontview,
                new String[] { "Name", "Phone", "Type" }, new int[] {
                R.id.ccontName, R.id.ccontNo, R.id.ccontType });
        mTxtPhoneNo.setAdapter(mAdapter);

    }

    public void PopulatePeopleList() {
        mPeopleList.clear();
        Cursor people = getContentResolver().query(
                ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        while (people.moveToNext()) {
            String contactName = people.getString(people
                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            String contactId = people.getString(people
                    .getColumnIndex(ContactsContract.Contacts._ID));
            String hasPhone = people
                    .getString(people
                            .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

            if ((Integer.parseInt(hasPhone) > 0)){
                // You know have the number so now query it like this
                Cursor phones = getContentResolver().query(
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,
                        null, null);
                while (phones.moveToNext()){
                    //store numbers and display a dialog letting the user select which.
                    String phoneNumber = phones.getString(
                            phones.getColumnIndex(
                                    ContactsContract.CommonDataKinds.Phone.NUMBER));
                    String numberType = phones.getString(phones.getColumnIndex(
                            ContactsContract.CommonDataKinds.Phone.TYPE));
                    Map<String, String> NamePhoneType = new HashMap<String, String>();
                    NamePhoneType.put("Name", contactName);
                    NamePhoneType.put("Phone", phoneNumber);
                    if(numberType.equals("0"))
                        NamePhoneType.put("Type", "Work");
                    else
                    if(numberType.equals("1"))
                        NamePhoneType.put("Type", "Home");
                    else if(numberType.equals("2"))
                        NamePhoneType.put("Type",  "Mobile");
                    else
                        NamePhoneType.put("Type", "Other");
                    //Then add this map to the list.
                    mPeopleList.add(NamePhoneType);
                }
                phones.close();
            }
        }
        people.close();
        startManagingCursor(people);
    }

    public void onItemClick(AdapterView<?> av, View v, int index, long arg){
        Map<String, String> map = (Map<String, String>) av.getItemAtPosition(index);
        Iterator<String> myVeryOwnIterator = map.keySet().iterator();
        while(myVeryOwnIterator.hasNext()) {
            String key=(String)myVeryOwnIterator.next();
            String value=(String)map.get(key);
            mTxtPhoneNo.setText(value);
        }
    }

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        getMenuInflater().inflate(R.menu.activity_contact_with_auto, menu);
//        return true;
//    }
}

清单:

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

    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="ContactWithAuto"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

共有1个答案

夏骏
2023-03-14

在您的ContactWithAuto.java顶部添加这一行

package com.example.chris.autocompletetextview;

缺少包行。

 类似资料:
  • 我最近升级到Android Studio1.5,现在我试图运行或调试的每个项目都显示,活动类不存在。下面列出了我尝试过但失败的解决方案。 清洁构建 重命名活动类 重新启动IDE 升级到Android Studio 2.0预览版 安装新的生成工具

  • 我正在尝试整合react原生和原生android应用程序。 apps build.gradle 中的 applicationId is manifest标签中的包是。 SplashActivity.kt 中的第 1 行是 活动清单如下所示: 跟随RN官方文档后,当我尝试通过< code > react-native run-Android-appId RCM . samapp-main-activ

  • 我有一个具有两个活动的Android应用程序 - 和。 当用户第一次打开应用程序时,它应该将他们带到,然后,他们应该登录并转到具有注销按钮的。 如果他们按下“注销”按钮,它应该再次返回到。如果他们按下后退按钮,它应该退出应用程序。当他们按下应用程序图标时,它应该直接将他们带到。 我对如何保存活动并在按下应用程序图标时返回该特定活动感到困惑。

  • 应用程序根本没有启动,显示错误,就像活动不存在一样(即使我有)。 执行时出错:am start-n“com.tectibet.loginapp/com.tectibet.loginapp.MainActivity”-a Android.Intent.Action.Main-c Android.Intent.Category.Launcher启动:Intent{act=Android.Intent.

  • 我升级到最新的sdk版本23。现在我的一些代码不再起作用了。这是我以前使用的获取json的类:

  • 我在设备上卸载了应用程序。然后,当我尝试在Android Studio中运行该应用程序时,它返回以下信息: 启动活动时出错我一直在尝试将应用程序重新安装到设备上,但我不知道如何强制Android Studio将项目重新安装回设备上。Android Studio版本:北极之狐2020.3.1补丁2