Instantiate Activtiy Component Fehler

  • Antworten:8
  • Bentwortet
Rob
  • Forum-Beiträge: 33

10.04.2014, 19:13:21 via Website

Hallo,

ich habe vorhin versucht mehrere Actvities hinzuzufügen, dies habe ich über FIle->New->Other->XML->XML.. Gemacht.

Die Activities habe ich auch soweit designed, nun habe ich nach dem dann kommenden Fehler gegoogelt, da sagte man mir ich soll die Activities noch in die Manifest Datei aufnehmen, dies tat ich dann:

1<application
2 android:allowBackup="true"
3 android:icon="@drawable/ic_launcher"
4 android:label="@string/app_name"
5 android:theme="@style/AppTheme" >
6 <activity
7 android:name="com.example.leerguttrainer2.act_begruessung"
8 android:label="@string/app_name" >
9 <intent-filter>
10 <action android:name="android.intent.action.MAIN" />
11
12 <category android:name="android.intent.category.LAUNCHER" />
13 </intent-filter>
14 </activity>
15 <activity
16 android:name="com.example.leerguttrainer2.act_login_gmail"
17 android:label="@string/app_name" >
18 <intent-filter>
19 <action android:name="android.intent.action.MAIN" />
20
21 <category android:name="android.intent.category.LAUNCHER" />
22 </intent-filter>
23 </activity>
24 <activity
25 android:name="com.example.leerguttrainer2.activity_main"
26 android:label="@string/app_name" >
27 <intent-filter>
28 <action android:name="android.intent.action.MAIN" />
29
30 <category android:name="android.intent.category.LAUNCHER" />
31 </intent-filter>
32 </activity>
33 </application>



Allerdings möchte die App trotzdem nicht starten und es kommt der Instantiation Fehler.

Ich hatte auch die Start-Activity auf eine andere gelegt. Vorher war es die MainActivity und nun ist es die act_begruessung.

— geändert am 10.04.2014, 19:13:45

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

10.04.2014, 19:30:49 via Website

Bitte mal Code und LogCat posten.
Eine Activity macht man normalerweise mit Fiel->...->new Activity
ein XML file ist doch keine Activity
Sondern nur ein Layout oder eine Andere art von deklaration

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Rob
  • Forum-Beiträge: 33

10.04.2014, 19:41:22 via Website

Oh okay, ich hatte gegoogelt, wie ich allg. eine neue Form hinzufüge.

Das habe ich dann über new Android XML File gemach, jetzt muss ich wohl die dazugehörige Activity erstellen?

Habs aktuell wieder ausgebessert/verändert nur noch eine zusätzliche Form/XML unbenannt in act_willkommen, sieht wie folgt aus:
Log:
104-10 19:37:45.825: D/AndroidRuntime(21183): Shutting down VM
204-10 19:37:45.825: W/dalvikvm(21183): threadid=1: thread exiting with uncaught exception (group=0x41843da0)
304-10 19:37:45.825: E/AndroidRuntime(21183): FATAL EXCEPTION: main
404-10 19:37:45.825: E/AndroidRuntime(21183): Process: com.example.testApp, PID: 21183
504-10 19:37:45.825: E/AndroidRuntime(21183): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
6
7{com.example.testApp/com.example.testApp.act_willkommen}: java.lang.ClassNotFoundException: Didn't find class
8
9"com.example.testApp.act_willkommen" on path: DexPathList[[zip file "/data/app/com.example.testApp.apk"],nativeLibraryDirectories=
10
11[/data/app-lib/com.example.testApp-151, /vendor/lib, /system/lib]]
1204-10 19:37:45.825: E/AndroidRuntime(21183): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2208)
1304-10 19:37:45.825: E/AndroidRuntime(21183): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
1404-10 19:37:45.825: E/AndroidRuntime(21183): at android.app.ActivityThread.access$800(ActivityThread.java:157)
1504-10 19:37:45.825: E/AndroidRuntime(21183): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
1604-10 19:37:45.825: E/AndroidRuntime(21183): at android.os.Handler.dispatchMessage(Handler.java:102)
1704-10 19:37:45.825: E/AndroidRuntime(21183): at android.os.Looper.loop(Looper.java:157)
1804-10 19:37:45.825: E/AndroidRuntime(21183): at android.app.ActivityThread.main(ActivityThread.java:5293)
1904-10 19:37:45.825: E/AndroidRuntime(21183): at java.lang.reflect.Method.invokeNative(Native Method)
2004-10 19:37:45.825: E/AndroidRuntime(21183): at java.lang.reflect.Method.invoke(Method.java:515)
2104-10 19:37:45.825: E/AndroidRuntime(21183): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
2204-10 19:37:45.825: E/AndroidRuntime(21183): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
2304-10 19:37:45.825: E/AndroidRuntime(21183): at dalvik.system.NativeStart.main(Native Method)
2404-10 19:37:45.825: E/AndroidRuntime(21183): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testApp.act_willkommen" on
25
26path: DexPathList[[zip file "/data/app/com.example.testApp-151.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testApp-151, /vendor/lib,
27
28/system/lib]]
2904-10 19:37:45.825: E/AndroidRuntime(21183): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
3004-10 19:37:45.825: E/AndroidRuntime(21183): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
3104-10 19:37:45.825: E/AndroidRuntime(21183): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
3204-10 19:37:45.825: E/AndroidRuntime(21183): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
3304-10 19:37:45.825: E/AndroidRuntime(21183): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
3404-10 19:37:45.825: E/AndroidRuntime(21183): ... 11 more

begruessung.xml:
1<?xml version="1.0" encoding="utf-8"?>
2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:background="#ffff00"
6 android:columnCount="1"
7 android:orientation="vertical" >
8
9 <ImageView
10 android:id="@+id/imageView1"
11 android:layout_width="wrap_content"
12 android:layout_height="wrap_content"
13 android:layout_alignParentTop="true"
14 android:layout_centerHorizontal="true"
15 android:src="@drawable/lgt_logo" />
16
17 <ImageButton
18 android:id="@+id/ibtn_Login_KontoAuth"
19 android:layout_width="wrap_content"
20 android:layout_height="wrap_content"
21 android:layout_alignRight="@+id/imageView1"
22 android:layout_below="@+id/imageView1"
23 android:layout_marginTop="66dp"
24 android:src="@drawable/lock_unlocked" />
25
26 <ImageButton
27 android:id="@+id/ibtn_Login_Gmail"
28 android:layout_width="wrap_content"
29 android:layout_height="wrap_content"
30 android:layout_alignTop="@+id/ibtn_Login_KontoAuth"
31 android:layout_marginRight="20dp"
32 android:layout_toLeftOf="@+id/ibtn_Login_KontoAuth"
33 android:src="@drawable/email" />
34
35 <TextView
36 android:id="@+id/textView1"
37 android:layout_width="wrap_content"
38 android:layout_height="wrap_content"
39 android:layout_above="@+id/ibtn_Login_Gmail"
40 android:layout_toLeftOf="@+id/ibtn_Login_KontoAuth"
41 android:text="Login Methode:"
42 android:textAppearance="?android:attr/textAppearanceLarge" />
43
44</RelativeLayout>

Manifest:
1<?xml version="1.0" encoding="utf-8"?>
2<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.example.testApp"
4 android:versionCode="1"
5 android:versionName="1.0" >
6
7 <uses-sdk
8 android:minSdkVersion="8"
9 android:targetSdkVersion="19" />
10 <uses-permission android:name="android.permission.INTERNET" />
11 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
12 <uses-permission android:name="android.permission.VIBRATE" />
13 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
14 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
15
16 <application
17 android:allowBackup="true"
18 android:icon="@drawable/ic_launcher"
19 android:label="@string/app_name"
20 android:theme="@style/AppTheme" >
21 <activity
22 android:name="com.example.testApp.act_willkommen"
23 android:label="@string/app_name" >
24 <intent-filter>
25 <action android:name="android.intent.action.MAIN" />
26
27 <category android:name="android.intent.category.LAUNCHER" />
28 </intent-filter>
29 </activity>
30 </application>
31
32</manifest>

— geändert am 10.04.2014, 19:43:36

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

10.04.2014, 20:03:21 via Website

Du musst jetzt die zugehörigen Activities noch erstellen.
zusätzlich tritt eine ClassnotFound exception auf.
Dies kann eine Folge von den Fehlenden Activities sein, poste aber trotzdem deine Main activity

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Rob
  • Forum-Beiträge: 33

10.04.2014, 20:08:28 via Website

Mit zugehörigen Activities meinst du dann die .java Dateien, die zu den Layout Files gehören?

In der MainActivity ist bisher nicht wirklich viel drin, nur das automatisch generierte und 2-3 MakeToast^^..

Ist nur zum testen von hinzufügen von neuen "Forms" (sorry so kenne ich die aus .NET) gewesen.

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

10.04.2014, 20:12:19 via Website

Ja ich meine die zugehörigen Java Files.
Und bitte poste deine Mainactivity.
In android ist das Konzept mit den "Forms" nicht so wie in .net
Da brauchst du füre jedes layout eine Activity (nicht notwendig aber ist schöner)
zusetzlich ist die Activity dass zuständig vür das annehmen von Daten oder Benutzerinteraktionen und um diese zu verarbeiten.
Aus einer Laufenden Activity kannst du eine Andere per intent starten.
PS: Wenn du eine Activity in Eclipse anlegst, legt sich der XML file dazu selber an.
Du musst nur noch die Activity in der Maifest hinzufügen.

LG Pascal //It's not a bug, it's a feature. :) ;)

Rob

Antworten
Rob
  • Forum-Beiträge: 33

10.04.2014, 20:15:22 via Website

Oh man, heil den Google Tuts..

Ich habe es so gesehen, dass man erst die XML Files anlegen soll :/..

Okay also zuerst die Activity anlegen und die XML wird automatisch generiert.

Eben suchen wo das geht :/..

Activity:
1package com.example.tutorial_post_request;
2
3import android.support.v7.app.ActionBarActivity;
4import android.support.v7.app.ActionBar;
5import android.support.v4.app.Fragment;
6import android.os.Bundle;
7import android.view.LayoutInflater;
8import android.view.Menu;
9import android.view.MenuItem;
10import android.view.View;
11import android.view.ViewGroup;
12import android.os.Build;
13
14
15public class MainActivity extends ActionBarActivity {
16
17 @Override
18 protected void onCreate(Bundle savedInstanceState) {
19 super.onCreate(savedInstanceState);
20 setContentView(R.layout.activity_main);
21
22Toast.makeText(getApplicationContext(), "Test1",
23 Toast.LENGTH_LONG).show();
24Toast.makeText(getApplicationContext(), "Test2",
25 Toast.LENGTH_LONG).show();
26 }
27
28
29 @Override
30 public boolean onCreateOptionsMenu(Menu menu) {
31
32 // Inflate the menu; this adds items to the action bar if it is present.
33 getMenuInflater().inflate(R.menu.main, menu);
34 return true;
35 }
36
37 @Override
38 public boolean onOptionsItemSelected(MenuItem item) {
39 // Handle action bar item clicks here. The action bar will
40 // automatically handle clicks on the Home/Up button, so long
41 // as you specify a parent activity in AndroidManifest.xml.
42 int id = item.getItemId();
43 if (id == R.id.action_settings) {
44 return true;
45 }
46 return super.onOptionsItemSelected(item);
47 }
48
49
50}

Ps: Weil ich mit dem Fragment-Gedöns nicht klargekommen bin, habe ich das gekillt..

EDIT:
Okay die neue Activity + Layout is drin, jetzt muss ich nur noch rausfinden, wie ich das als Startformular festlege.

— geändert am 10.04.2014, 20:26:25

Antworten
Rob
  • Forum-Beiträge: 33

10.04.2014, 20:28:29 via Website

Hat sich erledigt, habs hinbekommen, vielen Dank für die Hilfe :)!

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

10.04.2014, 21:14:17 via App

Kein Problem.
Thread noch auf beantwortet setztn.

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten