-1

有没有人遇到过这个错误?

现在,我正在尝试在 android/eclipse 中从选项卡主机的第一个选项卡切换到第二个选项卡。但是在运行显示为应用程序 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);

    }
    }

*活动_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();}
    }
});
} 
}

*活动_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();
} 
}

日志猫

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.java在您的 rmanifest 文件中注册您的。

在您的<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 回答