Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击按钮时,uri意图在android 4.1.2中有效,但在android 2.3.7中不起作用_Java_Android_Url_Android Intent_Uri - Fatal编程技术网

Java 单击按钮时,uri意图在android 4.1.2中有效,但在android 2.3.7中不起作用

Java 单击按钮时,uri意图在android 4.1.2中有效,但在android 2.3.7中不起作用,java,android,url,android-intent,uri,Java,Android,Url,Android Intent,Uri,我有以下活动: package com.example.myapp; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.content.SharedPr

我有以下活动:

     package com.example.myapp;

     import android.net.Uri;
     import android.os.Bundle;
     import android.app.Activity;
     import android.content.ComponentName;
     import android.content.Intent;
     import android.content.SharedPreferences;
     import android.view.Menu;
     import android.view.View;
     import android.view.View.OnClickListener;
     import android.view.animation.Animation;
     import android.view.animation.Animation.AnimationListener;
     import android.view.animation.AnimationUtils;
     import android.widget.Button;
     import android.widget.ImageButton;
     import android.widget.ScrollView;
     import android.widget.Toast;

     public class HomeActivity extends Activity implements AnimationListener {

 // Animation
     Animation animFadein;
     Animation animFadeout;

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

// load the animation
    animFadein = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_in);
    animFadeout = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_out);

    // set animation listener
    animFadein.setAnimationListener(this);

ImageButton homepage =(ImageButton)findViewById(R.id.homepage);
    ImageButton new_b =(ImageButton)findViewById(R.id.new_b);
    ImageButton view_b =(ImageButton)findViewById(R.id.view_b);
    ImageButton home_b =(ImageButton)findViewById(R.id.home_b);
    ImageButton info_b =(ImageButton)findViewById(R.id.info_b);
    Button back_b =(Button)findViewById(R.id.back_b);
    Button site =(Button)findViewById(R.id.site);

    homepage.startAnimation(animFadein);

    //Click on screen to start
    homepage.setOnClickListener(new OnClickListener() {
@Override    
    public void onClick(View v) {
        View homepage = (View)findViewById(R.id.homepage);
        View startpage = (View)findViewById(R.id.startpage);
        homepage.setVisibility(View.GONE);
        homepage.startAnimation(animFadeout);
        startpage.setVisibility(View.VISIBLE);
        startpage.setAnimation(animFadein);};});  

    new_b.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        SharedPreferences values = getSharedPreferences("valoar", 0);
        SharedPreferences.Editor editor = values.edit();
        editor.clear(); 
        editor.commit();
        View startpage = (View)findViewById(R.id.startpage);
        startpage.setAnimation(animFadeout);
        Intent intent = new Intent(HomeActivity.this,QuestionsActivity.class);
        startActivity(intent);}});



    home_b.setOnClickListener(new OnClickListener() {
    @Override    
    public void onClick(View v) {
        View homepage = (View)findViewById(R.id.homepage);
        View startpage = (View)findViewById(R.id.startpage);
        homepage.setVisibility(View.VISIBLE);
        homepage.startAnimation(animFadein);
        startpage.startAnimation(animFadeout);
        startpage.setVisibility(View.GONE);};}); 

    info_b.setOnClickListener(new OnClickListener() {
        @Override    
        public void onClick(View v) {
            View startpage = (View)findViewById(R.id.startpage);
            View infopage = (View)findViewById(R.id.infopage);
            ScrollView info_s = (ScrollView)findViewById(R.id.info_s);
            infopage.setVisibility(View.VISIBLE);
            info_s.setVisibility(View.VISIBLE);
            infopage.startAnimation(animFadein);
            startpage.startAnimation(animFadeout);
            startpage.setVisibility(View.GONE);};});

    back_b.setOnClickListener(new OnClickListener() {
        @Override    
        public void onClick(View v) {
            View startpage = (View)findViewById(R.id.startpage);
            View infopage = (View)findViewById(R.id.infopage);
            ScrollView info_s = (ScrollView)findViewById(R.id.info_s);
            infopage.setVisibility(View.GONE);
            info_s.setVisibility(View.GONE);
            infopage.startAnimation(animFadeout);
            startpage.startAnimation(animFadein);
            startpage.setVisibility(View.VISIBLE);};});

    **site.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent internetIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://www.i-amapp.com"));
                internetIntent.setComponent(new ComponentName("com.android.browser","com.android.browser.BrowserActivity"));
                internetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(internetIntent);};});**



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.home, menu);
    return true;
}

@Override
public void onAnimationEnd(Animation arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub

}

/**
 * Back button listener.
 * Will close the application if the back button pressed twice.
 */
@Override
public void onBackPressed()
{
    int backButtonCount = 0;
    if(backButtonCount  >= 1)
    {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    }
    else
    {
        Toast.makeText(this, "Press the x button to close the application.", Toast.LENGTH_SHORT).show();
        backButtonCount++;
    }
}
}

它在android 4.1.2中运行良好,但在android 2.3.7中崩溃,Logcat显示:

D/AndroidRuntime(2172): Shutting down VM
W/dalvikvm(2172): threadid=1: thread exiting with uncaught exception (group=0x40018560)
E/AndroidRuntime(2172): FATAL EXCEPTION: main
E/AndroidRuntime(2172): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.HomeActivity}: java.lang.NullPointerException
E/AndroidRuntime(2172):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
E/AndroidRuntime(2172):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
E/AndroidRuntime(2172):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime(2172):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime(2172):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(2172):     at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(2172):     at android.app.ActivityThread.main(ActivityThread.java:3835)
E/AndroidRuntime(2172):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(2172):     at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(2172):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
E/AndroidRuntime(2172):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
E/AndroidRuntime(2172):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(2172): Caused by: java.lang.NullPointerException
E/AndroidRuntime(2172):     at com.example.myapp.HomeActivity.onCreate(HomeActivity.java:107)
E/AndroidRuntime(2172):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(2172):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
E/AndroidRuntime(2172):     ... 11 more
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 61K, 50% free 2724K/5379K, external 0K/0K, paused 44ms
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 4K, 50% free 2730K/5379K, external 507K/513K, paused 43ms
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 1K, 50% free 2736K/5379K, external 1068K/1524K, paused 43ms
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 1K, 50% free 2741K/5379K, external 1669K/2086K, paused
这就是logcat显示的全部内容。我想不出是什么问题!
为什么android 2.3会崩溃

请发布完整的stacktrace,包括嵌套的“由”NPE异常。如果您有空指针异常。发布日志,让我们看看这里没有初始化的内容。可能您正在使用一个相当新的方法来初始化一个在旧版本中不起作用的对象。可能您正在使用一些只能从某个API级别使用的东西?