java - Helloworld Doesn't run on Emulator -


okay, ticking me off. ran on both emulator , on android device. code not display "helloworld, android -mykong.com". start app, find on emulator, click on it, , goes interface of app. however, blank screen! error not issue of me finding app, not emulator or android phone, issue has lie either in code or in way code structured/built. know the helloworld code 100% correct because reputable tutorial site. these 3 pairs of code. please help, in desperate need!

androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.test123"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.test123.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>  </manifest> 

mainactivity.java

package com.example.test123;  import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.menu;  public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);     }     public void activity()     {     intent helloworld = new intent(getapplicationcontext(), helloworldjavaactivity.class );     startactivity( helloworld );     }     @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     } } 

helloworldjavaactivity.java

package com.example.test123;  import android.app.activity; import android.os.bundle; import android.widget.textview;  public class helloworldjavaactivity extends activity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          textview text = new textview(this);         text.settext("hello world, android - mkyong.com");         setcontentview(text);     } } 

activity_main.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="35dp"         android:layout_margintop="57dp"         android:text=""          />  </relativelayout> 

you're not starting helloworldjavaactivity.java activity. need following in mainactivity:

intent helloworld = new intent(getapplicationcontext(), helloworldjavaactivity.class ); startactivity( helloworld ); 

of course, need code triggered even, button press example.

it easier eliminate second activity (since mainactivity isn't doing anyway) , put code in mainactivity instead. you'll need edit layout mainactivity includes appropriate views.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -