アプリで「アクティビティComponentInfoをインスタンス化できません」というエラーが発生します。すでにAndroidManifest.xmlでアクティビティを宣言しましたが、それでもエラーが発生します。何なのかわかりません。誰かが助けることができますか?
ありがとう
エラー:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{br.com.controladoratividades/br.com.controladoratividades.activities.NovaAtividadeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
at android.content.Context.getString(Context.java:182)
at br.com.controladoratividades.activities.NovaAtividadeActivity.<init>(NovaAtividadeActivity.java:15)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
... 11 more
私のAndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.controladoratividades"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".activities.ControladorAtividadesActivity"
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=".activities.NovaAtividadeActivity"
android:label="@string/nova_atividade" >
</activity>
<activity
android:name=".activities.PlanejadorActivity"
android:label="@string/novo_plano" >
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
アクティビティ:
package br.com.controladoratividades.activities;
import br.com.controladoratividades.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class NovaAtividadeActivity extends Activity {
private String[] DIAS = new String[] {getString(R.string.domingo),
getString(R.string.segunda),
getString(R.string.terca),
getString(R.string.quarta),
getString(R.string.quinta),
getString(R.string.sexta),
getString(R.string.sabado)};
protected boolean[] DIAS_SELECIONADOS = new boolean[ DIAS.length ];
static final int DIAS_DIALOG_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nova_atividade);
Button btAlterarDias = (Button)findViewById(R.id.btSalvarPlano);
btAlterarDias.setOnClickListener(new AlterarDiasClickHandler());
for (int i = 1; i < DIAS_SELECIONADOS.length; i++) {
DIAS_SELECIONADOS[i] = true;
}
}
public class AlterarDiasClickHandler implements View.OnClickListener{
@Override
public void onClick(View v) {
showDialog(DIAS_DIALOG_ID);
}
}
@Override
protected Dialog onCreateDialog( int id )
{
return
new AlertDialog.Builder( this )
.setTitle( "Planets" )
.setMultiChoiceItems(
DIAS,
DIAS_SELECIONADOS,
new DialogSelectionClickHandler() )
.setPositiveButton( "OK", new DialogButtonClickHandler() )
.create();
}
public class DialogSelectionClickHandler implements DialogInterface.OnMultiChoiceClickListener
{
public void onClick( DialogInterface dialog, int clicked, boolean selected )
{
Log.i( "ME", DIAS[ clicked ] + " selected: " + selected );
}
}
public class DialogButtonClickHandler implements DialogInterface.OnClickListener
{
public void onClick( DialogInterface dialog, int clicked )
{
switch( clicked )
{
case DialogInterface.BUTTON_POSITIVE:
//printSelectedPlanets();
break;
}
}
}
}