Error:(45, 43) error: no suitable constructor found for Intent(,Class) constructor Intent.Intent(String,Uri) is not applicable (argument mismatch; cannot be converted to String) constructor Intent.Intent(Context,Class) is not applicable (argument mismatch; cannot be converted to Context) Error:(51, 44) error: no suitable constructor found for Intent(,Class) constructor Intent.Intent(String,Uri) is not applicable (argument mismatch; cannot be converted to String) constructor Intent.Intent(Context,Class) is not applicable (argument mismatch; cannot be converted to Context) Error:(57, 43) error: no suitable constructor found for Intent(,Class) constructor Intent.Intent(String,Uri) is not applicable (argument mismatch; cannot be converted to String) constructor Intent.Intent(Context,Class) is not applicable (argument mismatch; cannot be converted to Context) Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Menu.java パブリッククラスメニューAppCompatActivity
activity_menu.xml {ListView lv;
private static String[] menu_list = { "list one", "list 2", "list 3" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
listview();
}
public void listview() {
lv = (ListView) findViewById(R.id.lv_Menu_List);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.list_layout, menu_list);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// String value =(String)lv.getItemAtPosition(position);
if (position == 0) {
Intent intent = new Intent(this, ListOne.class);
startActivity(intent);
} else if (position == 1) {
Intent intent = new Intent(this, List2.class);
startActivity(intent);
} else if (position == 2) {
Intent intent = new Intent(this, List3.class);
startActivity(intent);
}
}
});
}
}
を拡張
<?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.example.examplemenu.Menu"> <ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/lv_Menu_List" android:layout_centerHorizontal="true" android:layout_alignParentTop="true" /> </RelativeLayout>
list_layout.xml
<xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:soundEffectsEnabled="true">
</TextView>
この行を変更する意図インテント=新しいインテント(this、List2.class);インテントの意図=新しいインテント(Menu.this、List2.class); – Killer
は、「これは」は現在のコンテキストを返し、ここにあなたが内部クラス内でこれを使用している、ので、「これは」真剣ないMenu.class(Activityコンテキスト) – Killer