我想使用按鈕意圖活動到活動。 這是我的程序。活動意圖 - 不幸已停止
這是我的XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ibaby_single_picture.MainActivity" >
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "123"
></Button>
</LinearLayout>
這是我的Java(活動):
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(listener);
}
private Button.OnClickListener listener = new Button.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(getApplicationContext(),informationActivity.class);
startActivity(intent);
}
};
}
這是我AndroidManifest:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.ibaby_single_picture.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> //↓I have written this.
<activity android:label="iBaby" android:name=".informationActivity"></activity>
</application>
我不知道在哪裏這個錯誤。 有人可以幫我嗎? 非常感謝!!!!!!!
這是stacktrace嗎?
09-20 01:21:35.944: E/AndroidRuntime(28696): at java.lang.reflect.Method.invokeNative(Native Method)
09-20 01:21:35.944: E/AndroidRuntime(28696): at java.lang.reflect.Method.invoke(Method.java:515)
09-20 01:21:35.944: E/AndroidRuntime(28696): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
09-20 01:21:35.944: E/AndroidRuntime(28696): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
09-20 01:21:35.944: E/AndroidRuntime(28696): at dalvik.system.NativeStart.main(Native Method)
09-20 01:21:35.944: E/AndroidRuntime(28696): Caused by: java.lang.NoSuchMethodException: gotoinformationActivity [class android.view.View]
09-20 01:21:35.944: E/AndroidRuntime(28696): at java.lang.Class.getConstructorOrMethod(Class.java:472)
09-20 01:21:35.944: E/AndroidRuntime(28696): at java.lang.Class.getMethod(Class.java:857)
09-20 01:21:35.944: E/AndroidRuntime(28696): at android.view.View$1.onClick(View.java:3835)
09-20 01:21:35.944: E/AndroidRuntime(28696): ... 11 more
這是我的informationActivity。我用Tabhost擴展了Activity。
public class informationActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information_tabhost);
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = getActionBar().newTab();
tab1.setText("1");
tab1.setTabListener(new TabListener1(new information0()));
ActionBar.Tab tab2 = getActionBar().newTab();
tab2.setText("2");
tab2.setIcon(android.R.drawable.ic_menu_edit);
tab2.setTabListener(new TabListener1(new information1()));
ActionBar.Tab tab3 = getActionBar().newTab();
tab3.setText("3");
tab3.setIcon(android.R.drawable.ic_menu_search);
tab3.setTabListener(new TabListener1(new information2()));
ActionBar.Tab tab4 = getActionBar().newTab();
tab3.setText("3");
tab3.setIcon(android.R.drawable.ic_menu_search);
tab3.setTabListener(new TabListener1(new information3()));
getActionBar().addTab(tab1);
getActionBar().addTab(tab2);
getActionBar().addTab(tab3);
getActionBar().addTab(tab4);
}
private class TabListener1 implements ActionBar.TabListener {
private Fragment fragment;
public TabListener1(Fragment fragment) {
this.fragment = fragment;
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.add(R.id.tabsample1, fragment);
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
}
}
}
這是我information_tabhost.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/tabsample1" >
</LinearLayout>
真的謝謝,大家好!
是activity_main.xml中? – Blackbelt 2014-09-19 17:10:44
是的,那是activity_main.xml。 – irene 2014-09-19 17:14:06
發佈你的stacktrace – codeMagic 2014-09-19 17:14:18