-1

誰かがこのエラーに遭遇しましたか?

現在、android / eclipseでタブホストの最初のタブから2番目のタブに切り替えようとしています。しかし、アプリケーションTab_testingが予期せず停止したため、エミュレータを実行した後、もう一度やり直してください。

誰かがこれに対する解決策を見つけることができますか?

以下の私の情報源を見つけてください。

メインクラスのソース

public class Tab_testingActivity extends TabActivity 
{
 /** Called when the activity is first created. */

@Override      
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

   Resources res = getResources();                 
   TabHost tabHost = getTabHost();  // The activity TabHost
   TabHost.TabSpec spec;  // Resusable TabSpec for each tab
   Intent intent;  // Reusable Intent for each tab

   intent = new Intent().setClass(this, Activity_1.class);


    spec = tabHost.newTabSpec("first").setIndicator("First").setContent(intent);
    tabHost.addTab(spec);


    intent = new Intent().setClass(this, Activity_2.class);
    spec = tabHost.newTabSpec("second").setIndicator("Second").setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

    }
    }

* Activity_1 *

 public class Activity_1 extends Activity {
EditText get;
Button save;
SharedPreferences sharedPreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);

    get=(EditText)findViewById(R.id.editText1);
    save=(Button)findViewById(R.id.button1);

    save.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {

if(get.getText().toString().equalsIgnoreCase("")){
  Toast.makeText(getApplicationContext(), "enter something", Toast.LENGTH_SHORT).show();
  }
else
{
 sharedPreferences=PreferenceManager.getDefaultSharedPreferences(Activity_1.this);
 Editor editor1 = sharedPreferences.edit();
 editor1.remove("answer");
 editor1.commit();

 sharedPreferences=PreferenceManager.getDefaultSharedPreferences(Activity_1.this);
 Editor editor = sharedPreferences.edit();
 Log.i("set value",""+get.getText().toString());
 editor.putString("answer",get.getText().toString());
 editor.commit();}
    }
});
} 
}

* Activity_2 *

public class Activity_2 extends Activity {
TextView set;
SharedPreferences sharedPreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);

    set=(TextView)findViewById(R.id.textView1);
}

@Override
protected void onResume() 
{
 sharedPreferences = PreferenceManager.getDefaultSharedPreferences(Activity_2.this);
 String answer= sharedPreferences.getString("answer", "");

 Log.v("get value",""+answer);

if(answer.equalsIgnoreCase(null))
{
set.setText("nothing to display");
}
else
{
set.setText(answer);
}
super.onResume();
} 
}

logcat

06-15 15:23:13.995: D/AndroidRuntime(523): Shutting down VM
06-15 15:23:13.995: W/dalvikvm(523): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-15 15:23:14.015: E/AndroidRuntime(523): FATAL EXCEPTION: main
06-15 15:23:14.015: E/AndroidRuntime(523): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.and.roid.host/com.and.roid.host.Tab_testingActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.and.roid.host/com.and.roid.host.Activity_1}; have you declared this activity in your AndroidManifest.xml?
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.os.Looper.loop(Looper.java:123)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.ActivityThread.main(ActivityThread.java:3683)
06-15 15:23:14.015: E/AndroidRuntime(523):  at java.lang.reflect.Method.invokeNative(Native Method)
06-15 15:23:14.015: E/AndroidRuntime(523):  at java.lang.reflect.Method.invoke(Method.java:507)
06-15 15:23:14.015: E/AndroidRuntime(523):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-15 15:23:14.015: E/AndroidRuntime(523):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-15 15:23:14.015: E/AndroidRuntime(523):  at dalvik.system.NativeStart.main(Native Method)
06-15 15:23:14.015: E/AndroidRuntime(523): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.and.roid.host/com.and.roid.host.Activity_1}; have you declared this activity in your AndroidManifest.xml?
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1457)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:277)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.widget.TabHost.setCurrentTab(TabHost.java:326)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.widget.TabHost.addTab(TabHost.java:216)
06-15 15:23:14.015: E/AndroidRuntime(523):  at com.and.roid.host.Tab_testingActivity.onCreate(Tab_testingActivity.java:27)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-15 15:23:14.015: E/AndroidRuntime(523):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-15 15:23:14.015: E/AndroidRuntime(523):  ... 11 more
4

1 に答える 1

6

単純。Activity_1.javarmanifest ファイルに登録するだけです。

あなたの<application>タグの下に、以下のActivity_1.javaように言及してください

<activity android:name=".Activity_1" />

アプリケーションに複数のアクティビティがある場合は、上記のようにすべてのアクティビティを登録する必要があります。例えば ​​-

<activity android:name=".Activity_1" />
<activity android:name=".Activity_2" />
<activity android:name=".Activity_3" />
.
.
.
于 2012-06-15T10:12:58.797 に答える