Android SDK ツールをバージョン 22.0.1 に更新したら、アプリを実行できなくなりました。アプリを起動すると、次のエラーが表示されます。
06-19 20:44:47.297: D/AndroidRuntime(370): Shutting down VM
06-19 20:44:47.337: E/AndroidRuntime(370): FATAL EXCEPTION: main
06-19 20:44:47.337: E/AndroidRuntime(370): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.app.dictionary/com.android.app.dictionary.activity.MainActivity}: java.lang.ClassNotFoundException: com.android.app.dictionary.activity.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.android.app.dictionary-2.apk]
06-19 20:44:47.337: E/AndroidRuntime(370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.os.Looper.loop(Looper.java:123)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-19 20:44:47.337: E/AndroidRuntime(370): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 20:44:47.337: E/AndroidRuntime(370): at java.lang.reflect.Method.invoke(Method.java:521)
06-19 20:44:47.337: E/AndroidRuntime(370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-19 20:44:47.337: E/AndroidRuntime(370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-19 20:44:47.337: E/AndroidRuntime(370): at dalvik.system.NativeStart.main(Native Method)
06-19 20:44:47.337: E/AndroidRuntime(370): Caused by: java.lang.ClassNotFoundException: com.android.app.dictionary.activity.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.android.app.dictionary-2.apk]
06-19 20:44:47.337: E/AndroidRuntime(370): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-19 20:44:47.337: E/AndroidRuntime(370): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-19 20:44:47.337: E/AndroidRuntime(370): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-19 20:44:47.337: E/AndroidRuntime(370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
06-19 20:44:47.337: E/AndroidRuntime(370): ... 11 more
06-19 20:44:56.478: I/Process(370): Sending signal. PID: 370 SIG: 9
06-19 20:52:36.868: W/dalvikvm(400): Unable to resolve superclass of Lcom/android/app/dictionary/activity/MainActivity; (31)
06-19 20:52:36.868: W/dalvikvm(400): Link of class 'Lcom/android/app/dictionary/activity/MainActivity;' failed
06-19 20:52:36.898: D/AndroidRuntime(400): Shutting down VM
06-19 20:52:36.898: W/dalvikvm(400): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
これは私のメインクラスです:
public class DetailtFragment extends Fragment implements OnClickListener {
static Button btnAdd, btnListen, btnView, btnGame, btnGame2;
FragmentActivity activity;
static TextView tvWord, tvDetailt;
static Context mContext;
static ImageView imgView;
static File cacheDir, mp3;
static Bitmap bmp;
MediaPlayer mediaPlayer;
static Handler mHandler = new Handler();
boolean firstRun = true;
static SharedPreferences preferences;
public static Fragment newInstance(Context context) {
DetailtFragment f = new DetailtFragment();
return f;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
activity = getActivity();
mContext = activity;
}
@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
mediaPlayer = new MediaPlayer();
String newFolder = "/dictionary";
String extStorageDirectory = Environment.getExternalStorageDirectory()
.toString();
cacheDir = new File(extStorageDirectory + newFolder);
if (!cacheDir.exists()) {
cacheDir.mkdir();
}
preferences = activity.getSharedPreferences(Constants.PREF, 0);
}
@Override
public void onStart() {
// TODO Auto-generated method stub
super.onStart();
if (!firstRun) {
return;
}
String saved_word = preferences.getString(Constants.PREF_WORD, "");
if (saved_word.trim().length() > 0) {
WordDatabase db = new WordDatabase(activity);
db.open();
WordDTO saved_word_dto = db.getByName(saved_word);
showWordDetailt(saved_word_dto);
db.close();
}
firstRun = false;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.detailt, null);
btnAdd = (Button) root.findViewById(R.id.btnAddNew);
btnListen = (Button) root.findViewById(R.id.btnListen);
tvWord = (TextView) root.findViewById(R.id.tvWord);
tvDetailt = (TextView) root.findViewById(R.id.tvDetailt);
imgView = (ImageView) root.findViewById(R.id.imgDetailt);
btnView = (Button) root.findViewById(R.id.btnView);
btnGame = (Button) root.findViewById(R.id.btnGame);
btnGame2 = (Button) root.findViewById(R.id.btnGame2);
btnAdd.setOnClickListener(this);
btnListen.setOnClickListener(this);
btnView.setOnClickListener(this);
btnGame.setOnClickListener(this);
btnGame2.setOnClickListener(this);
return root;
}
public static void showWordDetailt(WordDTO word) {
if (word == null) {
return;
}
Constants.word = word;
if (preferences != null) {
Editor edit = preferences.edit();
edit.putString(Constants.PREF_WORD, word.getWord());
edit.commit();
}
final String name;
String pronunce, mean, type, msg;
String br = "<br>";
String tab = " ";
String mean1, mean2, mean3, mean4, mean5;
pronunce = word.getPronunce();
mean = word.getMean();
type = word.getType();
name = word.getWord();
mean1 = word.getMean1();
mean2 = word.getMean2();
mean3 = word.getMean3();
mean4 = word.getMean4();
mean5 = word.getMean5();
tvWord.setText(name);
msg = "";
if (pronunce != null && pronunce.trim().length() > 0) {
msg = "<b>Phát âm:</b>" + br + tab + pronunce + br + br;
}
msg += "<b>Loại từ:</b>" + br + tab + type + br + br;
msg += "<b>Nghĩa:</b>" + br + tab + "- " + mean;
if (mean1 != null) {
msg += br + tab + "- " + mean1;
}
if (mean2 != null) {
msg += br + tab + "- " + mean2;
}
if (mean3 != null) {
msg += br + tab + "- " + mean3;
}
if (mean4 != null) {
msg += br + tab + "- " + mean4;
}
if (mean5 != null) {
msg += br + tab + "- " + mean5;
}
tvDetailt.setText(Html.fromHtml(msg));
btnListen.setEnabled(false);
imgView.setImageDrawable(mContext.getResources().getDrawable(
R.drawable.default_image));
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
getImageAndSoundFromResource(name);
}
}).start();
}
private static void getImageAndSoundFromResource(String wordname) {
// TODO Auto-generated method stub
Context context = mContext.getApplicationContext();
InputStream imageIs = null;
InputStream soundIs = null;
try {
imageIs = context.getResources().getAssets()
.open(wordname + ".jpg");
soundIs = context.getResources().getAssets()
.open(wordname + ".mp3");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (imageIs != null) {
try {
bmp = BitmapFactory.decodeStream(imageIs);
setImage(bmp);
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (soundIs != null) {
try {
byte[] soundBytes = convertInputStreamToByteArray(soundIs);
try {
if (mp3 != null && mp3.exists()) {
mp3.delete();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// create temp file that will hold byte array
mp3 = File.createTempFile(wordname, "mp3", cacheDir);
mp3.deleteOnExit();
FileOutputStream fos = new FileOutputStream(mp3);
fos.write(soundBytes);
fos.close();
setEnableButton(true);
} catch (IOException ex) {
ex.printStackTrace();
setEnableButton(false);
}
}
}
private static byte[] convertInputStreamToByteArray(InputStream is)
throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
}
private static void setImage(final Bitmap bmp) {
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (bmp != null) {
imgView.setImageBitmap(bmp);
}
}
});
}
private static void setEnableButton(final boolean enabled) {
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
btnListen.setEnabled(enabled);
}
});
}
private void playSound(File mp3) {
if (mp3 == null){
return;
}
try {
FileInputStream fis = new FileInputStream(mp3);
mediaPlayer.reset();
mediaPlayer.setDataSource(fis.getFD());
mediaPlayer.prepare();
mediaPlayer.start();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
try {
if (mp3 != null && mp3.exists()) {
mp3.delete();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int id = v.getId();
switch (id) {
case R.id.btnAddNew:
Intent addIntent = new Intent(mContext, AddNewWordActivity.class);
mContext.startActivity(addIntent);
break;
case R.id.btnListen:
playSound(mp3);
break;
case R.id.btnView:
if (Constants.word != null) {
Intent detailtIntent = new Intent(mContext,
Detailt2Activity.class);
mContext.startActivity(detailtIntent);
}
break;
case R.id.btnGame:
List<WordDTO> list = MainActivity.getStarredList();
if (list.size() >= 5) {
Intent gameIntent = new Intent(mContext, GameActivity.class);
mContext.startActivity(gameIntent);
} else {
AlertDialog.Builder bl = new AlertDialog.Builder(mContext);
bl.setMessage(getString(R.string.alert_less_than_5));
bl.setNeutralButton(getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
bl.show();
}
break;
case R.id.btnGame2:
List<WordDTO> list2 = MainActivity.getStarredList();
if (list2.size() >= 5) {
Intent gameIntent = new Intent(mContext,
GameReverseActivity.class);
mContext.startActivity(gameIntent);
} else {
AlertDialog.Builder bl = new AlertDialog.Builder(mContext);
bl.setMessage(getString(R.string.alert_less_than_5));
bl.setNeutralButton(getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
bl.show();
}
break;
default:
break;
}
}
}
SDK ツール バージョン 22.0.1 と Eclipse Juno 4.2.2 を使用しています。助けてくれてありがとう。