屏幕之间的android多屏幕问题

时间:2011-11-08 03:24:27

标签: android multiscreen

我有一个只有第一个按钮才能工作的多屏幕应用程序。当他们转到下一个java文件时,其他按钮会崩溃。在清单中,我列出了所有这些,但我不知道为什么会崩溃。有任何想法吗?     包com.mike.BrowserScreen;     import android.app.Activity;     import android.os.Bundle;     import android.widget。;     import android.view。;     import android.content.Intent;

 public class BrowserScreenActivity extends Activity {
 /** Called when the activity is first created. */
Button flea=null; 
Button bu1=null;
Button bu2=null;
Button bu3=null;
TextView tv1=null; 
TextView tv2=null;
TextView tv3=null; 
TextView tv4=null; 
TextView tv5=null;
TextView tv6=null; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    flea=(Button)findViewById(R.id.flea);
    bu1=(Button)findViewById(R.id.bu1);
    bu2=(Button)findViewById(R.id.bu2);
    bu3=(Button)findViewById(R.id.bu3);
    tv1=(TextView)findViewById(R.id.tv1);
    tv2=(TextView)findViewById(R.id.tv2);
    tv3=(TextView)findViewById(R.id.tv3);
    tv4=(TextView)findViewById(R.id.tv4);
    tv5=(TextView)findViewById(R.id.tv5);
    tv6=(TextView)findViewById(R.id.tv6);
    flea.setOnClickListener(new View.OnClickListener(){ 
    public void onClick(View v){ 
     Intent myIntent=new Intent(v.getContext(),SecondActivity.class);
    startActivity(myIntent); 
                }
          });

        bu1.setOnClickListener(new View.OnClickListener(){ 
      public void onClick(View v){ 
       Intent myIntent1=new Intent(v.getContext(),ThirdActivity.class);
     startActivity(myIntent1); 
           }
         }); 
      bu2.setOnClickListener(new View.OnClickListener(){ 
      public void onClick(View v){ 
      Intent myIntent2=new Intent(v.getContext(),FourthActivity.class);
      startActivity(myIntent2); 
          }
     });
     bu3.setOnClickListener(new View.OnClickListener(){ 
      public void onClick(View v){ 
      Intent myIntent3=new Intent(v.getContext(),FifthActivity.class);
      startActivity(myIntent3); 
        }
         }); 
      } 
    }

继承清单                         

    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".BrowserScreenActivity"
              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=".SecondActivity"></activity>
    <activity android:name=".ThirdActivity"></activity>
    <activity android:name=".ForthActivity"></activity>
    <activity android:name=".FifthActivity"></activity>
    </application>
    </manifest>

我在其他java文件中找到它我忘了将其更改为正确的xml文件。我将有另一个问题从textview或按钮启动网站

1 个答案:

答案 0 :(得分:1)

启动新活动..

而不是v.getContext()使用BrowserScreenActivity.thisgetBaseContext()

像这样

 flea.setOnClickListener(new View.OnClickListener(){ 
    public void onClick(View v){ 
     Intent myIntent=new Intent(BrowserScreenActivity.this,SecondActivity.class);
    startActivity(myIntent); 
                }
          });