2012-02-10 90 views
-3

我無法讓我的應用程序工作,但在開發中沒有錯誤消息。 我試圖學習如何將我的頁面鏈接到另一個頁面。Android eclipse。運行我的應用程序時出錯

enter image description here

TMactivity第1

public class TmActivity extends Activity { 

    private ImageButton NewPage; 

    /** Called when the activity is first created. */ 

    @Override 

    public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    this.setContentView(R.layout.main); 

    this.NewPage = (ImageButton)this.findViewById(R.id.widget38); 

    this.NewPage.setOnClickListener(new OnClickListener() { 



public void onClick(View WebView) { 

Intent i = new Intent(TmActivity.this, New.class); 

startActivity(i); 

} 

}); 

} 

} 

//第2頁:

public class WebView extends Activity { 

     public class New extends Activity { 

      /** Called when the activity is first created. */ 

      @Override 

      public void onCreate(Bundle savedInstanceState) { 

      super.onCreate(savedInstanceState); 

      setContentView(R.layout.web); 

      } 

      } 
    } 

//第一XML:

<?xml version="1.0" encoding="utf-8"?> 
    <AbsoluteLayout 
     android:id="@+id/widget0" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 
    <ImageButton 
     android:id="@+id/widget37" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#FFFFFF" 
     android:layout_x="4dp" 
     android:layout_y="387dp" /> 
    <ImageButton 
     android:id="@+id/widget38" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="69dp" 
     android:layout_y="386dp" /> 
    <ImageButton 
     android:id="@+id/widget39" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="151dp" 
     android:layout_y="386dp" /> 
    <ImageButton 
     android:id="@+id/widget40" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="242dp" 
     android:layout_y="383dp" /> 
    <TextView 
     android:id="@+id/widget43" 
     android:layout_width="wrap_content" 
     android:layout_height="47px" 
     android:background="#FF0000" 
     android:text="Teknikmagasinet" 
     android:textSize="20sp" 
     android:typeface="sans" 
     android:textStyle="bold" 
     android:textColor="#FFFF00" 
     android:layout_x="74dp" 
     android:layout_y="11dp" /> 
    <TextView 
     android:id="@+id/widget44" 
     android:layout_width="203px" 
     android:layout_height="30px" 
      android:text="nyheter" 
     android:textColor="#FFFF00" 
     android:layout_x="34dp" 
     android:layout_y="77dp" /> 
    <ImageView 
     android:id="@+id/widget45" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#ff33cc00" 
     android:layout_x="44dp" 
     android:layout_y="143dp" /> 
    <TextView 
     android:id="@+id/widget46" 
     android:layout_width="wrap_content" 
     android:layout_height="47px" 
     android:background="#ffcc6600" 
     android:text=" emil bergstrlm han &#228;r kung " 
     android:hint="phuong" 
     android:layout_x="13dp" 
     android:layout_y="255dp" /> 
    </AbsoluteLayout> 

//第二XML:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    package="tm.com" 

    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    /> 

    <ImageButton 
     android:id="@+id/widget38" 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" /> 

    <Button 
    android:text="Second Page" 
    android:id="@+id/close" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"></Button> 

    </LinearLayout> 

    sting xml: 
    <?xml version="1.0" encoding="utf-8"?> 
    <resources> 

     <string name="hello">Hello World, TmActivity!</string> 
     <string name="app_name">Tm.com</string> 
     <string name="main_title">My Main Title</string> 
    </resources> 

感謝您的幫助!

+0

,而不是你的代碼ü需要來發表您的錯誤日誌。 – 2012-02-10 15:50:49

+3

我想你忘了在你的manifest.xml文件中註冊你的活動。 – 2012-02-10 15:51:07

+0

打開終端,輸入'adb locat'並找到錯誤(錯誤以「E /」開始行)。如果你打開終端並鍵入'adb logcat'然後嘗試啓動應用程序(打開終端),你將能夠看到錯誤發生的地方。 – 2012-02-10 15:52:29

回答

0

//從你的第二個活動

public class WebView extends Activity { 

刪除此生活中,在你的manifest.xml

+0

[2012-02-10 17時08分29秒 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] /Users/zamilio/Documents/workspace/tm/AndroidManifest.xml的解析器異常:元素類型「application」後面必須跟有屬性規範,「>」或「/>」。 [2012-02-10 17:08:29 - tm] XML文件錯誤:中止構建。 [2012-02-10 17:11:53 - tm] XML文件錯誤:中止構建。 – Emil 2012-02-10 16:19:11

0

如果我理解正確的,你想從已經運行的打開一個新的活動註冊新活動(切換你的頁面)?嘗試這個。

活動Main.java:

package tm.com 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 

public class TmActivity extends Activity { 
    /** Called when the activity is first created. */ 
     @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     final Button butn = (Button) findViewById(R.id.button1); 

     butn.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       Intent intent = new Intent(TmActivity.this, New.class); 
       startActivityForResult(intent, 0); 
      } 
     }); 
    } 
} 

佈局的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <Button android:id="@+id/button1" android:text="name" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
</RelativeLayout> 

在應用程序清單: *修改應用程序中的支架上的清單看起來像這樣。

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".TmActivity" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity>  
     <activity android:name=".New"></activity> 
</application> 
+0

02-10 17:26:38.690:D/dalvikvm(538):不延遲啓用CheckJNI(已啓用) 02-10 17:26:39.580:D/AndroidRuntime(538):關閉VM 02-10 17:26:39.580:W/dalvikvm(538):threadid = 1:線程以未捕獲的異常退出(group = 0x409c01f8) 02-10 17:26:39.610:E/AndroidRuntime(538):致命例外:main 02 -10 17:26:39.610:E/AndroidRuntime(538):java.lang.RuntimeException:無法實例化應用程序tm.com.Main:java.lang.ClassNotFoundException:tm.com.Main 02-10 17:26: 39.610:E/AndroidRuntime(538): – Emil 2012-02-10 16:29:08

+0

'Main'被替換爲你的類的名字,我把它放在那裏作爲一個虛擬名字,你可以用'TmActivity'替換它(每個你看到我放置'Main'的地方,例如作爲'android:name =「Main」'和'Intent(Main.this,..);'等等。 – gkiar 2012-02-10 16:35:13

+0

我已經編輯它爲ha在清單和java類中都有您的活動名稱。 – gkiar 2012-02-10 16:38:36

相關問題