Java getExtras()返回null

Java getExtras()返回null,java,android,android-intent,android-activity,Java,Android,Android Intent,Android Activity,这是我的密码 在我的main.java文件中 public void showQuiz (View view){ Username = (EditText) findViewById(R.id.Username); String userId = Username.getText().toString(); String deviceId = Secure.getString(this.getContentResolver(),

这是我的密码

在我的main.java文件中

public void showQuiz (View view){
        Username = (EditText) findViewById(R.id.Username);
        String userId = Username.getText().toString();
        String deviceId = Secure.getString(this.getContentResolver(),
                Secure.ANDROID_ID);
       //this intent is used to open other activity wich contains another webView
         Intent intent = new Intent(this, Quiz.class);

         Bundle bun = new Bundle();
         bun.putString("userid",userId);
         bun.putString("deviceid", deviceId);

         intent.putExtras(bun);
         startActivity(intent); 
    }
package com.earn.egpt;

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

public class Quiz extends Activity {
    private static final String url = "http://www.m.s-w-family.com/?subid=";
    private static final String url2 = "&deid=";

     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_quiz);
            Bundle extras=getIntent().getExtras();
            String userId=extras.getString("userId");
            String deviceId=extras.getString("deviceId");
         WebView webview;
        webview = (WebView) findViewById(R.id.webView1);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url+userId+url2+deviceId);
        }
    }
这是活动的.java文件中的内容

public void showQuiz (View view){
        Username = (EditText) findViewById(R.id.Username);
        String userId = Username.getText().toString();
        String deviceId = Secure.getString(this.getContentResolver(),
                Secure.ANDROID_ID);
       //this intent is used to open other activity wich contains another webView
         Intent intent = new Intent(this, Quiz.class);

         Bundle bun = new Bundle();
         bun.putString("userid",userId);
         bun.putString("deviceid", deviceId);

         intent.putExtras(bun);
         startActivity(intent); 
    }
package com.earn.egpt;

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

public class Quiz extends Activity {
    private static final String url = "http://www.m.s-w-family.com/?subid=";
    private static final String url2 = "&deid=";

     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_quiz);
            Bundle extras=getIntent().getExtras();
            String userId=extras.getString("userId");
            String deviceId=extras.getString("deviceId");
         WebView webview;
        webview = (WebView) findViewById(R.id.webView1);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url+userId+url2+deviceId);
        }
    }

出于某种原因,它将字符串作为null传递,但我不知道为什么。我对这种编程非常陌生,所以我甚至不知道该去哪里。我已经研究了与我类似的其他问题,并尝试对其进行修复,但值仍然为空。

您无意中使用了额外的捆绑包。将额外内容直接放在意图中:

intent.putExtra("userid", userId);
intent.putExtra("deviceid", deviceId);

startActivity(intent); 

现在,您的
getString()
方法将返回您在测验中想要的内容。

注意变量的大小写。您正在插入“userid”并检索“userid”。

我收到了一个错误
方法putString(String,String)未定义类型意图
不幸的是,他们仍然返回NULLHmm,您在ShowQuike中仔细检查了值
userid
deviceId
?很好,Tim,我错过了。(UpDebug)@ KILI423考虑使用“代码>公共静态最终字符串< /代码>引用,而不是手写字符串,以防止将来出现这种错误。