- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序此时总是崩溃,请帮我解决这个问题。谢谢。
现在的情况如上标题所述。
特此是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.contactmanager"
android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.WRITE_OWNER_DATA"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<application android:label="@string/app_name" android:icon="@drawable/icon" android:allowBackup="true">
<!-- --><activity android:name=".ContactManager" 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="ContactAdder" android:label="@string/addContactTitle">
</activity>
<activity android:name=".SingleListContact"
android:label="Contact Person Details">
</activity>
</application>
</manifest>
SingleListContact.java
package com.example.android.contactmanager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SingleListContact extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.single_list_contact_view);
TextView txtContact = (TextView) findViewById(R.id.contactList);
Intent i = getIntent();
// getting attached intent data
String contact = i.getStringExtra("contact");
// displaying selected product name
txtContact.setText(contact);
}
}
我的ContactManager.java如下
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.contactmanager;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public final class ContactManager extends Activity implements OnItemClickListener
{
public static final String TAG = "ContactManager";
private Button mAddAccountButton;
private ListView mContactList;
private boolean mShowInvisible;
//public BooleanObservable ShowInvisible = new BooleanObservable(false);
private CheckBox mShowInvisibleControl;
/**
* Called when the activity is first created. Responsible for initializing the UI.
*/
@Override
public void onCreate(Bundle savedInstanceState)
{
Log.v(TAG, "Activity State: onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_manager);
// Obtain handles to UI objects
mAddAccountButton = (Button) findViewById(R.id.addContactButton);
mContactList = (ListView) findViewById(R.id.contactList);
mShowInvisibleControl = (CheckBox) findViewById(R.id.showInvisible);
// Initialise class properties
mShowInvisible = false;
mShowInvisibleControl.setChecked(mShowInvisible);
// Register handler for UI elements
mAddAccountButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d(TAG, "mAddAccountButton clicked");
launchContactAdder();
}
});
mShowInvisibleControl.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
Log.d(TAG, "mShowInvisibleControl changed: " + isChecked);
mShowInvisible = isChecked;
populateContactList();
}
});
mContactList = (ListView) findViewById(R.id.contactList);
mContactList.setOnItemClickListener(this);
// Populate the contact list
populateContactList();
}
/**
* Populate the contact list based on account currently selected in the account spinner.
*/
private void populateContactList() {
// Build adapter with contact entries
Cursor cursor = getContacts();
String[] fields = new String[] {
ContactsContract.Data.DISPLAY_NAME
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor,
fields, new int[] {R.id.contactEntryText});
mContactList.setAdapter(adapter);
}
/**
* Obtains the contact list for the currently selected account.
*
* @return A cursor for for accessing the contact list.
*/
private Cursor getContacts()
{
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[]
{
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + (mShowInvisible ? "0" : "1") + "'";
//String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + (mShowInvisible.get() ? "0" : "1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return this.managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}
/**
* Launches the ContactAdder activity to add a new contact to the selected account.
*/
protected void launchContactAdder()
{
Intent i = new Intent(this, ContactAdder.class);
startActivity(i);
}
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
Log.i("TAG", "You clicked item " + id + " at position " + position);
// Here you start the intent to show the contact details
// selected item
TextView tv=(TextView)v.findViewById(R.id.contactList);
String allcontactlist = tv.getText().toString();
// Launching new Activity on selecting single List Item
Intent i = new Intent(getApplicationContext(), SingleListContact.class);
// sending data to new activity
i.putExtra("Contact Person", allcontactlist);
startActivity(i);
}
}
contact_entry.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:text="@+id/contactEntryText"
android:id="@+id/contactEntryText"
android:layout_width="fill_parent"
android:textSize="30sp"
android:layout_height="wrap_content"/>
</LinearLayout>
contact_manager.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView android:layout_width="wrap_content"
android:id="@+id/contactList"
android:layout_height="0dp"
android:padding="10dp"
android:textSize="200sp"
android:layout_weight="10"/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/showInvisible"
android:text="@string/showInvisible"/>
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/addContactButton"
android:text="@string/addContactButtonLabel"/>
</LinearLayout>
Logcat 结果:
12-05 05:00:31.289: E/AndroidRuntime(642): FATAL EXCEPTION: main
12-05 05:00:31.289: E/AndroidRuntime(642): java.lang.NullPointerException
12-05 05:00:31.289: E/AndroidRuntime(642): at com.example.android.contactmanager.ContactManager.onItemClick(ContactManager.java:148)
12-05 05:00:31.289: E/AndroidRuntime(642): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
12-05 05:00:31.289: E/AndroidRuntime(642): at android.widget.ListView.performItemClick(ListView.java:3513)
12-05 05:00:31.289: E/AndroidRuntime(642): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
12-05 05:00:31.289: E/AndroidRuntime(642): at android.os.Handler.handleCallback(Handler.java:587)
12-05 05:00:31.289: E/AndroidRuntime(642): at android.os.Handler.dispatchMessage(Handler.java:92)
12-05 05:00:31.289: E/AndroidRuntime(642): at android.os.Looper.loop(Looper.java:123)
12-05 05:00:31.289: E/AndroidRuntime(642): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-05 05:00:31.289: E/AndroidRuntime(642): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 05:00:31.289: E/AndroidRuntime(642): at java.lang.reflect.Method.invoke(Method.java:507)
12-05 05:00:31.289: E/AndroidRuntime(642): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-05 05:00:31.289: E/AndroidRuntime(642): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-05 05:00:31.289: E/AndroidRuntime(642): at dalvik.system.NativeStart.main(Native Method)
最佳答案
onItemClick() 方法中存在错误。请按以下方式更新您的代码。
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
Log.i("TAG", "You clicked item " + id + " at position " + position);
// Here you start the intent to show the contact details
// selected item
TextView tv=(TextView)v.findViewById(R.id.contactList);
String allcontactlist = tv.getText().toString();
// Launching new Activity on selecting single List Item
Intent i = new Intent(getApplicationContext(), SingleListContact.class);
// sending data to new activity
i.putExtra("Contact Person", allcontactlist);
startActivity(i);
}
关于android - 单击单个联系人时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13716245/
对于我的应用程序的一部分,我需要在选择该选项时显示所有联系人的列表(带有电话号码)。 这是按下按钮时调用的 Activity : package com.example.prototype01; im
我正在尝试使用 Google Contact API (C#) 将“生日”值添加到 Google Contact。谁能帮我解决这个问题。 我正在使用 Google 数据 API 设置 (1.4.0.2
如何使用 Google Contact API (c#) 在 Google Contact 中创建新的“自定义字段”? 我用过: ExtendedProperty obj_ExtendedProper
我正在 iPhone 应用程序中使用地址簿框架,并且我想获取项目公司名称。我在 AddressBookUI_Framework.pdf 中找不到此信息,有人可以解释一下吗? 问候 AddressBoo
我正在开发一个数据库来管理一家小公司的客户数据。客户是公司和机构(学校等),当然还有人/联系人。会有更多的范围及时添加,但现在我正在寻找关于核心设计本身的任何输入,如果有任何我在这里遗漏的东西可能会导
我正在使用 Swift Contacts 并尝试确定是否可以将 contacts.phoneNumbers 转换为 NSDictionary?即可以通过以下方式在 contacts.phoneNumb
我想要我的联系人的 ListView。我使用谷歌示例代码。问题是我一遍又一遍地获得相同的联系人: 吉姆 吉姆 吉姆 吉姆 吉姆 安娜 安娜 安娜 安娜 ... 如何获得我的联系人的 DISTINCT
对于我的应用程序,我需要导入 Gmail 地址簿,我可以按照“Gmail Contact API”进行操作。 最近 Gmail 添加了一些不属于 xml 的新字段(即生日、网站等)。 gmail ap
在 NetSuite 中编辑记录时,我有一个按钮需要能够获取所有联系人的名字、姓氏、电子邮件和可能的 Angular 色,以便我可以将其附加到我已经编写的其他代码中。我似乎无法弄清楚如何提取与记录关联
我们需要一种使用 Delphi/Pascal 代码读取(并且可以选择写入).vcf 文件的方法。带有源代码的免费库将是完美的。 最佳答案 AceVCard是delphi 2009的免费开放组件,兼容V
我正在模拟一个电话簿,其中有 ArrayList 。如何覆盖toString()函数为了拥有像这样的东西,我们正在做 System.out.println(phonebook) ? Name: nam
我正在尝试构建一个搜索 XML 表达式以与 Java 中的 Exchange Web 服务一起使用。我试图实现的是我可以通过电子邮件地址搜索所有联系人。我已经浏览了他们的文档,但未能使其正常工作。这是
我有一个项目正在进行,我想自动发送 SMS,并有时间和日期将 SMS 推送给特定的联系人。那么如何以简洁高效的方式从手机中提取联系人呢?基本上我希望用户按下一个按钮,然后应用程序转到联系人列表,然后用
我有一个表格 View ,显示所有联系人都使用 RealmSwift。如何使用谓词按电话号码过滤 Realm 联系人? class Contact: Object { @obj
我正在尝试使用 CNContactVCardSerialization 将联系人保存为 vcf,效果相对较好。我确实发现苹果不包含注释或图像作为 VCF 的一部分。我确实使用了 stackoverfl
我正在读取手机中的所有联系人,如下所示: Cursor cursor = MainApp.get().getContentResolver().query( C
我有具有 list 权限的应用程序 我的 Activity 尝试加载联系人: eDeviceRecordsLoader contactsLoader = new eDeviceRec
我正在尝试编辑组标题和注释, 编辑标题适用于系统组 和用户创建的组, 虽然注释列只有在系统组(例如“联系人”、“ friend ”、“家庭”、“同事”)时才会保留,我假设它不会为用户创建的组保存注释,
在我的应用中,我想将联系人与其他数据相关联。对联系人的引用必须尽可能持久,否则关联的数据将变成垃圾。 首先,我应该使用 ContactsContract.Contact.LOOKUP_KEY 访问聚合
我正在做一个应用程序,因为我显示从设备到 ListView 的所有联系人(姓名、号码、图像)。我想使用工具栏搜索从 ListView 中搜索联系人。我添加了工具栏搜索,但我不知道如何从列表中过滤联系人
我是一名优秀的程序员,十分优秀!