Runtime Error because of ListView id - java

i'm still new at learning java and this is my first android app and it used to work but now it just shows me an error whenever i try to run this page :
package com.ds.rssreader;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
public class StartingPoint extends ListActivity {
Button Add;
Button Delete;
public static String Menu[];
public static int Menu_counter = 0;
ListView Sites;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.starting);
Add = (Button) findViewById(R.id.Add);
Delete = (Button) findViewById(R.id.Delete);
Sites = (ListView) findViewById(R.id.list);
Add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenAddPage = new Intent("com.ds.rssreader.AddPage");
startActivity(OpenAddPage);
}
});
Delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenDeletePage = new Intent(
"com.ds.rssreader.DeletePage");
startActivity(OpenDeletePage);
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
and here it's Layout:
<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:padding="25dp"
tools:context="com.ds.rssreader.StartingPoint" >
<Button
android:id="#+id/Add"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Add"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/Delete"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Delete"
tools:ignore="HardcodedText" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/Add"
android:clickable="true"
tools:ignore="HardcodedText" >
</ListView>
</RelativeLayout>
and here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ds.rssreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:name="android.permission.INTERNET"
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.ds.rssreader.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.StartingPoint" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.AddPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.AddPage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.DeletePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.DeletePage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSFeed"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSFeed" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSHandler"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSHandler" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSItem"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSItem" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
the error causes the program to crash whenever i try to open this page and it says :
E/AndroidRuntime(1085): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ds.rssreader/com.ds.rssreader.StartingPoint}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
and when i try to debug it, it tells me that there is something's source not found
and for the record when i make any other page opens instead of this page it opens without any problems.
REMEMBER GUYS : I'm new in java so don't say big words try to simplify as much as you can
Thanks

In your layout, change:
android:id="#+id/list"
to
android:id="#id/android:list"
and, in your class change:
Sites = (ListView) findViewById(R.id.list);
to
Sites = (ListView) findViewById(android.R.id.list);

Related

App showing a blank screen but Preview looks fine

So I've tried to write an application that saves relatively high-quality images but when I start the app in an emulator or my phone, it only shows a blank screen. In the Preview, it looks like it should look.
I have little experience in Java. Not much tho. I've tried a few things like changing the layout or what is displayed but nothing really worked or made any difference.
This is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cameraexample">
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".DisplayImage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:authorities="com.example.android.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_path" />
</provider>
</application>
</manifest>
This is the activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/capture_image"
android:onClick="captureImage"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/display_image"
android:onClick="displayImage"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
This is activity_main source code:
public class MainActivity extends AppCompatActivity {
String currentImagePath = null;
private static final int IMAGE_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void captureImage(View view) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(cameraIntent.resolveActivity(getPackageManager()) != null){
File imageFile = null;
try {
imageFile = getImageFile();
}
catch (IOException e) {
e.printStackTrace();
}
if(imageFile != null) {
Uri imageUri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, IMAGE_REQUEST);
}
}
}
public void displayImage(View view) {
Intent intent = new Intent(this, DisplayImage.class);
intent.putExtra("image_path", currentImagePath);
startActivity(intent);
}
private File getImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageName = "jps_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(imageName, ".jpg", storageDir);
currentImagePath = imageFile.getAbsolutePath();
return imageFile;
}
}
This is the activity_display_image.xml:
<?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"
tools:context=".DisplayImage">
<ImageView
android:contentDescription="#string/bild_ansicht"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
android:id="#+id/mimageView"/>
</RelativeLayout>
And last but not least, it's source code:
public class DisplayImage extends AppCompatActivity {
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_image);
imageView = findViewById(R.id.mimageView);
Bitmap bitmap = BitmapFactory.decodeFile(getIntent().getStringExtra("image_path"));
imageView.setImageBitmap(bitmap);
}
}
There are no error messages. I want those buttons to show up. The rest should work just fine.
It seems like that the multiple MAIN entry points are confusing your opening of the app.
Make sure you are opening the app from the correct launcher icon.
You should see two icons from the same app in your launcher. There might be a blank layout for the DisplayImage Activity which you are opening. Thus the blank screen.
I am referring to these in the manifest file
<activity android:name=".DisplayImage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I am also not that experienced with Android but have you tried removing the intent filter for DisplayImage in your manifest?
You have two activities with this defined :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
That tells Android that it can launch the application from either of them and since DisplayImage is declared first in the manifest, what you are seeing is an empty blank screen as no image has yet been loaded from MainActivity.
Check this out so that you have a better understanding of intents and intent filter
https://developer.android.com/guide/components/intents-filters

Unable to instantiate activity ComponentInfo{ProductSimpleInfoActivity} NullPointerException

this is my manifest files:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iadmo.dahan"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal"
>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:name="com.iadmo.dahan.application.MyApplication"
android:icon="#drawable/appicon"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.iadmo.dahan.activity.WelcomeActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:clearTaskOnLaunch="false"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RecommendActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PersonalActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.LoginActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RegisterActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SortedActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ClassesActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SearchedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductDetailsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PerClassActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductCommentActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductSimpleInfoActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.CommentDetailsActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadingActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<service android:name="com.iadmo.dahan.service.DownloadService"/>
</application>
and this is the xml for layout of productdetailsActivity:
public class ProductDetailsActivity extends TabActivity {
private TabHost mHost;
private String appId, userId;
private ListView per_class_simple_info;
private List<BaseInfo> datas;
private DetailsAdapter adapter;
private TextView txtview1, txtview2;
private Button back;
private TextView title_name;
private Dialog dialog;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_productdetail);
MyApplication.getInstance().addActivity(this);
Bundle bundle = getIntent().getExtras();
appId = bundle.getString("appId");
userId = AppUtil.getString(getApplicationContext(), "userid", "");
initCompanents();
initViews();
initDatas();
Intent intent = new Intent();
intent.setAction("GOODID");
intent.putExtras(bundle);
getApplicationContext().sendBroadcast(intent);
initEvents();
}
#SuppressWarnings("deprecation")
private void initViews() {
back = (Button) findViewById(R.id.back);
title_name = (TextView) findViewById(R.id.title_name);
per_class_simple_info = (ListView) findViewById(R.id.per_class_simple_info);
mHost = this.getTabHost();
mHost.addTab(mHost.newTabSpec("mhost_job").setIndicator(txtview1)
.setContent(new Intent(this, ProductSimpleInfoActivity.class)));
mHost.addTab(mHost.newTabSpec("mhost_company").setIndicator(txtview2)
.setContent(new Intent(this, ProductCommentActivity.class)));
}
private void initCompanents() {
txtview1 = new TextView(this);
txtview1.setText("简介");
txtview1.setTextColor(getResources().getColor(R.color.white));
txtview1.setGravity(Gravity.CENTER);// 文字居中
txtview1.setTextSize(15);// 字体大小
txtview1.setPadding(15, 16, 15, 15);// 四周填充
txtview1.setBackgroundResource(R.drawable.tabhost_bg);
txtview2 = new TextView(this);
txtview2.setText("评论");
txtview2.setTextColor(getResources().getColor(R.color.black));
txtview2.setGravity(Gravity.CENTER);// 居中
txtview2.setTextSize(15);// 字体大小
txtview2.setPadding(15, 16, 15, 15);// 填充
txtview2.setBackgroundResource(R.drawable.tabhost_bg);
LayoutParams param1 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param1.setMargins(0, 10, 0, 0);
param1.weight = 1;// 权重
txtview1.setLayoutParams(param1);
LayoutParams param2 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param2.setMargins(0, 10, 0, 0);
param2.weight = 1;// 权重
txtview2.setLayoutParams(param2);
}
and this is the productSimpleInfoActivity's code:
public class ProductSimpleInfoActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simpleinfo);
MyApplication.getInstance().addActivity(this);
initViews();
registerReceivers();
initEvents();
}
this is the productDetail xml layout,i think this is right ,i tired it ,it worked,but today i tired again,it failed:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
</TabWidget>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/s_5"
android:background="#color/red_light" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Try the following code.It hopefully works.
main.xml file :
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabhost" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"></FrameLayout>
</LinearLayout>
</TabHost>
In Class File add this code in your onCreate():
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Personal.class);
spec = tabHost.newTabSpec("personal").setIndicator("Personal").setContent(intent);
tabHost.addTab(spec);

Emulator opens all activities when clicking just the above...?

here I am again.
I have a problem with my menu in combination with my activities.
When I run my emulator, and click the uppest item in the list, the emulator opens all list activities.
Hopefully someone can help me.. Thank you all in advance!
My Menu.Java:
package com.jacob.eindproject;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity implements OnItemClickListener {
String classes[] = { "BMI- Calculator", "Ondergewicht", "Gezond Gewicht", "Overgewicht"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//Positie 0 is het eerste item (dus de BMI-Calculator.)
super.onListItemClick(l, v, position, id);
switch(position)
{
case 0:
Intent openStartingPoint = new Intent(getApplicationContext(),MainActivity.class);
startActivity(openStartingPoint);
case 1:
Intent openOndergewicht = new Intent(getApplicationContext(),Ondergewicht.class);
startActivity(openOndergewicht);
case 2:
Intent openGezondgewicht = new Intent(getApplicationContext(),Gezond_gewicht.class);
startActivity(openGezondgewicht);
case 3:
Intent openOvergewicht = new Intent(getApplicationContext(),Overgewicht.class);
startActivity(openOvergewicht);
break;
}
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jacob.eindproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jacob.eindproject.Menu"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.jacob.eindproject.Inleiding"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Ondergewicht"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.ONDERGEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Gezond_gewicht"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.GEZOND_GEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Overgewicht"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.OVERGEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
</application>
First, there opens the Inleiding, it's my logo, and after 5 seconds it disappears.
After that, I want the menu with 4 items, 1 for the MainActivity.java, wich is a BMI-calculator. The last 3 items are informational items, about weight and stuff.
Somebody who knows the answer?
Thank you all for your efforts.
The reason all your activities open is because you don't have break statements at the end of each case clause in your switch. You need to add a break at the end of each case block.
Also, you should remove the <intent-filter> tags from all of your activities except the first one (Inleiding) that contains CATEGORY=DEFAULT and ACTION=MAIN. You don't need those and they will just confuse you.

Widget configuration activity doesn't start

As I understood, if I define configuration activity for widget, onUpdate() method will not call, until I'll not configure it. But in my case, and I wonder why - configuration activity doesn't start, and update method calls after placing widget. My application have other activities, one of them starts when application run, maybe that's is the reason? Here my code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.watcom.MobileInformer"
android:versionCode="2"
android:versionName="1.01"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<application android:label="#string/app_name" android:theme="#style/WatcomTheme" android:icon="#drawable/icon">
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="false"/>
<activity android:name=".AuthorizationActivity"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="com.watcom.MobileInformer.UPDATE_WIDGET"/>
</intent-filter>
</activity>
<activity android:launchMode="singleTop" android:name=".WidgetConfigureActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity android:name=".ProjectsActivity" android:screenOrientation="portrait"/>
<receiver
android:icon="#drawable/icon"
android:label="Watcom informer"
android:name=".MyWidgetProvider" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="ru.example.android.widget.ACTION_WIDGET_RECEIVER"/>
</intent-filter>
<intent-filter>
<action android:name="com.watcom.MobileInformer.UPDATE_WIDGET"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_provider" />
</receiver>
</application>
<uses-permission xmlns:android="http://schemas.android.com/apk/res/android"
android:name="android.permission.INTERNET" />
</manifest>
widget_provider.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="schemas.android.com/apk/res/android"
android:minHeight="320dp"
android:minWidth="100dp"
android:updatePeriodMillis="1800000"
android:initialLayout="#layout/widget_layout"
android:configuration="com.watcom.MobileInformer.WidgetConfigureActivity"/>
WidgetConfigureActivity
public class WidgetConfigureActivity extends Activity {
int widgetId;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
setContentView(R.layout.login_layout);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras!=null)
widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
if (widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
setResult(RESULT_OK, resultValue);
finish();
}

error emulate player developed in android

I am a beginner in programming for Android, and am making a music and video player, which already programmed much of the program, but when the emulator executes I get the following error:
Unfortunately, FlagPlayer has stopped
I have done many researches on the subject but I can not find anything that solves my problem. I hope you can help me.
here is my main class:
package tcc.etec.FlagPlayer;
import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button btMusica;
private Button btArtista;
private Button btAlbum;
private Button btVideo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
acaobutton();
}
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) this);
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) this);
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) this);
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) this);
}
public void onClick(View v){
if (v.getId()==R.id.btmusica){
Intent intent = new Intent(MainActivity.this, ListaMusicaActivity.class);
}else if (v.getId()==R.id.btartista){
Intent intent = new Intent(MainActivity.this, ListaArtistaActivity.class);
}else if (v.getId()==R.id.btalbuns){
Intent intent = new Intent(MainActivity.this, ListaAlbumActivity.class);
}else if (v.getId()==R.id.btvideo){
Intent intent = new Intent(MainActivity.this, ListaVideoActivity.class);
}
}
XML:
<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"
tools:context=".MainActivity" >
<Button
android:id="#+id/btmusica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:text="Musicas" />
<Button
android:id="#+id/btartista"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btmusica"
android:layout_alignBottom="#+id/btmusica"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:text="Artistas" />
<Button
android:id="#+id/btalbuns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="66dp"
android:text="Albuns" />
<Button
android:id="#+id/btvideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btalbuns"
android:layout_alignBottom="#+id/btalbuns"
android:layout_alignRight="#+id/btartista"
android:text="Videos" />
and AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tcc.etec.FlagPlayer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".tcc.etec.FlagPlayer.activity_main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".tcc.etec.FlagPlayer.ListaMusicaActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".tcc.etec.FlagPlayer.MusicPlayerActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Try to replacing your:
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) this);
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) this);
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) this);
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) this);
}
To:
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) getBaseContext());
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) getBaseContext());
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) getBaseContext());
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) getBaseContext());
}

Categories

Resources