我正在从书中的一个示例(Android编程 - 大书呆子牧场指南)中学习Android,我正在逐字逐句地遵循他们的代码。非常简单的代码,至少我认为...下面是我的模拟器的图像和大多数,如果不是所有的代码,除了布局文件。
我的模拟器使用API Level 18 android 4.3.1 cpu ARM。当我从列表中点击犯罪时,我想看到一条日志,说明我点击犯罪#x但我没有看到它。相反,我看到SoundPool标签错误加载/system/media/audio/ui/KeypressDelete.ogg和其他4个类似错误,如加载KeypressReturn.ogg错误。
我搜索了互联网并在堆栈上溢出了几个小时的解决方案。我能找到的只是"忽略它"或者"关闭设置",我不知道怎么做但我不想关掉它。我想解决它并继续这个例子,这样我就可以学习。有谁知道这个错误,可以帮我解决吗,拜托?我很感激。
以下是代码的一部分:
public class Crime
{
private UUID mId;
private String mTitle;
private Date mDate;
private boolean mSolved;
public Crime()
{
// Generate unique identifier
mId = UUID.randomUUID();
mDate = new Date();
}
public String getTitle()
{
return mTitle;
}
public void setTitle(String title)
{
mTitle = title;
}
public UUID getId()
{
return mId;
}
public Date getDate()
{
return mDate;
}
public void setDate(Date date)
{
mDate = date;
}
public boolean isSolved()
{
return mSolved;
}
public void setSolved(boolean solved)
{
mSolved = solved;
}
@Override
public String toString()
{
return mTitle;
}
}
public class CrimeLab
{
private ArrayList<Crime> mCrimes;
private static CrimeLab sCrimeLab;
private Context mAppContext;
private CrimeLab(Context appContext)
{
mAppContext = appContext;
mCrimes = new ArrayList<Crime>();
// Mock Crime objects
for (int i = 0; i < 100; i++)
{
Crime c = new Crime();
c.setTitle("Crime #" + i);
c.setSolved(i % 2 == 0); // Every other one
mCrimes.add(c);
}
}
public static CrimeLab get(Context c)
{
if (sCrimeLab == null)
{
sCrimeLab = new CrimeLab(c.getApplicationContext());
}
return sCrimeLab;
}
public ArrayList<Crime> getCrimes()
{
return mCrimes;
}
public Crime getCrime(UUID id)
{
for (Crime c : mCrimes)
{
if (c.getId().equals(id))
return c;
}
return null;
}
}
package com.bignerdranch.android.criminalintent;
import java.util.ArrayList;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class CrimeListFragment extends ListFragment
{
private static final String TAG = "CrimeListFragment";
private ArrayList<Crime> mCrimes;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getActivity().setTitle(R.string.crimes_title);
mCrimes = CrimeLab.get(getActivity()).getCrimes();
ArrayAdapter<Crime> adapter = new ArrayAdapter<Crime>(getActivity(), android.R.layout.simple_list_item_1, mCrimes);
setListAdapter(adapter);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
Crime c = (Crime) (getListAdapter()).getItem(position);
Log.d(TAG, c.getTitle() + " was clicked");
}
}