second class - not found

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

second class - not found

Postby königdmx » Wed Feb 27, 2008 1:24 pm

Hi,

I have tested a little application, which call from a first class a method owned by a second class. Hier is the code:

first class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.app.Activity;
  3.  
  4. import android.os.Bundle;
  5.  
  6.  
  7.  
  8. public class Erste extends Activity {
  9.  
  10.    
  11.  
  12.         @Override
  13.  
  14.         public void onCreate(Bundle icicle) {
  15.  
  16.         super.onCreate(icicle);
  17.  
  18.        
  19.  
  20.         Zweite zweite = new Zweite();
  21.  
  22.         zweite.drucken();
  23.  
  24.     }
  25.  
  26. }
  27.  
  28.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

second class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.app.Activity;
  3.  
  4. import android.os.Bundle;
  5.  
  6. import android.widget.TextView;
  7.  
  8.  
  9.  
  10. public class Zweite extends Activity {
  11.  
  12.    
  13.  
  14.         private int counter;
  15.  
  16.        
  17.  
  18.     @Override
  19.  
  20.     public void onCreate(Bundle icicle) {
  21.  
  22.         super.onCreate(icicle);
  23.  
  24.                
  25.  
  26.         counter = 10;
  27.  
  28.     }
  29.  
  30.    
  31.  
  32.     public void drucken (){
  33.  
  34.         TextView tv = new TextView(this);
  35.  
  36.         tv.setText("\n\nWelcome to the World of ... (counter: " + counter + ")");
  37.  
  38.         setContentView(tv);
  39.  
  40.     }
  41.  
  42. }
  43.  
  44.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


the xml-file:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    package="com.android.ANDJ">
  7.  
  8.     <application android:icon="@drawable/icon">
  9.  
  10.         <activity android:name=".Erste" android:label="@string/app_name">
  11.  
  12.             <intent-filter>
  13.  
  14.                 <action android:name="android.intent.action.MAIN" />
  15.  
  16.                 <category android:name="android.intent.category.LAUNCHER" />
  17.  
  18.             </intent-filter>
  19.  
  20.         </activity>
  21.  
  22.         <activity android:name=".Zweite" android:label="@string/app_name">
  23.  
  24.             <intent-filter>
  25.  
  26.                 <action android:name="android.intent.action.MAIN" />
  27.  
  28.                 <category android:name="android.intent.category.LAUNCHER" />
  29.  
  30.             </intent-filter>
  31.  
  32.         </activity>
  33.  
  34.     </application>
  35.  
  36. </manifest>
  37.  
  38.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


when I start the debug-mode, the display on emulator stay black, but I can see the application name. Eclipse opens the "Class File Editor - Source not found" ActivityThread.class..

Whats my problem??
Thx
königdmx
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Feb 19, 2008 11:09 am

Top

Postby plusminus » Wed Feb 27, 2008 1:32 pm

Hello königdmx

other Activities are started using Intents, not using the Constructor!
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.           /* Create intent which will finally start the "Zweite"-Activity. */
  2.  
  3.           Intent myStarterIntent = new Intent(this, Zweite.class);
  4.  
  5.  
  6.  
  7.           /* Send the Intent to the OS. */
  8.  
  9.           this.startActivity(myStarterIntent);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Additionally when you write :darrow: to ".Zweite" in AndroidManifest.xml, it will be launchable from "outside".
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.                 <action android:name="android.intent.action.MAIN" />
  2.  
  3.                 <category android:name="android.intent.category.LAUNCHER" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

This is what you should write instead:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.                 <action android:name="android.intent.action.DEFAULT" />
  2.  
  3.                 <category android:name="android.intent.category.VIEW" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I suggest to read:
http://www.anddev.org/viewtopic.php?t=99
and after that:
http://www.anddev.org/viewtopic.php?t=305

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby königdmx » Wed Feb 27, 2008 1:37 pm

thank you plusminus!!
it works..
königdmx
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Feb 19, 2008 11:09 am

Top

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests