PDA

View Full Version : چرا onClick برای باتون در جاوا فعال نیست



علیرضا5
جمعه 05 آبان 1396, 08:25 صبح
سلام
من یک باتون در صفحه گذاشتم و براش کد نوشتم ولی چرا @Override و (onClick(View v در کد زیر خطا میده یعنی اصلا onClick جزو گزینه ها موقع تایپ نیست




Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {


Toast.makeText(MainActivity.this, " UnitAzad.ir!!", Toast.LENGTH_LONG).show();
}
});

علیرضا5
جمعه 05 آبان 1396, 22:18 عصر
دوستان لطفا جواب بدید

mz6488
شنبه 06 آبان 1396, 12:21 عصر
سلام
خطای چی میده؟

علیرضا5
شنبه 06 آبان 1396, 12:46 عصر
گفتم که زیر اون دوتا خط می اندازه
@Override و ( onClick(View
و onclike هم موقع تایپ تو گزینه ها نمیده
پیغام خطایی هم نمیده

محمد رضا فاتحی
شنبه 06 آبان 1396, 20:35 عصر
کل کد کلاستون رو قرار بدید...بخصوص اول کلاستون

علیرضا5
یک شنبه 07 آبان 1396, 00:43 صبح
بفرمائید






package com.rasaagahi.myapplication;


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.view.Menu;
import android.view.MenuItem;






public class MainActivity extends AppCompatActivity {


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


Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
// your code
}
});
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();
}
});
}


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


@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();


//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}


return super.onOptionsItemSelected(item);
}
}








اینهم پیغام خطا موقع اجرا



Information:Gradle tasks [:app:assembleDebug]
C:\Users\ali\Desktop\new\MyApplication\app\src\mai n\java\com\rasaagahi\myapplication\MainActivity.ja va
Error:(21, 9) error: cannot find symbol class Button
Error:(21, 21) error: cannot find symbol class Button
Error:(22, 34) error: cannot find symbol class OnClickListener
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 1 mins 22.698 secs
Information:4 errors
Information:0 warnings
Information:See complete output in console

mz6488
یک شنبه 07 آبان 1396, 09:49 صبح
ظاهرا کد زیر تو import وجود ندارره
import android.support.v7.widget.Button;

علیرضا5
دوشنبه 08 آبان 1396, 17:26 عصر
آقا ببخشید دیر شد
متاسفانه مشکل هست
یه پیغام خطای اینطوری هم در برنامه وجود داره که ظاهرا فابل idea.jar و Groovy.jar
رو پیدا نمیکنه





Entry fileTemplates//code/Google Test Fixture SetUp Method.cc.ft not found in D:/Android-Studio/lib/idea.jar




java.io.FileNotFoundException: Entry fileTemplates//code/Google Test Fixture SetUp Method.cc.ft not found in D:/Android-Studio/lib/idea.jar

java.io.FileNotFoundException: Entry fileTemplates//code/Groovy New Method Body.groovy.ft not found in D:/Android-Studio/plugins/Groovy/lib/Groovy.jar