ページ 1 / 1
アプリが起動しない
Posted: 2013年9月29日(日) 21:56
by sozai
アプリをエミュレーターで起動すると"Unfortunately,(アプリ名) has stopped."と出て起動しません。
調べてみると、AndroidMaifest.xmlに原因があるようなのですが、原因がわかりません。
以下、ソースコードとログです。
MainActivity.java
► スポイラーを表示
コード:
package com.example.difficultquiz;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Start start = new Start();
start.StartScene();
this.finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Start.java
► スポイラーを表示
コード:
package com.example.difficultquiz;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class Start extends Activity implements OnClickListener{
private ImageButton StartButton;
public void StartScene(){
StartButton = (ImageButton)findViewById(R.id.imgButton1);
StartButton.setOnClickListener(this);
}
public void OnClickStart(View v){
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(this, "スタートします", Toast.LENGTH_LONG).show();
}
}
log.txt
- LogCatのやつです。
- (109 バイト) ダウンロード数: 171 回
Re: アプリが起動しない
Posted: 2013年9月29日(日) 22:04
by みけCAT
sozai さんが書きました:調べてみると、AndroidMaifest.xmlに原因があるようなのですが、原因がわかりません。
そう思うのなら、AndroidMaifest.xmlを貼ったほうがいいのではないでしょうか?
Re: アプリが起動しない
Posted: 2013年9月29日(日) 22:18
by sozai
すみません。
わすれていました。
コード:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.difficultquiz"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18"
/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:allowBackup="true"
android:logo="@drawable/ic_launcher"
android:name="android.test.mock.MockApplication"
android:killAfterRestore="true"
android:restoreNeedsApplication="true"
android:hardwareAccelerated="false"
android:restoreAnyVersion="true"
android:testOnly="false"
android:allowClearUserData="true" android:persistent="true" android:hasCode="true">
<activity
android:name="com.example.difficultquiz.MainActivity"
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>
Re: アプリが起動しない
Posted: 2013年9月29日(日) 22:35
by みけCAT
とりあえず、AndroidMaifest.xmlの以下の2行を削り、
コード:
android:name="android.test.mock.MockApplication"
android:hardwareAccelerated="false" (これを書いてあると自分のEclipseがエラーを吐く)
Start.javaの以下の2行をコメントアウトすると、2.3.3のエミュレータでエラーが出ずに終了しました。
コード:
StartButton = (ImageButton)findViewById(R.id.imgButton1);
StartButton.setOnClickListener(this);
Re: アプリが起動しない
Posted: 2013年9月29日(日) 22:44
by みけCAT
以下のようにファイルを編集すると、
画面が開いて何もしなければ閉じず、メニューボタンを押すとメニューが表示され、
画面上の画像が貼られたボタンを押すと「スタートします」と表示される、という動作になりました。
MainActivity.java
コード:
package com.example.difficultquiz;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Start start = new Start();
// start.StartScene();
start.StartScene(this);
// this.finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Start.java
コード:
package com.example.difficultquiz;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class Start extends Activity implements OnClickListener{
private ImageButton StartButton;
// public void StartScene(){
public void StartScene(Activity a){
// StartButton = (ImageButton)findViewById(R.id.imgButton1);
StartButton = (ImageButton)a.findViewById(R.id.imgButton1);
StartButton.setOnClickListener(this);
}
public void OnClickStart(View v){
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Toast.makeText(this, "スタートします", Toast.LENGTH_LONG).show();
Toast.makeText(v.getContext(), "スタートします", Toast.LENGTH_LONG).show();
}
}
AndroidMaifest.xml
コード:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.difficultquiz"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18"
/>
<!--
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:allowBackup="true"
android:logo="@drawable/ic_launcher"
android:name="android.test.mock.MockApplication"
android:killAfterRestore="true"
android:restoreNeedsApplication="true"
android:hardwareAccelerated="false"
android:restoreAnyVersion="true"
android:testOnly="false"
android:allowClearUserData="true" android:persistent="true" android:hasCode="true">
-->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:allowBackup="true"
android:logo="@drawable/ic_launcher"
android:killAfterRestore="true"
android:restoreNeedsApplication="true"
android:restoreAnyVersion="true"
android:testOnly="false"
android:allowClearUserData="true" android:persistent="true" android:hasCode="true">
<activity
android:name="com.example.difficultquiz.MainActivity"
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>
検証に使用したプロジェクトを添付します。
Re: アプリが起動しない
Posted: 2013年10月01日(火) 18:59
by sozai
>みけCATさん
ソースコードありがとうございます。
早速試してみようと思います。
ところで、確認に使ったエミュレーターはなんですか?
設定を教えてください。
Re: アプリが起動しない
Posted: 2013年10月01日(火) 22:32
by みけCAT
エミュレータは標準(?)のAVDで、バージョンはよくわからないのですが、
SDKのtools\emulator.exeの更新日時は2012年12月29日でした。
設定は画像の通りです。
Re: アプリが起動しない
Posted: 2013年10月07日(月) 21:57
by sozai
ありがとうございます。
無事動きました。
ですが、何故ああなったのかわからず頭を抱えています...