0

これは私の LogCat のログです。

07-04 06:47:46.012: E/AndroidRuntime(2885): FATAL EXCEPTION: main
07-04 06:47:46.012: E/AndroidRuntime(2885): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.goodnight.ppt/com.goodnight.ppt.BoardActivity_wow}: java.lang.NullPointerException

これはメイン アクティビティ コードです。

package com.goodnight.ppt;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class BoardActivity_main extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.board_main);

        TabHost tabHost = getTabHost();


        //LOL tap
        Intent intent1;
        intent1 = new Intent().setClass(this, BoardActivity_lol.class);
        TabSpec sp1 = tabHost.newTabSpec("Tab1");
        sp1.setIndicator("LOL");
        sp1.setContent(intent1);
        tabHost.addTab(sp1);

        //WOW tap
        Intent intent2;
        intent2 = new Intent().setClass(this, BoardActivity_wow.class);
        TabSpec sp2 = tabHost.newTabSpec("Tab2");
        sp2.setIndicator("WOW");
        sp2.setContent(intent2);
        tabHost.addTab(sp2);

        //STAR tap
        Intent intent3;
        intent3 = new Intent().setClass(this, BoardActivity_star.class);
        TabSpec sp3 = tabHost.newTabSpec("Tab3");
        sp3.setIndicator("STAR");
        sp3.setContent(intent3);
        tabHost.addTab(sp3);

        //WIND tap
        Intent intent4;
        intent4= new Intent().setClass(this, BoardActivity_wind.class);
        TabSpec sp4 = tabHost.newTabSpec("Tab4");
        sp4.setIndicator("WIND");
        sp4.setContent(intent4);
        tabHost.addTab(sp4);


    }

}

メイン アクティビティの xml ファイル。

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                >


            </FrameLayout>



    </TabHost>

</LinearLayout>

これは他のアクティビティ (BoardActivity_wow) です。

    package com.goodnight.ppt;

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

public class BoardActivity_wow extends Activity implements OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.board_wow);

        Button writeButton_wow = new Button(this);
        writeButton_wow = (Button)findViewById(R.id.bbb);

        writeButton_wow.setOnClickListener(this);

    }

    public void onClick(View v){
        Intent wow = new Intent(this, BoardActivity_wow_write.class);
        startActivity(wow);
    }

}

BoardrActivity_wow の xml ファイル。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="bottom"
    android:orientation="vertical" >

    <Button
        android:id="@+id/boardWrite_lol"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Write_lol" />

</LinearLayout>

boardactivity_wow_write アクティビティ..

    package com.goodnight.ppt;

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

public class BoardActivity_wow_write extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.board_wow_write);

    }

}

BoardActivity_wow_write の xml ファイル..

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="bottom"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/title_wow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

   <EditText
        android:id="@+id/content_wow"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:ems="10"
        android:inputType="textMultiLine" >

    </EditText>

    <Button
        android:id="@+id/bbb"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="boardWrite_wow" />

</LinearLayout>

やあ、

このアプリを実行すると、強制停止します。このエラーの原因は OnClickListener だと思います。OnClickListener を削除すると、このアプリが実行されます。しかし、OnClickListenerが必要です...

4

3 に答える 3

2

BoardrActivity_wowid の Button がありません。Activitybbbのレイアウト内で宣言したものを使用する必要があります ( R.id.boardWrite_lol)

変化する

 Button writeButton_wow = new Button(this);
 writeButton_wow = (Button)findViewById(R.id.bbb);

Button  writeButton_wow = (Button)findViewById(R.id.boardWrite_lol);
于 2013-07-05T08:39:36.010 に答える
0

ボタンの名前boardWrite_lolbbb

于 2013-07-05T08:41:25.443 に答える
0

あなたはこれを持っています

setContentView(R.layout.board_wow);

そして、これはboard_wow.xmlにあります

 <Button
    android:id="@+id/boardWrite_lol" // id is boardWrite_lol
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Write_lol" />

これを変える

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.board_wow);
    Button writeButton_wow = new Button(this); // no need for this 
    writeButton_wow = (Button)findViewById(R.id.bbb); // change this statement.
    writeButton_wow.setOnClickListener(this);
    }

     @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.board_wow);
    Button writeButton_wow = (Button)findViewById(R.id.boardWrite_lol)
    writeButton_wow.setOnClickListener(this);
    }
于 2013-07-05T08:41:50.273 に答える