- Forum-Beiträge: 7
08.03.2014, 00:39:35 via Website
08.03.2014 00:39:35 via Website
bin neu hier und gerade bissl mit android am rumspielen ...
nunja hab nen kleines problem wollte ne 2te activity starten nur irgendwie stürzt die app immer ab wenn ich den button berühre und eigtl. die 2. activity starten sollte und ich komme mit meinem derzeitigen wissensstand leider nicht dahinter was da falsch läuft hoffe ihr könnt mir helfen ...
also hier ma die mainactivity:
2
3import android.os.Bundle;
4import android.app.Activity;
5import android.content.Intent;
6import android.view.Menu;
7import android.view.View;
8import android.view.View.OnClickListener;
9import android.widget.Button;
10
11public class MainActivity extends Activity {
12 private Button btn;
13 Intent intent = new Intent(this,Second.class);
14 private OnClickListener butListener = new OnClickListener(){
15
16 @Override
17 public void onClick(View v) {
18 // TODO Auto-generated method stub
19
20 startActivity(intent);
21
22
23 }
24
25 };
26
27
28 @Override
29 protected void onCreate(Bundle savedInstanceState) {
30 super.onCreate(savedInstanceState);
31 setContentView(R.layout.activity_main);
32 btn = (Button) findViewById(R.id.button1);
33 btn.setOnClickListener(butListener);
34 }
35
36 @Override
37 public boolean onCreateOptionsMenu(Menu menu) {
38 // Inflate the menu; this adds items to the action bar if it is present.
39 getMenuInflater().inflate(R.menu.main, menu);
40 return true;
41 }
42
43}
hier die manifest datei:
2<manifest xmlns:android="link"
3 package="de.kush.test"
4 android:versionCode="1"
5 android:versionName="1.0" >
6
7 <uses-sdk
8 android:minSdkVersion="8"
9 android:targetSdkVersion="14" />
10
11 <application
12 android:allowBackup="true"
13 android:icon="@drawable/ic_launcher"
14 android:label="@string/app_name"
15 android:theme="@style/AppTheme" >
16 <activity
17 android:name="de.kush.test.MainActivity"
18 android:label="@string/app_name" >
19 <intent-filter>
20 <action android:name="android.intent.action.MAIN" />
21
22 <category android:name="android.intent.category.LAUNCHER" />
23 </intent-filter>
24 </activity>
25
26 <activity
27 android:label="@string/app_name"
28 android:name=".Second" >
29
30 </activity>
31
32
33
34 </application>
35
36</manifest>
die second.java existiert logischerveise auch und zeigt testweise auch nur ne textview an
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.view.Menu;
6
7public class Second extends Activity {
8
9 @Override
10 protected void onCreate(Bundle savedInstanceState) {
11 // TODO Auto-generated method stub
12 super.onCreate(savedInstanceState);
13 setContentView(R.layout.second);
14 }
15
16 @Override
17 public boolean onCreateOptionsMenu(Menu menu) {
18 // Inflate the menu; this adds items to the action bar if it is present.
19 getMenuInflater().inflate(R.menu.main, menu);
20 return true;
21 }
22
23}
das sollte ja eigtl. reichen oder? wenn ihr noch was braucht nochma bescheid sagen...
thx im vorraus