androidアプリの開発 WebViewに受信したデータを表示する際にnullのテキストリンクが表示される

このQ&Aのポイント
  • androidアプリの開発について質問です。受信したデータをWebViewに表示すると、WebView領域にnullというテキストリンクが表示されます。通常のデータは正常に表示されています。nullのテキストリンクをクリックするとページが表示されません。
  • 質問:androidアプリの開発において、受信したデータをWebViewに表示した結果、nullのテキストリンクが表示される問題が発生しています。どなたか対処法をご存知の方がいらっしゃいましたら、教えていただけないでしょうか?
  • androidアプリの開発において、WebViewに受信したデータを表示する際にnullのテキストリンクが表示される問題が発生しています。通常のデータは正常に表示されていますが、nullのテキストリンクをクリックするとページが表示されません。どなたか解決策をご存知の方がいましたら、教えてください。
回答を見る
  • ベストアンサー

androidアプリの開発 WebView

androidアプリの開発について質問です。 現在intentによりデータを受信して表示する事までができたのですが、 受信したデータをWebViewにて表示をすると、 WebView領域にnull というテキストリンクまでもが表示されます。 通常のデータは正常に表示されています。 ちなみに null のテキストリンクをクリックしても ページが表示されませんというエラーが出るだけです。 どなたかご存知の方がいましたらご教授くださいませ。 以下ソース抜粋 if (intent != null) { String tmp = ""; String desc = ""; TextView tv; tv = (TextView) findViewById(R.id.item_detail_title); tmp = intent.getStringExtra("TITLE"); tv.setText(tmp); tv = (TextView) findViewById(R.id.item_detail_descr); tmp = intent.getStringExtra("DESCRIPTION"); tv.setText(tmp); WebView wv = (WebView) findViewById(R.id.Des); desc = WEBVIEW_BEGIN; tmp = intent.getStringExtra("Link"); desc += String.format(WEBVIEW_LINK, tmp, tmp); tmp = intent.getStringExtra("DESCRIPTION"); desc += tmp + WEBVIEW_END; wv.loadDataWithBaseURL("about:blank", desc, "text/html", "utf-8", null); }

  • Java
  • 回答数1
  • ありがとう数2

質問者が選んだベストアンサー

  • ベストアンサー
noname#177743
noname#177743
回答No.1

WEBVIEW_BEGINにはどんな値が設定されているのでしょうか。 WEBVIEW_BEGIN、WEBVIEW_LINK、WEBVIEW_ENDといったものに正しく値は設定されているでしょうか。まずはそのあたりから確認してみてはいかがでしょう。

javamanx
質問者

お礼

ご返答遅くなり申し訳ございません。 WEBVIEW_LINKの値が抜けていたのが原因でした。 おかげ様で解決致しました。 ありがとうございます!

関連するQ&A

  • webviewを使用したandroidアプリ

    現在WebViewを使用したandroidアプリを作成中です。 webview領域を更新するボタンを作成したいのですが、 手順がわからず困っています。 内容的には intentにてListViewを生成(タイトルと日付を表示)→リストをクリックすると タイトル(TextView)・日付(TextView)・詳細文言(WebView)が 別Activityにて表示される内容になっています。 詳細文言を表示されるページにてWebView領域更新ボタンを作成したいが うまく行かないという状況です。 現在作成した内容は下記になり、このコードで更新をすると WebView領域には何も表示がされない状況となります。 public boolean onOptionsItemSelected(MenuItem item) { WebView myWebView =(WebView)findViewById(R.id.webView1); switch (item.getItemId()) { case MENU_SELECT_A: //更新が押されたときの処理 myWebView.reload(); return true; } return false; } わかる方がいらっしゃいましたら、ご指導お願いいたします。

  • AndroidアプリからMySQLのデータ取得

    こんにちは。 今、androidの勉強をしながらアプリを作成しています。 androidやjavaの知識レベルは、初心者レベルです。 タイトルにもあるように、AndroidアプリからMySQLのデータ取得方法がわかりません。 今現在、eclipse内のエミュレータではデータの取得と表示はできています。 しかしながら、実機でテストをすると、データが取れていません。 なにぶん初心者なので、どこを見れば良いか、何を設定すれば好いか、いきあたりばったりでテストしています。皆様のアドバイス宜しくお願いします。 【開発環境】 windowsXP eclipse3.5 mysql5.1(ユーザー、IP、ポート、データベース、テーブルなどは設定済み) jdbc5.1(構成パスにJDBCは追加済み) 【ソース一部抜粋】 public class Prof extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Connection conn = null; Statement stmt = null; ResultSet rs = null; setContentView(R.layout.prof); TextView set_NameLabel = (TextView) findViewById(R.id.set_nameLabel); TextView set_oldLabel = (TextView) findViewById(R.id.set_oldLabel); TextView set_jobLabel = (TextView) findViewById(R.id.set_jobLabel); TextView set_addLabel = (TextView) findViewById(R.id.set_addLabel); TextView set_homeLabel = (TextView) findViewById(R.id.set_homeLabel); TextView set_hobbyLabel = (TextView) findViewById(R.id.set_hobbyLabel); TextView set_comentLabel = (TextView) findViewById(R.id.set_comentLabel); try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://10.0.2.2:3306/prof_db","test_01","test_pass"); stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM my_prof"); rs.next(); set_NameLabel.setText(rs.getString("prof_name")); set_oldLabel.setText(rs.getString("prof_age")); set_jobLabel.setText(rs.getString("prof_occupation")); set_addLabel.setText(rs.getString("prof_address")); set_homeLabel.setText(rs.getString("prof_home")); set_hobbyLabel.setText(rs.getString("prof_hobby")); set_comentLabel.setText(rs.getString("prof_comment")); conn.close(); rs.close(); stmt.close(); } catch (ClassNotFoundException e){ e.printStackTrace(); } catch ( SQLException e) { e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); } } } 何かしらのアドバイス、解決方法、参考HPなど、ご教授宜しくお願いします。

  • nullpointexceptionについて

    プログラミング初心者です。 エラーが全くわかりません。 ボタンを押すと、リストビューに移動するというものなんですが、ボタンを押すとnullpointexceptionが出ます。 最後の、et.setText(str);でエラーになっているようなんですが、 お分かりになる方いらっしゃいますか・・・? よろしくお願いいたします。 public class MainActivity extends Activity { EditText text_naiyou =null; Button save=null; Button buck=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); save=(Button)findViewById(R.id.save); buck=(Button)findViewById(R.id.buck); text_naiyou=(EditText)findViewById(R.id.text_naiyou); save.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText et = (EditText)findViewById(R.id.text_naiyou); String str = et.getText().toString(); Intent intent = new Intent(); intent.setClass(getApplicationContext(), ListActivity.class); String pkg = getPackageName(); intent.putExtra(pkg + ".input",str); startActivity(intent); public class ListActivity extends Activity { EditText text_naiyou =null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); Intent intent = getIntent(); String pkg = getPackageName(); String str = intent.getStringExtra(pkg + ".input"); EditText et = (EditText)findViewById(R.id.text_naiyou); et.setText(str);

  • 【Android開発】ボタンのテキスト表示

    Android初心者です。現在画面遷移先の画面に配列で設定した質問文、選択肢を表示するアプリを制作しています。質問文はTextView、選択肢は2つのButtonにテキストとして表示する。画面遷移した後にsetQuestion()、setChoiceを呼び出したいんですが実機で試したところ、画面遷移した後に「問題が発生しため、(アプリ名)を終了します」とポップアップが出て、アプリが落ちます。 この2つのメソッドをonCreateに入れるのは間違なのでしょうか?どうすればうまくいきますか?初心者なのでうまく書けてないかも知れません。 よろしくお願いします。 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sub); setChoice(); setQuestion();  } int number = 0; //質問番号 //選択肢 Button button1; Button button2; Button button3; Button button4; //質問文を配列に格納 static String question[] = { "質問文1", "質問文2", }; //選択肢 static String choice[][] = { {"1番", "2番", "3番", "4番"}, {"1番", "2番", "3番", "4番"}, }; //問題の回答 static String answer[] = { "2番", "4番" }; //出力 //質問文を表示 public void setQuestion() { String setQuestion = question[number]; // TextView question = (TextView) findViewById(R.id.Question); question.setText(setQuestion); } //選択肢の表示 public void setChoice() { TextView button1 = (Button) findViewById(R.id.button1); TextView button2 = (Button) findViewById(R.id.button2); button1.setText(choice[number][0]); button2.setText(choice[number][1]); } xml <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Question" android:id="@+id/Question" android:textSize="40dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="81dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:textSize="30dp" android:onClick="choiceClick" android:layout_above="@+id/button2" android:layout_centerHorizontal="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:textSize="30dp" android:onClick="choiceClick" android:layout_alignParentBottom="true" android:layout_alignLeft="@+id/button1" android:layout_alignStart="@+id/button1" />

  • android studioのlistview

    listviewに他画面から、受け取ったデータを追加する方法について、質問です。 他画面から、データを受け取って、textviewに表示させることは出来たのですが、listに追加することが出来ません。 text = (TextView)findViewById(R.id.++); と text.setText(data.getCharSequenceExtra("key")); という感じでテキストには表示することは可能でした。listに追加していく方法を教えて下さい。 list.add(data.getCharSequenceExtra("key"));じゃ、出来ませよね。。

  • androidアプリ開発について

    androidアプリ開発初心者です。 やりたいことは、 スタートボタンを押して、自分のお気に入りのページに飛び、(例えばオークションなど)サイトを表示させ、何分間ごとに更新できるループ処理?などができればいいなと考えています。 スタートボタンを押してサイトを表示するまでは何とか作れたのですが、それ以降をどのように作ったらいいのか分かりません。 初心者的な質問で申し訳ないのですが、どのように書いたらよいのか教えてください。 コードはこのようになっています。 <<main.xml>> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="192dp" android:layout_height="wrap_content" android:text="スタート" /> </LinearLayout> <<MainActivity.java>> import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { Button btn =null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn=(Button)findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ Uri uri =Uri.parse("http://"); Intent intent=new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(uri); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 長文で申し訳ありません。どうぞ宜しくお願い致します。

  • android getFromLocationが?

    Android初心者です。 下記コードでエラーとなり、解決策が見当たらず、非常に困っています。 どなたがご教授をお願いします。 public class MapViewSample extends MapActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView)findViewById(R.id.MapView01); mapView.setClickable(true); mapView.setBuiltInZoomControls(true); ConcreteOverlay overlay = new ConcreteOverlay(this); List<Overlay> overlayList = mapView.getOverlays(); overlayList.add(overlay); } protected boolean isRouteDisplayed() { return false; } private class ConcreteOverlay extends Overlay { GeoPoint mGeoPoint; Geocoder mGeocoder; ConcreteOverlay(Context context) { mGeocoder = new Geocoder(context, Locale.JAPAN); } public boolean onTap(GeoPoint point, MapView mapView) { mGeoPoint = point; try { TextView textView = (TextView)findViewById(R.id.TextView01); boolean success = false; ★ここでエラー⇒ List<Address>addressList = mGeocoder.getFromLocation(point.getLatitudeE6()/1E6, point.getLongitudeE6()/1E6, 5); for (Iterator<Address> it=addressList.iterator(); it.hasNext();) { Address address = it.next(); String country = address.getCountryName(); String admin = address.getAdminArea(); String locality = address.getLocality(); if(country != null && admin != null & locality != null) { textView.setText(country + admin + locality); success = true; break; } } if(!success) textView.setText("Error"); textView.invalidate(); } catch (Exception e){ Toast.makeText(getApplicationContext(), "ErrorToast", 1000).show(); } return super.onTap(point, mapView); } public void draw(Canvas canvas, MapView mapView, boolean shadow) {          ・・・省略・・・ } } }

    • ベストアンサー
    • Java
  • android HashMapについて助言お願いし

    初心者ですが、どうぞ宜しくお願いします。 下記コードでは、マップに 「 map.put( "Key1", "val1" ); map.put( "key2", "val2" ); 」を追加しているのですが、このデータをキーから取り出しテキストビューに表示しようとしています。 このままではエラーはないのですが、何も表示されない状況です。 初心者の無知な質問となりますが、 テキストビューへの表示方法はどのようにすればよいのでしょうか? 何か別の方法でもよいので、ご教授宜しくお願いいたします。 -------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv1"></TextView> </LinearLayout> ------------------------------------------------------------ package com.test; import java.util.HashMap; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //1)HashMapからMapのインスタンスを生成 HashMap<String, String> map = new HashMap<String, String>(); // キーと値のペアを格納 map.put( "Key1", "val1" ); map.put( "key2", "val2" ); // 指定したキーに対応する値を取得. String val = (String)map.get( "key1" ); // テキストビュー取得 TextView tv = (TextView)findViewById(R.id.tv1); tv.setText(val); } }

    • ベストアンサー
    • Java
  • androidでアプリを作ろうとしてるのですが

    package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; public class InOutTest extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public TextView txtResult; public TextView txtjudge; public String strInch; public String gettext; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから // ラベル txtInfo = new TextView(this); txtInfo.setText("check"); strInch = ("check"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setText("check"); layout.addView(txtjudge); //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ public void onClick(View v) { gettext = edtText.toString(); if (strInch==gettext){ txtjudge.setText("ok"); } }; }); }} 上のプログラムで strInchに入ってるデータとgettextで取得した文章を比較して同じなら txtjudgeにOKと引き渡して表示させたいのですがうまく動きません 何方かどうぞよろしくお願い致します

    • ベストアンサー
    • Java
  • Androidアプリの開発について

    アンドロイドアプリ開発の勉強をしておりますが 全くの素人のためご教授願います。 以下で、氏名1を選択すると、勤務表が表示されるのですが スクロールされずに悩んでおります。 自分なりに調べてみると XMLでScrollViewの中にTextViewを入れれば スクロールされるようなのですが、うまくスクロールされません。 どのように記述すれば、スクロールされるのでしょうか? 以上、宜しくお願いいたします。 package test.kintai; /**import java.nio.charset.Charset; */ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.widget.TextView; public class kintai extends Activity implements DialogInterface.OnClickListener{ /** Called when the activity is first created. */ public AlertDialog _alertDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } public void onResume(){ super.onResume(); CharSequence[] _char = {"氏名1","氏名2","氏名3","氏名4","氏名5","氏名6","氏名7"}; _alertDialog = new AlertDialog.Builder(this) .setTitle("勤務表") .setCancelable(false) .setItems(_char, this).show(); } @Override public void onClick(DialogInterface dialog, int which) { setContentView(R.layout.main); if(_alertDialog == dialog){ TextView display = new TextView(this); switch(which){ case 0: display.setText("氏名1\n" + "\n" + "2011年4月\n" + "\n" + " 1日(日) 休\n" + " 2日(月) 夜勤\n" + " 3日(火) 休\n" + " 4日(水) 休\n" + " 5日(木) 休\n" + " 6日(金) 夜勤\n" + " 7日(土) 休\n" + " 8日(日) 休\n" + " 9日(月) 日勤\n" + "10日(火) 日勤\n" + "11日(水) 日勤\n" + "12日(木) 日勤\n" + "13日(金) 夜勤\n" + "14日(土) 休\n" + "15日(日) 休\n" + "16日(月) 日勤\n" + "17日(火) 日勤\n" + "18日(水) 日勤\n" + "19日(木) 日勤\n" + "20日(金) 夜勤\n" + "21日(土) 休\n" + "22日(日) 休\n" + "23日(月) 日勤\n" + "24日(火) 日勤\n" + "25日(水) 日勤\n" + "26日(木) 日勤\n" + "27日(金) 夜勤\n" + "28日(土) 休\n" + "29日(日) 休\n" + "30日(月) 日勤\n" + "31日(火) 日勤\n"); break; case 1: display.setText("氏名2"); break; case 2: display.setText("氏名3"); break; case 3: display.setText("氏名4"); break; case 4: display.setText("氏名5"); break; case 5: display.setText("氏名6"); break; case 6: display.setText("氏名7"); break; } setContentView(display); } } } --------------- ■main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/display" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </ScrollView> </LinearLayout>

専門家に質問してみよう