2016-05-04 29 views
2

私はAndroidスタジオを使用して最初のアプリケーションを作成しています。私はhttp://developer.android.com/training/basics/firstapp/starting-activity.html#DisplayMessageの指示に従っていますが、setTextSize、setText、addViewのシンボルエラーを複数解決できません。 alt + Enterを使用してTextViewをインポートしましたが、まだエラーが発生しています。私はこれに初心者であり、助けを感謝します。前もって感謝します。私は、あなたがのonCreateたりのonCreateメソッドの内部で呼ばれている別のJavaメソッド内のコードを配置する必要があり、私のDisplayMessageActivity.javaAndroidスタジオのシンボルsetTextSize、setText、addViewを解決できません

package com.deepdil.hello; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 


public class DisplayMessageActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_display_message); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
     } 
    }); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
} 
Intent intent = getIntent(); 
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); 
TextView textView= new TextView(this); 
textView.setTextSize(40); 
textView.setText(message); 
RelativeLayout layout = (RelativeLayout) findViewById(R.id.content); 
layout.addView(textView); 
} 
+0

文はonCreateメソッド内にありますか。あなたは適切に中括弧ですか? – Raghunandan

+0

いいえ、そうではありませんでした。申し訳ありませんが、私はそれを逃しました。おかげさまで100万人になりました:)その解決済み –

答えて

3

を含めています。

Javaは関数型プログラミング言語ではないので、このコードをメソッドの中に配置する必要があります。

Intent intent = getIntent(); 
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); 
TextView textView= new TextView(this); 
textView.setTextSize(40); 
textView.setText(message); 
RelativeLayout layout = (RelativeLayout) findViewById(R.id.content); 
layout.addView(textView); 
関連する問題