2012-02-15 14 views
0

イムでテーブルビューから新しいビューに移動するときにアプリケーションがクラッシュしたばかり。私はテーブルビューを作成したイムは、このような単純な問題</p> <p>あなたに専門家を求めて、それが正常に動作している理由アンドロイド開発とのthatsで初心者がアンドロイド

最初のセルをクリックすると新しいビューに移動しようとしましたが、新しいファイルNewview.javaを作成しました。

しかし、最初のセルアプリケーションをクリックするとクラッシュし、「残念ながらHelloTableLayoutが停止しました」というメッセージが表示されます。

誰でもこれを手伝ってください。

HelloTableLayoutActivity.java 

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

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

     TextView name = (TextView)findViewById(R.id.label); 
     name.setOnClickListener(new View.OnClickListener() 
     { 

        public void onClick(View v) { 
     Intent nameActivity =new Intent(); 
     nameActivity .setClass(getApplicationContext(), Newview.class); 
     startActivity(nameActivity); 

    } 
     }); 
    } 
} 

Main.xml

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 

    <TextView 
     android:id="@+id/label" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <TableRow> 
     <TextView 
      android:layout_column="1" 
      android:text="@string/name" 
      android:padding="3dip" /> 
     <TextView 
      android:text="@string/initial" 
      android:gravity="right" 
      android:padding="3dip" /> 
    </TableRow> 

    <TableRow> 
     <TextView 
      android:layout_column="1" 
      android:text="@string/hometown" 
      android:padding="3dip" /> 
     <TextView 
      android:text="@string/state" 
      android:gravity="right" 
      android:padding="3dip" /> 
    </TableRow>  
</TableLayout> 

Newview.java

import android.app.Activity; 
import android.os.Bundle; 

public class Newview extends Activity 
{ 
/** Called when the activity is first created. */ 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.foo); 
    } 
} 

HelloTableLayoutマニフェスト

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.sweans.tb" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     > 
     <activity 
      android:label="@string/app_name" 
      android:name=".HelloTableLayoutActivity"> 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity 
      android:name=".NewviewActivity" 
      android:label="@string/app_name" 
      > 
     </activity> 

    </application> 

</manifest> 

foo.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <TextView 
     android:id="@+id/label" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 


</LinearLayout> 

誰でも私のコードで間違っていると、アプリがクラッシュする理由を助けてください。

ありがとうございます。

+0

クラッシュログ – josephus

+0

ここにLogCatトレースを投稿してください。赤色のテキストは問題ありません。 – SamSPICA

答えて

3

次のコードを変更してください。

Intent nameActivity =new Intent(); 
nameActivity .setClass(getApplicationContext(), Newview.class); 
startActivity(nameActivity); 

以下のコードを使用してください。

Intent nameActivity =new Intent(HelloTableLayoutActivity.this,Newview.class); 
startActivity(nameActivity); 

androidマニフェストファイルでNewviewクラスを定義します。あなたのメインクラスからNewviewを呼び出して、あなたは、AndroidマニフェストファイルにNewviewActvityクラスを宣言するので、あなたはその時点でのTextViewをクリックしたときには存在しないので、アンドロイドは、AndroidのマニフェストファイルにNewviewクラスを見つけ

<activity android:name=".Newview" > </activity> 

ためとして、そのマニフェストファイルがアプリケーションにクラッシュするように指示します。

+0

それは働いて問題を解決しました – suji

+0

私は新しいビューに移動したいと思っていたら、2番目と3番目の行をクリックするとどうすればいいのでしょうか? – suji

+0

あなたは同じように新しいビューを呼び出すことができます上記の例では、 –

関連する問題

 関連する問題