1
이 코드를 Main.java 클래스에 작성했지만 프로그램이 실행되지 않습니다. 왜? 프로그램에는 Intent i=new Intent(this,Location.class);
의 오류가 있습니다. 무엇이 문제입니까 ??생성자가 정의되지 않았습니다. 오류
package org.example.loyaltier;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.content.Intent;
public class Main extends Activity {
private WebView mWebView;
private Button mHome;
private Button mProduct;
private Button mPlaces;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView)findViewById(R.id.web_view);
mHome = (Button)findViewById(R.id.button_home);
mProduct=(Button)findViewById(R.id.button_product);
mPlaces=(Button)findViewById(R.id.button_places);
mHome.setOnClickListener(onClickListener);
}
private OnClickListener onClickListener=new OnClickListener(){
public void onClick(View v){
switch(v.getId()){
case R.id.button_home:
mWebView.loadUrl ("http://loyaltier.com/app/mobile/code/home/home.php");
break;
case R.id.button_product:
mWebView.loadUrl("http://loyaltier.com/app/mobile/design/catalog/catalog1.php");
break;
case R.id.button_places:
Intent i=new Intent(this,Location.class);
startActivity(i);
break;
}
}
};
}
문제점은 다음과 같습니다 The constructor Intent(new View.OnClickListener(){}, Class<Location>) is undefined
하지만 난 문제가 무엇이며 어떻게이 해결할 수 이해하지?
나 빨리 도와주세요은)
로그 캣 :: new Intent(this,Location.class);
에서
10-31 11:35:04.135: D/AndroidRuntime(16626): Shutting down VM
10-31 11:35:04.135: W/dalvikvm(16626): threadid=1: thread exiting with uncaught exception (group=0x40a3e1f8)
10-31 11:35:04.159: E/AndroidRuntime(16626): FATAL EXCEPTION: main
10-31 11:35:04.159: E/AndroidRuntime(16626): java.lang.IllegalStateException: Could not find a method Places(View) in the activity class org.example.loyaltier.Main for onClick handler on view class android.widget.Button with id 'button_places'
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.view.View$1.onClick(View.java:3026)
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.view.View.performClick(View.java:3480)
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.view.View$PerformClick.run(View.java:13983)
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.os.Handler.handleCallback(Handler.java:605)
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.os.Handler.dispatchMessage(Handler.java:92)
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.os.Looper.loop(Looper.java:137)
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.app.ActivityThread.main(ActivityThread.java:4340)
10-31 11:35:04.159: E/AndroidRuntime(16626): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 11:35:04.159: E/AndroidRuntime(16626): at java.lang.reflect.Method.invoke(Method.java:511)
10-31 11:35:04.159: E/AndroidRuntime(16626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-31 11:35:04.159: E/AndroidRuntime(16626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-31 11:35:04.159: E/AndroidRuntime(16626): at dalvik.system.NativeStart.main(Native Method)
10-31 11:35:04.159: E/AndroidRuntime(16626): Caused by: java.lang.NoSuchMethodException: Places [class android.view.View]
10-31 11:35:04.159: E/AndroidRuntime(16626): at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-31 11:35:04.159: E/AndroidRuntime(16626): at java.lang.Class.getMethod(Class.java:915)
10-31 11:35:04.159: E/AndroidRuntime(16626): at android.view.View$1.onClick(View.java:3019)
10-31 11:35:04.159: E/AndroidRuntime(16626): ... 11 more
10-31 11:35:04.190: D/dalvikvm(16626): GC_CONCURRENT freed 212K, 3% free 14282K/14599K, paused 2ms+2ms
10-31 11:35:09.057: I/Process(16626): Sending signal. PID: 16626 SIG: 9
답변 해 주셔서 감사합니다. 이것을 Main.this로 바꿉니다. 그러나 장소 버튼이나 제품 버튼을 클릭하면 프로그램이 멈 춥니 다. 왜? 나는 첫 번째 글에서 LogCat을 쓴다. –
@PariyaDaghoghi 다른 질문이 있습니다 – Blackbelt
다른 페이지에서이 질문을하셨습니까? –