cannot be referenced from a from static context HATASI
12.09.2016 - 05:29
main dosyası
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.nuri.toastresimmesaji.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YAZI GELSİN"
android:id="@+id/button1"
android:layout_alignParentTop="true"
android:layout_marginTop="79dp"
android:textSize="30dp"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESİM GELSİN"
android:id="@+id/button2"
android:textSize="30dp"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/button1"
android:layout_alignStart="@+id/button1" />
</RelativeLayout>
java
package com.nuri.toastresimmesaji;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button Btn1,Btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Btn1= (Button) findViewById(R.id.button1);
Btn2= (Button) findViewById(R.id.button2);
//Btn1.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v)
// {
// Toast.makeText(getApplicationContext(),"Bu bir Tost MEsajıdır",Toast.LENGTH_LONG).show();
// }
//});
Btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
ImageView resim=new ImageView(getApplicationContext());
resim.setImageResource(R.drawable.reklam);
Toast toast=new Toast(getApplicationContext());
Toast.setView(resim);
Toast.setDuration(Toast.LENGTH_LONG);
Toast.show();
}
});
}
}
hata ise
cannot be referenced from a from static context HATASI
MainActivity.java:36: error: non-static method setView(View) cannot be referenced from a static context
Toast.setView(resim);
^
MainActivity.java:37: error: non-static method setDuration(int) cannot be referenced from a static context
Toast.setDuration(Toast.LENGTH_LONG);
^
MainActivity.java:38: error: non-static method show() cannot be referenced from a static context
Toast.show();
^
3 errors
Bayağı uğraştırdı androidde bayağı yeniyim yardımlarınız için şimdiden
Teşekkürler
98
Görüntülenme
0 Beğeni